org.abstracthorizon.danube.service.server
Class MultiThreadServerSocketChannelService

java.lang.Object
  extended by org.abstracthorizon.danube.service.Service
      extended by org.abstracthorizon.danube.service.server.ServerService
          extended by org.abstracthorizon.danube.service.server.MultiThreadServerService
              extended by org.abstracthorizon.danube.service.server.MultiThreadServerSocketChannelService
All Implemented Interfaces:
Runnable

public class MultiThreadServerSocketChannelService
extends MultiThreadServerService

This is server service that is implemented using socket channels. This service works in blocked IO mode and accepts connections from a server socket channel, creates new ConnectionHandlerThread objects and executes them in a given thread by Executor.

Author:
Daniel Sendula

Nested Class Summary
 
Nested classes/interfaces inherited from class org.abstracthorizon.danube.service.server.MultiThreadServerService
MultiThreadServerService.ConnectionHandlerThread
 
Field Summary
protected  int newSocketTimeout
          New socket timeout
protected  ServerSocketChannel serverSocketChannel
          Reference to the server socket
protected  int serverSocketTimeout
          Initial socket timeout
 
Fields inherited from class org.abstracthorizon.danube.service.server.MultiThreadServerService
activeConnections, executor, graceFinishPeriod
 
Fields inherited from class org.abstracthorizon.danube.service.server.ServerService
connectionHandler, socketAddress
 
Fields inherited from class org.abstracthorizon.danube.service.Service
DESTROYED, INITIALIZED, listeners, logger, name, NOT_INITIALIZED, RUNNING, SERVICE_STATE_NAMES, STARTED, STOPPED, STOPPING, stopService
 
Constructor Summary
MultiThreadServerSocketChannelService()
          Default constructor
 
Method Summary
 void create()
          Creates the socket
protected  void createServerSocket()
          Creates server socket
protected  Connection createSocketConnection(SocketChannel socketChannel)
          Creates new socket connection
 void destroy()
          Closes the server socket
protected  void destroyServerSocket()
          Closes server socket
 int getNewSocketTimeout()
          Returns new socket timeout
 int getServerSocketTimeout()
          Returns server socket timeout
protected  void processConnection(SocketChannel socketChannel)
          Creates socket connection and new instance of ConnectionHandlerThread to process socket under the given executor
protected  void processConnections()
          This method processes connections
 void setNewSocketTimeout(int socketTimeout)
          Sets new socket timeout
 void setServerSocketTimeout(int socketTimeout)
          Sets initial socket timeout
 
Methods inherited from class org.abstracthorizon.danube.service.server.MultiThreadServerService
getActiveConnections, getExecutor, getGraceFinishPeriod, getNumberOfActiveConnections, run, setExecutor, setGraceFinishPeriod, start, stop
 
Methods inherited from class org.abstracthorizon.danube.service.server.ServerService
getAddress, getConnectionHandler, getPort, getSocketAddress, setAddress, setConnectionHandler, setPort, setSocketAddress
 
Methods inherited from class org.abstracthorizon.danube.service.Service
addListener, changeState, getName, getState, getStateName, removeListener, setName
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

serverSocketTimeout

protected int serverSocketTimeout
Initial socket timeout


newSocketTimeout

protected int newSocketTimeout
New socket timeout


serverSocketChannel

protected ServerSocketChannel serverSocketChannel
Reference to the server socket

Constructor Detail

MultiThreadServerSocketChannelService

public MultiThreadServerSocketChannelService()
Default constructor

Method Detail

getServerSocketTimeout

public int getServerSocketTimeout()
Returns server socket timeout

Returns:
server socket timeout

setServerSocketTimeout

public void setServerSocketTimeout(int socketTimeout)
Sets initial socket timeout

Parameters:
socketTimeout - initial socket timeout

getNewSocketTimeout

public int getNewSocketTimeout()
Returns new socket timeout

Returns:
new socket timeout

setNewSocketTimeout

public void setNewSocketTimeout(int socketTimeout)
Sets new socket timeout

Parameters:
socketTimeout - new socket timeout

create

public void create()
            throws ServiceException
Creates the socket

Overrides:
create in class Service
Throws:
ServiceException

destroy

public void destroy()
             throws ServiceException
Closes the server socket

Overrides:
destroy in class Service
Throws:
ServiceException

processConnections

protected void processConnections()
This method processes connections

Specified by:
processConnections in class MultiThreadServerService

createServerSocket

protected void createServerSocket()
                           throws ServiceException
Creates server socket

Throws:
ServiceException

destroyServerSocket

protected void destroyServerSocket()
                            throws ServiceException
Closes server socket

Throws:
ServiceException

processConnection

protected void processConnection(SocketChannel socketChannel)
Creates socket connection and new instance of ConnectionHandlerThread to process socket under the given executor

Parameters:
socketChannel - socket channel

createSocketConnection

protected Connection createSocketConnection(SocketChannel socketChannel)
                                     throws IOException
Creates new socket connection

Parameters:
socketChannel - socket channel
Returns:
server connection
Throws:
IOException
Exception


Copyright © 2005-2009 Abstract Horizon. All Rights Reserved.