cz.cuni.amis.pogamut.base.communication.connection
Interface IWorldConnection<ADDRESS extends IWorldConnectionAddress>

All Superinterfaces:
IComponent, IWorldReaderProvider, IWorldWriterProvider
All Known Implementing Classes:
AbstractConnection, SocketConnection

public interface IWorldConnection<ADDRESS extends IWorldConnectionAddress>
extends IWorldReaderProvider, IWorldWriterProvider

Interface for the connection to a remote world.

Simple methods that are needed to make connection read/write messages.

Implementor is required to implement the interface as reusable. Meaning that one instance of object may serve first as the connection to one server and then to another.

Control the object through IControllable interface.

Example scenario 1:

  1. instantiate
  2. set address through setAddress()
  3. start()
  4. do some work with reader/writer
  5. stop()

Or more advance scenario 2 (reconnection):

  1. instantiate
  2. set address through setAddress()
  3. start()
  4. do some work with reader/writer
  5. stop()
  6. set address again
  7. start() ... this connects again
  8. do some work on other server
  9. stop()
There is a nice abstract implementation AbstractConnection where all you have to do is implement inner methods for connect / close / getting raw readers and writers.


Method Summary
 ADDRESS getAddress()
          Get the descriptor of the connection's remote side.
 void setAddress(ADDRESS address)
          Sets the connection address to the object.
 void setLogMessages(boolean logMessages)
          Sets whether to log the messages that are sent/received through writer/reader.
 
Methods inherited from interface cz.cuni.amis.pogamut.base.communication.connection.IWorldReaderProvider
getReader
 
Methods inherited from interface cz.cuni.amis.pogamut.base.component.IComponent
getComponentId
 
Methods inherited from interface cz.cuni.amis.pogamut.base.communication.connection.IWorldWriterProvider
getWriter
 

Method Detail

setLogMessages

void setLogMessages(boolean logMessages)
Sets whether to log the messages that are sent/received through writer/reader. Note that logging those messages is costly operation and may slow things a lot. That's why this is OFF as DEFAULT.

Parameters:
logMessages -

getAddress

ADDRESS getAddress()
Get the descriptor of the connection's remote side.

Returns:

setAddress

void setAddress(ADDRESS address)
                throws CommunicationException
Sets the connection address to the object.

If the object is connected - it throws exception AlreadyConnectedException

Parameters:
address -
Throws:
CommunicationException