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

Package class diagram package AbstractSocketServerXSocket
java.lang.Object
  extended by org.universAAL.lddi.zwave.exporter.Server.AbstractSocketServer
      extended by org.universAAL.lddi.zwave.exporter.Server.AbstractSocketServerXSocket
All Implemented Interfaces:
Closeable, ISocketServer, ISocketServerConnectionListener, org.xsocket.connection.IConnectHandler, org.xsocket.connection.IConnectionTimeoutHandler, org.xsocket.connection.IDataHandler, org.xsocket.connection.IDisconnectHandler, org.xsocket.connection.IHandler, org.xsocket.connection.IIdleTimeoutHandler
Direct Known Subclasses:
MotionServer

public abstract class AbstractSocketServerXSocket
extends AbstractSocketServer
implements org.xsocket.connection.IConnectHandler, org.xsocket.connection.IDisconnectHandler, org.xsocket.connection.IDataHandler, org.xsocket.connection.IIdleTimeoutHandler, org.xsocket.connection.IConnectionTimeoutHandler, ISocketServerConnectionListener

Socket server implemented using xSocket library.

Version:
$Rev: 4442 $ $Date: 2011-11-23 16:22:03 +0100 (miƩ, 23 nov 2011) $
Author:
fraperod

Field Summary
protected static boolean activateConnectionLogging
          True to allow xSocket connection to log.
protected  org.xsocket.connection.IServer srv
          xSocket server.
protected  TransferRateCalculator transferRate
          Calculates transfer rates.
 
Fields inherited from class org.universAAL.lddi.zwave.exporter.Server.AbstractSocketServer
DEFAULT_TCP_BUFFERS_SIZE, listenPort, nWorkersCPUmultiplier, nWorkersIO, protocolDecoderFactory, tcpBufferSizeIn, tcpBufferSizeOut, workerPool
 
Fields inherited from interface org.xsocket.connection.IHandler
DEFAULT_EXECUTION_MODE
 
Constructor Summary
AbstractSocketServerXSocket(ISocketServerProtocolDecoderFactory protocolFactory, int listenPort)
          Constructor.
AbstractSocketServerXSocket(ISocketServerProtocolDecoderFactory protocolFactory, int listenPort, SSLContext sslContext, int idleTimeout, int connectionTimeout)
          Constructor.
 
Method Summary
 void close()
          Closes the server.
 org.xsocket.connection.IServer getServerXSocket()
          Returns the xSocket server class.
 long getTotalReadBytes()
          Returns the total number of bytes read.
 long getTotalSentBytes()
          Retuns the total number of bytes sent.
 float getTransferRateIn()
          Incoming data transfer rate in bytes/second.
 float getTransferRateOut()
          Outgoing data transfer rate in bytes/second.
 boolean onConnect(org.xsocket.connection.INonBlockingConnection connection)
          Socket connected.
 boolean onConnectionTimeout(org.xsocket.connection.INonBlockingConnection connection)
          Method called when a connection timeout is reached.
 boolean onData(org.xsocket.connection.INonBlockingConnection connection)
          New data available on xSocket connection.
 boolean onDisconnect(org.xsocket.connection.INonBlockingConnection connection)
          Disconnect event.
 boolean onIdleTimeout(org.xsocket.connection.INonBlockingConnection connection)
          Idle time out event.
 void packetSent(ISocketServerConnection connection, int size)
          Data sent notification.
 void run()
          Stars the server in the current thread.
static void setActivateConnectionLogging(boolean activateConnectionLogging)
          Sets the xSocket connection log.
 void setIP(String ip)
          Sets the IP to bind the port.
 void start()
          Starts the server in a different thread.
 
Methods inherited from class org.universAAL.lddi.zwave.exporter.Server.AbstractSocketServer
setPort
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.universAAL.lddi.zwave.exporter.Server.ISocketServerConnectionListener
packetArrived, socketConnected, socketDisconnected, socketException
 

Field Detail

transferRate

protected TransferRateCalculator transferRate
Calculates transfer rates.


activateConnectionLogging

protected static boolean activateConnectionLogging
True to allow xSocket connection to log.


srv

protected org.xsocket.connection.IServer srv
xSocket server.

Constructor Detail

AbstractSocketServerXSocket

public AbstractSocketServerXSocket(ISocketServerProtocolDecoderFactory protocolFactory,
                                   int listenPort)
Constructor. No Idle timeout, nor connection timeout used.

Parameters:
protocolFactory - protocol decoder factory to be used by the server
listenPort - port to be used by the server to accept incoming connections

