|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.abstracthorizon.danube.service.Service org.abstracthorizon.danube.service.server.ServerSocketChannelService
public class ServerSocketChannelService
This is server socket service. This service accepts connections from a
server socket, creates new ServerSocketChannelService.ConnectionHandlerThread
objects
and executes them in a given Executor
.
Nested Class Summary | |
---|---|
class |
ServerSocketChannelService.ConnectionHandlerThread
This class is executed in under the given executor. |
Field Summary | |
---|---|
protected Set<ServerSocketChannelService.ConnectionHandlerThread> |
activeConnections
Set of active connections |
protected ConnectionHandler |
connectionHandler
Connection handler new connection to be handed with |
protected Executor |
executor
Executor (thread pool) to be used |
protected int |
graceFinishPeriod
Grace period for connections to finish after service state changes to STOPPING |
protected int |
newSocketTimeout
New socket timeout |
protected int |
port
Port this service is going to listen on |
protected ServerSocketChannel |
serverSocketChannel
Reference to the server socket |
protected int |
serverSocketTimeout
Server socket timeout |
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 | |
---|---|
ServerSocketChannelService()
Default constructor |
Method Summary | |
---|---|
void |
create()
Creates the socket |
protected ServerSocketChannel |
createServerSocket()
Creates server socket |
protected Connection |
createSocketConnection(SocketChannel socketChannel)
Creates new socket connection |
void |
destroy()
Closes the server socket |
ConnectionHandler |
getConnectionHandler()
Returns connection handler connections are handed to. |
Executor |
getExecutor()
Return the executor which is used or connections to be handled with |
int |
getGraceFinishPeriod()
Returns grace finish period |
int |
getNewSocketTimeout()
Returns new socket timeout |
int |
getPort()
Returns the port service is expecting connections on |
int |
getServerSocketTimeout()
Returns initial socket timeout |
protected void |
processConnection(SocketChannel socket)
Creates socket connection and new instance of ServerSocketChannelService.ConnectionHandlerThread to process
socket under the given executor |
void |
run()
Accepts connections from server socket and calls #processConnection(Socket) method |
void |
setConnectionHandler(ConnectionHandler connectionHandler)
Sets connection handler |
void |
setExecutor(Executor executor)
Sets the executor for connections to be handled with |
void |
setGraceFinishPeriod(int graceFinishPeriod)
Sets grace finish period |
void |
setNewSocketTimeout(int socketTimeout)
Sets new socket timeout |
void |
setPort(int port)
Sets the port. |
void |
setServerSocketTimeout(int socketTimeout)
Sets initial socket timeout |
void |
start()
Starts the service |
void |
stop()
Stops the service. |
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 |
---|
protected ServerSocketChannel serverSocketChannel
protected int port
protected int serverSocketTimeout
protected int newSocketTimeout
protected Executor executor
protected Set<ServerSocketChannelService.ConnectionHandlerThread> activeConnections
protected ConnectionHandler connectionHandler
protected int graceFinishPeriod
Constructor Detail |
---|
public ServerSocketChannelService()
Method Detail |
---|
public int getPort()
public void setPort(int port)
create()
method is called.
port
- the portpublic int getServerSocketTimeout()
public void setServerSocketTimeout(int socketTimeout)
socketTimeout
- initial socket timeoutpublic int getNewSocketTimeout()
public void setNewSocketTimeout(int socketTimeout)
socketTimeout
- new socket timeoutpublic int getGraceFinishPeriod()
public void setGraceFinishPeriod(int graceFinishPeriod)
graceFinishPeriod
- grace finish periodpublic Executor getExecutor()
public void setExecutor(Executor executor)
executor
- public ConnectionHandler getConnectionHandler()
public void setConnectionHandler(ConnectionHandler connectionHandler)
connectionHandler
- connection handlerpublic void create() throws ServiceException
create
in class Service
ServiceException
public void start() throws ServiceException
start
in class Service
ServiceException
public void stop() throws ServiceException
stop
in class Service
ServiceException
public void destroy() throws ServiceException
destroy
in class Service
ServiceException
public void run()
#processConnection(Socket)
method
protected ServerSocketChannel createServerSocket() throws ServiceException
ServiceException
protected Connection createSocketConnection(SocketChannel socketChannel) throws IOException
socket
- socket
IOException
Exception
protected void processConnection(SocketChannel socket)
ServerSocketChannelService.ConnectionHandlerThread
to process
socket under the given executor
socket
- socket
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |