|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object cz.cuni.amis.pogamut.base.communication.connection.impl.AbstractConnection<ADDRESS>
public abstract class AbstractConnection<ADDRESS extends IWorldConnectionAddress>
Implementation of the basic connection to the world server. Note that it has some nice features :-)
This implementation is THREAD-SAFE! It is IComponent
!
Calling getReader().read(), getWriter().write() is synchronized as well!
Reader and writer can be got in advance (no need to start() the connection before getReader() or getWriter() is invoked).
Calling reader.close() or writer.close() will stop() the connection as well ... you don't have to have this instance referenced directly.
Whenever an exception is thrown during read/write operation, the connection is immediately stop()ed,
not kill()ed and IStoppedEvent
is broadcasted. The flag will be changed correctly as well.
... if you're waiting on the reader.read() and the socket is closed meanwhile, be ready to catch the SocketException ...
The instance of the class can be reused (e.g. you may start(), stop() it repeatedly).
All you have to implement:
Ignores IComponentControlHelper.startPaused()
, performs IComponentControlHelper.start()
in both start cases.
Field Summary | |
---|---|
protected ADDRESS |
address
Current remote side address of the connection. |
static cz.cuni.amis.utils.token.Token |
COMPONENT_ID
|
protected ComponentController<IComponent> |
controller
Control helper starting/stopping the component. |
static String |
DEFAULT_LINE_END
|
protected IComponentBus |
eventBus
Event bus of the agent. |
protected LogCategory |
log
Special category for the connection. |
Constructor Summary | |
---|---|
AbstractConnection(ADDRESS address,
ComponentDependencies dependencies,
IComponentBus bus,
IAgentLogger logger)
|
|
AbstractConnection(ComponentDependencies dependencies,
IComponentBus bus,
IAgentLogger logger)
|
Method Summary | |
---|---|
ADDRESS |
getAddress()
Get the descriptor of the connection's remote side. |
cz.cuni.amis.utils.token.Token |
getComponentId()
Unique identification of the component. |
protected abstract Reader |
getConnectionReader()
This should return plain reader for the current connection. |
protected abstract Writer |
getConnectionWriter()
This should return plain writer for the current connection. |
LogCategory |
getLog()
|
String |
getMessageEnd()
|
WorldReader |
getReader()
To be used by (usually) IParser upon IParser.start() method call to obtain a world reader. |
WorldWriter |
getWriter()
To be used on ICommandSerializer.start() method to obtain a writer into the world. |
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. |
String |
toString()
|
protected abstract void |
unsyncClose()
Inner unsynchronized implementation of the close(), should close the connection to the remote side without throwing any exception. |
protected abstract void |
unsyncConnect(ADDRESS address)
Inner implementation of connect, unsynchronized, this is called from connect(IConnectionDescriptor). |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
public static final cz.cuni.amis.utils.token.Token COMPONENT_ID
public static final String DEFAULT_LINE_END
protected ADDRESS extends IWorldConnectionAddress address
protected LogCategory log
protected IComponentBus eventBus
protected ComponentController<IComponent> controller
Constructor Detail |
---|
public AbstractConnection(ComponentDependencies dependencies, IComponentBus bus, IAgentLogger logger)
public AbstractConnection(ADDRESS address, ComponentDependencies dependencies, IComponentBus bus, IAgentLogger logger)
Method Detail |
---|
protected abstract void unsyncConnect(ADDRESS address) throws ConnectionException
ConnectionException
protected abstract void unsyncClose()
protected abstract Reader getConnectionReader() throws ConnectionException
ConnectionException
protected abstract Writer getConnectionWriter() throws ConnectionException
ConnectionException
public cz.cuni.amis.utils.token.Token getComponentId()
IComponent
getComponentId
in interface IComponent
public LogCategory getLog()
public void setAddress(ADDRESS address) throws ConnectionException
IWorldConnection
If the object is connected - it throws exception AlreadyConnectedException
setAddress
in interface IWorldConnection<ADDRESS extends IWorldConnectionAddress>
ConnectionException
public WorldWriter getWriter() throws ConnectionException
IWorldWriterProvider
Use writer.close() to stop the writer.
getWriter
in interface IWorldWriterProvider
ConnectionException
public WorldReader getReader() throws ConnectionException
IWorldReaderProvider
Use reader.close() to close the connection.
getReader
in interface IWorldReaderProvider
ConnectionException
public ADDRESS getAddress()
IWorldConnection
getAddress
in interface IWorldConnection<ADDRESS extends IWorldConnectionAddress>
public String toString()
toString
in class Object
public void setLogMessages(boolean logMessages)
IWorldConnection
setLogMessages
in interface IWorldConnection<ADDRESS extends IWorldConnectionAddress>
public String getMessageEnd()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |