org.openarchitectureware.debug.communication
Class Connection

java.lang.Object
  extended by org.openarchitectureware.debug.communication.Connection

public class Connection
extends java.lang.Object

This class implements a socket connection model. "Packets" (units of information) can be transfered between two different virtual machines. During the initialisation of a socket connection a reader and a writer thread are established. This class can be used both on the sender and receiver side.

Author:
Clemens Kadura (zAJKa)

Constructor Summary
Connection()
           
 
Method Summary
 void accept(int timeout)
          the server listens for a client to connect, creates new reader and writer threads and sends a first handshake packet to test the communication
 void close()
          close and dispose the socket and the (possibly waiting) sender thread
 void connect(int port)
          the client establishes the connection here, creates new reader and writer threads and waits for a handshake packet to be received from the server
 boolean isConnected()
           
 AbstractPacket listenForPacket(java.lang.Class<? extends AbstractPacket> type)
           
 AbstractPacket listenForPacket(java.lang.Class<? extends AbstractPacket> type, int refId)
           
protected  AbstractPacket readPacket()
           
 int sendPacket(AbstractPacket packet)
           
 void startListeningSocket(int port)
          create a new ServerSocket.
protected  void writePacket(AbstractPacket packet)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Connection

public Connection()
Method Detail

listenForPacket

public AbstractPacket listenForPacket(java.lang.Class<? extends AbstractPacket> type)
                               throws java.io.InterruptedIOException
Throws:
java.io.InterruptedIOException

listenForPacket

public AbstractPacket listenForPacket(java.lang.Class<? extends AbstractPacket> type,
                                      int refId)
                               throws java.io.InterruptedIOException
Throws:
java.io.InterruptedIOException

sendPacket

public int sendPacket(AbstractPacket packet)
               throws java.io.IOException
Throws:
java.io.IOException

startListeningSocket

public void startListeningSocket(int port)
                          throws java.io.IOException
create a new ServerSocket.

Parameters:
port - the communication port
Throws:
java.io.IOException

accept

public void accept(int timeout)
            throws java.io.IOException
the server listens for a client to connect, creates new reader and writer threads and sends a first handshake packet to test the communication

Parameters:
timeout -
Throws:
java.io.IOException

connect

public void connect(int port)
             throws java.io.IOException
the client establishes the connection here, creates new reader and writer threads and waits for a handshake packet to be received from the server

Parameters:
port -
Throws:
java.io.IOException

isConnected

public boolean isConnected()
Returns:
if the socket connection is still active

close

public void close()
close and dispose the socket and the (possibly waiting) sender thread


readPacket

protected AbstractPacket readPacket()
                             throws java.io.IOException
Throws:
java.io.IOException

writePacket

protected void writePacket(AbstractPacket packet)
                    throws java.io.IOException
Throws:
java.io.IOException