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)
ConnectionsetLogBytes in interface Connectionenabled - Whether to enable byte-level logging.public final void startup()
Connectionstartup in interface Connectionpublic final void shutdown()
Connectionshutdown in interface Connectionpublic boolean isAlive()
ConnectionisAlive in interface Connectionpublic void addConnectionListener(ConnectionListener l)
ConnectionaddConnectionListener in interface Connectionl - The listener to add.public void removeConnectionListener(ConnectionListener l)
ConnectionremoveConnectionListener in interface Connectionl - The listener to remove.public void sendMessage(Message msg) throws ConnectionException
ConnectionsendMessage in interface Connectionmsg - 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
ConnectionsendMessages in interface Connectionmessages - 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)
ConnectionsetRegistry in interface Connectionr - The new Registry to use.public Registry getRegistry()
ConnectiongetRegistry in interface Connectionpublic java.lang.String getName()
ConnectiongetName in interface Connectionpublic void setName(java.lang.String newName)
ConnectionsetName in interface ConnectionnewName - The new name.public java.lang.String toString()
toString in class java.lang.Objectprotected 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.