org.abstracthorizon.danube.service.server
Class MultiThreadServerSocketService

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.MultiThreadServerSocketService
All Implemented Interfaces:
Runnable
Direct Known Subclasses:
MultiThreadServerSSLSocketService

public class MultiThreadServerSocketService
extends MultiThreadServerService

This is server service that is implemented using sockets. This service accepts connections from a server socket, 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's timeout
protected  ServerSocket serverSocket
          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
MultiThreadServerSocketService()
          Default constructor
 
Method Summary
 void create()
          Creates the socket
protected  void createServerSocket()
          Creates server socket
protected  Connection createSocketConnection(Socket socket)
          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 initial socket timeout
protected  void processConnection(Socket socket)
          Creates server 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 server 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's timeout


serverSocket

protected ServerSocket serverSocket
Reference to the server socket

Constructor Detail

MultiThreadServerSocketService

public MultiThreadServerSocketService()
Default constructor

Method Detail

getServerSocketTimeout

public int getServerSocketTimeout()
Returns initial socket timeout

Returns:
initial socket timeout

setServerSocketTimeout

public void setServerSocketTimeout(int socketTimeout)
Sets server 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(Socket socket)
Creates server connection and new instance of ConnectionHandlerThread to process socket under the given executor

Parameters:
socket - socket

createSocketConnection

protected Connection createSocketConnection(Socket socket)
                                     throws IOException
Creates new socket connection

Parameters:
socket - socket
Returns:
socket connection
Throws:
IOException
Exception


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