|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectcz.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 Token |
COMPONENT_ID
|
protected ComponentController<IComponent> |
controller
Control helper starting/stopping the component. |
static java.lang.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. |
Token |
getComponentId()
Unique identification of the component. |
protected abstract java.io.Reader |
getConnectionReader()
This should return plain reader for the current connection. |
protected abstract java.io.Writer |
getConnectionWriter()
This should return plain writer for the current connection. |
LogCategory |
getLog()
|
java.lang.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. |
java.lang.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 Token COMPONENT_ID
public static final java.lang.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
ConnectionExceptionprotected abstract void unsyncClose()
protected abstract java.io.Reader getConnectionReader()
throws ConnectionException
ConnectionException
protected abstract java.io.Writer getConnectionWriter()
throws ConnectionException
ConnectionExceptionpublic Token getComponentId()
IComponent
getComponentId in interface IComponentpublic 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
IWorldWriterProviderUse writer.close() to stop the writer.
getWriter in interface IWorldWriterProviderConnectionException
public WorldReader getReader()
throws ConnectionException
IWorldReaderProviderUse reader.close() to close the connection.
getReader in interface IWorldReaderProviderConnectionExceptionpublic ADDRESS getAddress()
IWorldConnection
getAddress in interface IWorldConnection<ADDRESS extends IWorldConnectionAddress>public java.lang.String toString()
toString in class java.lang.Objectpublic void setLogMessages(boolean logMessages)
IWorldConnection
setLogMessages in interface IWorldConnection<ADDRESS extends IWorldConnectionAddress>public java.lang.String getMessageEnd()
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||