org.abstracthorizon.danube.service.server
Class MultiThreadServerService

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

public abstract class MultiThreadServerService
extends ServerService

This class models multi-threaded model of connection service. Each new connection is spawned in a separate, possibly new, thread obtained from given executor. Connections passed to the thread must be of ServerConnection type in order for close method to be called at the end of processing.

Author:
Daniel Sendula

Nested Class Summary
protected  class MultiThreadServerService.ConnectionHandlerThread
          This class is executed in under the given executor.
 
Field Summary
protected  Set<MultiThreadServerService.ConnectionHandlerThread> activeConnections
          Set of active connections
protected  Executor executor
          Executor (thread pool) to be used
protected  int graceFinishPeriod
          Grace period for connections to finish after service state changes to STOPPING
 
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
MultiThreadServerService()
          Default constructor
 
Method Summary
 Set<MultiThreadServerService.ConnectionHandlerThread> getActiveConnections()
          Returns active connections
 Executor getExecutor()
          Return the executor which is used or connections to be handled with
 int getGraceFinishPeriod()
          Returns grace finish period
 int getNumberOfActiveConnections()
          Returns number of active connections
protected abstract  void processConnections()
          This method processes connections
 void run()
          Accepts connections from processes them
 void setExecutor(Executor executor)
          Sets the executor for connections to be handled with
 void setGraceFinishPeriod(int graceFinishPeriod)
          Sets grace finish period
 void start()
          Starts the service
 void stop()
          Stops the service.
 
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, create, destroy, 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

graceFinishPeriod

protected int graceFinishPeriod
Grace period for connections to finish after service state changes to STOPPING


executor

protected Executor executor
Executor (thread pool) to be used


activeConnections

protected Set<MultiThreadServerService.ConnectionHandlerThread> activeConnections
Set of active connections

Constructor Detail

MultiThreadServerService

public MultiThreadServerService()
Default constructor

Method Detail

getGraceFinishPeriod

public int getGraceFinishPeriod()
Returns grace finish period

Returns:
grace finish period

setGraceFinishPeriod

public void setGraceFinishPeriod(int graceFinishPeriod)
Sets grace finish period

Parameters:
graceFinishPeriod - grace finish period

getExecutor

public Executor getExecutor()
Return the executor which is used or connections to be handled with

Returns:
the executor

setExecutor

public void setExecutor(Executor executor)
Sets the executor for connections to be handled with

Parameters:
executor -

getActiveConnections

public Set<MultiThreadServerService.ConnectionHandlerThread> getActiveConnections()
Returns active connections

Returns:
connections

getNumberOfActiveConnections

public int getNumberOfActiveConnections()
Returns number of active connections

Returns:
number of active connections

start

public void start()
           throws ServiceException
Starts the service

Overrides:
start in class Service
Throws:
ServiceException

stop

public void stop()
          throws ServiceException
Stops the service.

Overrides:
stop in class Service
Throws:
ServiceException

run

public void run()
Accepts connections from processes them


processConnections

protected abstract void processConnections()
This method processes connections



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