org.eclipse.emf.mwe.internal.core.debug.communication
Class Connection

java.lang.Object
  extended by org.eclipse.emf.mwe.internal.core.debug.communication.Connection

public class Connection
extends java.lang.Object

This class implements a socket connection model. "Packages" (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.


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()
           
 AbstractPackage listenForPackage(java.lang.Class<? extends AbstractPackage> type)
           
 AbstractPackage listenForPackage(java.lang.Class<? extends AbstractPackage> type, int refId)
           
protected  AbstractPackage readPackage()
           
 int sendPackage(AbstractPackage packet)
           
 void startListeningSocket(int port)
          create a new ServerSocket.
protected  void writePackage(AbstractPackage 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

listenForPackage

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

listenForPackage

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

sendPackage

public int sendPackage(AbstractPackage 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


readPackage

protected AbstractPackage readPackage()
                               throws java.io.IOException
Throws:
java.io.IOException

writePackage

protected void writePackage(AbstractPackage packet)
                     throws java.io.IOException
Throws:
java.io.IOException