Download Developer Manual

Transcript
AsTeRICS
Developer Manual
void connectionLost();
void connectionClosed();
connectionEstablished() is called whenever a plugin requests a connection and the
connection has been established. This can either happen if a connection has already been
established before or if the new connection has finished its setup and connection process.
dataReceived() is called whenever new data arrives from the other end of the connection.
Data is transferred in a byte array and has to be processed by the event listener.
connectionLost() is called when the connection management cannot read from or write to the
socket.
connectionClosed() is called after the connection has been closed.
5.2.2 RemoteConnectionManager
The RemoteConnectionManager is implemented as a singleton and can be accessed via a
public static member of the class. Thus access is always achieved through:
RemoteConnectionManager.instance
A connection is opened by a call the RemoteConnectionManager’s method:
boolean requestConnection (String port, IRemoteConnectionListener l)
This call will try to access a connection on the specified port. Although the port is actually an
integer it is passed as a String here. The method will return true if a connection on this port
has already been established and attach the remote connection listener passed in the
second argument to the connection. If there is no active connection on the specified port, the
requestConnection method will initiate the setup of the connection and return false. With this
return value the user can decide whether he needs to perform setup actions or will be able to
do this in the connectionEstablished() callback.
The socket connection handling is implemented using two threads, one for sending, one for
receiving data. The receiver thread will continuously read data from the socket and forward it
to the registered listener calling the dataReceived() method. Since incoming data is handled
in another thread than the plugin which will use the socket connection, access to the
methods handling this data or the way of passing data should be done in a synchronised
code block.
Sending data is done calling the method sendData of RemoteConnectionManager:
public boolean writeData(String port, byte[] data)
This method is called using a String holding the port number of the connection socket and an
array of bytes to be sent. The call to this method will place the data in an outgoing queue and
return true if this was successful. Thus it is not guaranteed that the data has already been
sent when the method returns. The sender thread will grab data from the outgoing queue and
transfer it via the socket or call the connectionLost() method of the registered listener if there
are problems while sending.
Page 44