public class ConnectionDataHandler extends Object implements org.xsocket.connection.IWriteCompletionHandler, ISocketServerConnection, ISocketServerProtocolDecoderListener
Constructor and Description |
---|
ConnectionDataHandler(org.xsocket.connection.INonBlockingConnection connection,
ISocketServerConnectionListener listener,
ISocketSeverProtocolDecoder protocolDecoder)
Constructor.
|
Modifier and Type | Method and Description |
---|---|
void |
close()
Closes the connection.
|
void |
decode(byte[] newData)
Decodes incoming data.
|
void |
errorDecoding(String errorDecoding)
Error produced while decoding data.
|
org.xsocket.connection.INonBlockingConnection |
getConnection()
getConnectionSynchronized.
|
int |
getConnectionReceivedPackets()
Gets the total number of received packets.
|
int |
getConnectionSentPackets()
Gets the total number of sent packets.
|
int |
getId()
Returns the connection identifier.
|
ISocketServerConnectionListener |
getListener()
Returns the listener.
|
InetAddress |
getRemoteAddress()
Returns the remote IP address.
|
int |
getRemotePort()
Returns the remote port.
|
boolean |
isConnectionClosed()
Returns true if the connections is closed.
|
void |
onException(IOException ioe)
Exception raised while trying to write.
|
void |
onWritten(int written)
Callback method that notifies that a packet has been sent.
|
void |
packetReceived(Object pckt)
Method called by the protocol decoder when a new packet has been
assembled.
|
void |
setConnectionLister(ISocketServerConnectionListener listener)
Set the listener.
|
void |
setId(int connectionId)
.
|
void |
writeToConnection(ByteBuffer data)
Writes data to connection.
|
public ConnectionDataHandler(org.xsocket.connection.INonBlockingConnection connection, ISocketServerConnectionListener listener, ISocketSeverProtocolDecoder protocolDecoder)
connection
- xSocket connection that wraps the socket channellistener
- connection listenerprotocolDecoder
- connection protocol decoderpublic void close()
close
in interface Closeable
close
in interface AutoCloseable
public void decode(byte[] newData)
newData
- incoming new datapublic int getConnectionReceivedPackets()
getConnectionReceivedPackets
in interface ISocketServerConnection
public int getConnectionSentPackets()
getConnectionSentPackets
in interface ISocketServerConnection
public int getId()
getId
in interface ISocketServerConnection
public boolean isConnectionClosed()
isConnectionClosed
in interface ISocketServerConnection
public void onException(IOException ioe)
onException
in interface org.xsocket.connection.IWriteCompletionHandler
ioe
- error while trying to write to the connection.public void onWritten(int written) throws IOException
onWritten
in interface org.xsocket.connection.IWriteCompletionHandler
written
- the size of the packet writtenIOException
- error handling onWritten eventIWriteCompletionHandler.onWritten(int)
public void packetReceived(Object pckt)
packetReceived
in interface ISocketServerProtocolDecoderListener
pckt
- the new assembled packetpublic void setId(int connectionId)
setId
in interface ISocketServerConnection
connectionId
- integer used to identify the connection.public void writeToConnection(ByteBuffer data)
onWritten
is called after the packet has
been written.writeToConnection
in interface ISocketServerConnection
data
- data to be writtenpublic InetAddress getRemoteAddress()
getRemoteAddress
in interface ISocketServerConnection
public org.xsocket.connection.INonBlockingConnection getConnection()
public void errorDecoding(String errorDecoding)
errorDecoding
in interface ISocketServerProtocolDecoderListener
errorDecoding
- .public ISocketServerConnectionListener getListener()
public void setConnectionLister(ISocketServerConnectionListener listener)
setConnectionLister
in interface ISocketServerConnection
listener
- listener.public int getRemotePort()
ISocketServerConnection
getRemotePort
in interface ISocketServerConnection
Copyright © 2018 universAAL Consortium. All rights reserved.