org.universAAL.lddi.zwave.exporter.Server
Class ConnectionDataHandler

Package class diagram package ConnectionDataHandler
java.lang.Object
  extended by org.universAAL.lddi.zwave.exporter.Server.ConnectionDataHandler
All Implemented Interfaces:
Closeable, ISocketServerConnection, ISocketServerProtocolDecoderListener, org.xsocket.connection.IWriteCompletionHandler

public class ConnectionDataHandler
extends Object
implements org.xsocket.connection.IWriteCompletionHandler, ISocketServerConnection, ISocketServerProtocolDecoderListener

Connection wrapper to be used with xSocket library.

Version:
$Rev: 5339 $ $Date: 2012-09-25 17:17:28 +0200 (mar, 25 sep 2012) $
Author:
fraperod

Constructor Summary
ConnectionDataHandler(org.xsocket.connection.INonBlockingConnection connection, ISocketServerConnectionListener listener, ISocketSeverProtocolDecoder protocolDecoder)
          Constructor.
 
Method Summary
 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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ConnectionDataHandler

public ConnectionDataHandler(org.xsocket.connection.INonBlockingConnection connection,
                             ISocketServerConnectionListener listener,
                             ISocketSeverProtocolDecoder protocolDecoder)
Constructor.

Parameters:
connection - xSocket connection that wraps the socket channel
listener - connection listener
protocolDecoder - connection protocol decoder
Method Detail

close

public void close()
Closes the connection.

Specified by:
close in interface Closeable

decode

public void decode(byte[] newData)
Decodes incoming data. New frames will be notified to the connection Listener.

Parameters:
newData - incoming new data

getConnectionReceivedPackets

public int getConnectionReceivedPackets()
Gets the total number of received packets.

Specified by:
getConnectionReceivedPackets in interface ISocketServerConnection
Returns:
the total number of received packets

getConnectionSentPackets

public int getConnectionSentPackets()
Gets the total number of sent packets.

Specified by:
getConnectionSentPackets in interface ISocketServerConnection
Returns:
the total number of sent packets

getId

public int getId()
Returns the connection identifier.

Specified by:
getId in interface ISocketServerConnection
Returns:
connection identifier

isConnectionClosed

public boolean isConnectionClosed()
Returns true if the connections is closed.

Specified by:
isConnectionClosed in interface ISocketServerConnection
Returns:
true if the connection is closed

onException

public void onException(IOException ioe)
Exception raised while trying to write.

Specified by:
onException in interface org.xsocket.connection.IWriteCompletionHandler
Parameters:
ioe - error while trying to write to the connection.

onWritten

public void onWritten(int written)
               throws IOException
Callback method that notifies that a packet has been sent.

Specified by:
onWritten in interface org.xsocket.connection.IWriteCompletionHandler
Parameters:
written - the size of the packet written
Throws:
IOException - error handling onWritten event
See Also:
IWriteCompletionHandler.onWritten(int)

packetReceived

public void packetReceived(Object pckt)
Method called by the protocol decoder when a new packet has been assembled.

Specified by:
packetReceived in interface ISocketServerProtocolDecoderListener
Parameters:
pckt - the new assembled packet

setId

public void setId(int connectionId)
.

Specified by:
setId in interface ISocketServerConnection
Parameters:
connectionId - integer used to identify the connection.

writeToConnection

public void writeToConnection(ByteBuffer data)
Writes data to connection. Asynchronous method, retuns imediatly. onWritten is called after the packet has been written.

Specified by:
writeToConnection in interface ISocketServerConnection
Parameters:
data - data to be written

getRemoteAddress

public InetAddress getRemoteAddress()
Returns the remote IP address.

Specified by:
getRemoteAddress in interface ISocketServerConnection
Returns:
the remote IP address.

getConnection

public org.xsocket.connection.INonBlockingConnection getConnection()
getConnectionSynchronized.

Returns:
.

errorDecoding

public void errorDecoding(String errorDecoding)
Error produced while decoding data.

Specified by:
errorDecoding in interface ISocketServerProtocolDecoderListener
Parameters:
errorDecoding - .

getListener

public ISocketServerConnectionListener getListener()
Returns the listener.

Returns:
the listener

setConnectionLister

public void setConnectionLister(ISocketServerConnectionListener listener)
Set the listener.

Specified by:
setConnectionLister in interface ISocketServerConnection
Parameters:
listener - listener.

getRemotePort

public int getRemotePort()
Description copied from interface: ISocketServerConnection
Returns the remote port.

Specified by:
getRemotePort in interface ISocketServerConnection
Returns:
the remote port.


Copyright © 2014 universAAL Consortium. All Rights Reserved.