public abstract class AbstractConnection extends java.lang.Object implements Connection
Modifier and Type | Class and Description |
---|---|
protected static class |
AbstractConnection.State
The state of this connection: either not yet started, started or shut down.
|
Modifier | Constructor and Description |
---|---|
protected |
AbstractConnection()
Construct an abstract connection.
|
Modifier and Type | Method and Description |
---|---|
void |
addConnectionListener(ConnectionListener l)
Add a ConnectionListener.
|
protected void |
bytesReceived(byte[] b)
Process some bytes that were received.
|
protected void |
fireMessageReceived(Message m)
Fire a messageReceived event to all registered listeners.
|
java.lang.String |
getName()
Get the name for this connection.
|
Registry |
getRegistry()
Get the Registry that this connection is using for decoding messages and entities.
|
boolean |
isAlive()
Find out if this connection is still alive.
|
void |
removeConnectionListener(ConnectionListener l)
Remove a ConnectionListener.
|
protected abstract void |
sendBytes(byte[] b)
Send some bytes to the other end of the connection.
|
void |
sendMessage(Message msg)
Send a message across this connection.
|
void |
sendMessages(java.util.Collection<? extends Message> messages)
Send a set of messages across this connection.
|
void |
setLogBytes(boolean enabled)
Turn byte-level logging on or off.
|
void |
setName(java.lang.String newName)
Set the name for this connection.
|
void |
setRegistry(Registry r)
Set the Registry that this connection should use for decoding messages and entities.
|
void |
shutdown()
Shut this connection down.
|
protected abstract void |
shutdownImpl()
Perform shutdown actions.
|
void |
startup()
Start this connection up.
|
protected abstract void |
startupImpl()
Perform startup actions.
|
java.lang.String |
toString() |
protected AbstractConnection()
public void setLogBytes(boolean enabled)
Connection
setLogBytes
in interface Connection
enabled
- Whether to enable byte-level logging.public final void startup()
Connection
startup
in interface Connection
public final void shutdown()
Connection
shutdown
in interface Connection
public boolean isAlive()
Connection
isAlive
in interface Connection
public void addConnectionListener(ConnectionListener l)
Connection
addConnectionListener
in interface Connection
l
- The listener to add.public void removeConnectionListener(ConnectionListener l)
Connection
removeConnectionListener
in interface Connection
l
- The listener to remove.public void sendMessage(Message msg) throws ConnectionException
Connection
sendMessage
in interface Connection
msg
- The message to send.ConnectionException
- If the connection has not been started up or has been shut down, or if there is an error sending the message.public void sendMessages(java.util.Collection<? extends Message> messages) throws ConnectionException
Connection
sendMessages
in interface Connection
messages
- The messages to send.ConnectionException
- If the connection has not been started up or has been shut down, or if there is an error sending the message.public void setRegistry(Registry r)
Connection
setRegistry
in interface Connection
r
- The new Registry to use.public Registry getRegistry()
Connection
getRegistry
in interface Connection
public java.lang.String getName()
Connection
getName
in interface Connection
public void setName(java.lang.String newName)
Connection
setName
in interface Connection
newName
- The new name.public java.lang.String toString()
toString
in class java.lang.Object
protected abstract void sendBytes(byte[] b) throws java.io.IOException
b
- The bytes to send.java.io.IOException
- If the data cannot be sent.protected abstract void startupImpl()
protected abstract void shutdownImpl()
protected void bytesReceived(byte[] b)
b
- The received bytes.protected void fireMessageReceived(Message m)
m
- The message that was received.