AbstractSocketServerXSocket

public AbstractSocketServerXSocket(ISocketServerProtocolDecoderFactory protocolFactory,
                                   int listenPort,
                                   SSLContext sslContext,
                                   int idleTimeout,
                                   int connectionTimeout)
Constructor.

Parameters:
protocolFactory - protocol decoder factory to be used by the server.
listenPort - port to be used by the server to accept incoming connections.
sslContext - SSLContext.
idleTimeout - milliseconds to receive some data, connection will be closed if no data is received. 0 to disable timeout.
connectionTimeout - milliseconds to close the connection after being established. 0 to disable timeout.
Method Detail

setActivateConnectionLogging

public static void setActivateConnectionLogging(boolean activateConnectionLogging)
Sets the xSocket connection log.

Parameters:
activateConnectionLogging - true to allow xSocket connection to log

close

public void close()
           throws IOException
Closes the server.

Specified by:
close in interface Closeable
Specified by:
close in interface ISocketServer
Throws:
IOException - error closgin the socket server.

getServerXSocket

public org.xsocket.connection.IServer getServerXSocket()
Returns the xSocket server class.

Returns:
the xSocket server class

getTotalReadBytes

public long getTotalReadBytes()
Returns the total number of bytes read.

Specified by:
getTotalReadBytes in interface ISocketServer
Returns:
the total number of bytes read

getTotalSentBytes

public long getTotalSentBytes()
Retuns the total number of bytes sent.

Specified by:
getTotalSentBytes in interface ISocketServer
Returns:
the total number of bytes sent

getTransferRateIn

public float getTransferRateIn()
Incoming data transfer rate in bytes/second.

Specified by:
getTransferRateIn in interface ISocketServer
Returns:
the incoming data transfer rate in bytes/second

getTransferRateOut

public float getTransferRateOut()
Outgoing data transfer rate in bytes/second.

Specified by:
getTransferRateOut in interface ISocketServer
Returns:
the Outgoing data transfer rate in bytes/second

onConnect

public boolean onConnect(org.xsocket.connection.INonBlockingConnection connection)
                  throws IOException
Socket connected.

Specified by:
onConnect in interface org.xsocket.connection.IConnectHandler
Parameters:
connection - new xSocket connection opened
Returns:
true if the event was handled
Throws:
IOException - error handling new connection

onConnectionTimeout

public boolean onConnectionTimeout(org.xsocket.connection.INonBlockingConnection connection)
                            throws IOException
Method called when a connection timeout is reached.

Specified by:
onConnectionTimeout in interface org.xsocket.connection.IConnectionTimeoutHandler
Parameters:
connection - the connection
Returns:
true if the event was handled
Throws:
IOException - error handling connection timeout

onData

public boolean onData(org.xsocket.connection.INonBlockingConnection connection)
               throws IOException
New data available on xSocket connection.

Specified by:
onData in interface org.xsocket.connection.IDataHandler
Parameters:
connection - the connection
Returns:
true if the event was handled
Throws:
IOException - error while processing incoming data.

onDisconnect

public boolean onDisconnect(org.xsocket.connection.INonBlockingConnection connection)
                     throws IOException
Disconnect event.

Specified by:
onDisconnect in interface org.xsocket.connection.IDisconnectHandler
Parameters:
connection - the disconnected connection
Returns:
true if the event was handled
Throws:
IOException - error handling disconnect event

onIdleTimeout

public boolean onIdleTimeout(org.xsocket.connection.INonBlockingConnection connection)
                      throws IOException
Idle time out event.

Specified by:
onIdleTimeout in interface org.xsocket.connection.IIdleTimeoutHandler
Parameters:
connection - the idle connection
Returns:
true if the event has handled
Throws:
IOException - error handling idle timeout

packetSent

public void packetSent(ISocketServerConnection connection,
                       int size)
Data sent notification.

Specified by:
packetSent in interface ISocketServerConnectionListener
Parameters:
connection - connection
size - the size of the data sent

run

public void run()
         throws IOException
Stars the server in the current thread.

Specified by:
run in interface ISocketServer
Throws:
IOException - error starting the server
See Also:
es.tsbsoluciones.socketServer.ISocketServer#run()

setIP

public void setIP(String ip)
Sets the IP to bind the port.

Specified by:
setIP in interface ISocketServer
Parameters:
ip - the IP to be used to bind the port

start

public void start()
           throws IOException
Starts the server in a different thread.

Specified by:
start in interface ISocketServer
Throws:
IOException - error starting the server


Copyright © 2014 universAAL Consortium. All Rights Reserved.