org.abstracthorizon.danube.service.server
Class ServerConnectionHandler

java.lang.Object
  extended by org.abstracthorizon.danube.service.server.ServerConnectionHandler
All Implemented Interfaces:
ConnectionHandler
Direct Known Subclasses:
HTTPServerConnectionHandler

public class ServerConnectionHandler
extends Object
implements ConnectionHandler

This class is entry point for typical server that handles request sequentially.

Author:
Daniel Sendula

Field Summary
protected  ConnectionHandler connectionHandler
          Connection Handler
protected  org.slf4j.Logger logger
          Logger
 
Constructor Summary
ServerConnectionHandler()
          Constructor
 
Method Summary
protected  void closeConnection(Connection connection)
          Closes connection.
protected  Connection decorateConnection(Connection connection)
          This method can "decorate" connection wrapping it with own.
protected  void finishProcessingConnection(Connection connection, boolean closedConnection)
          Finishes connection for this server connection handler.
 ConnectionHandler getConnectionHandler()
          Returns connection handler
 void handleConnection(Connection connection)
          This template method allows connection to be wrapped and then processes sequential requests/commands while socket is open or an exception occurs.
protected  boolean postProcessing(Connection connection)
          Post processing that should determine shell we persist connection (invoke handler again) or leave connection handler.
protected  void processConnection(Connection connection)
          Template method for processing of connection.
 void setConnectionHandler(ConnectionHandler connectionHandler)
          Sets connection handler
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

logger

protected final org.slf4j.Logger logger
Logger


connectionHandler

protected ConnectionHandler connectionHandler
Connection Handler

Constructor Detail

ServerConnectionHandler

public ServerConnectionHandler()
Constructor

Method Detail

setConnectionHandler

public void setConnectionHandler(ConnectionHandler connectionHandler)
Sets connection handler

Parameters:
connectionHandler -

getConnectionHandler

public ConnectionHandler getConnectionHandler()
Returns connection handler

Returns:
connection handler

handleConnection

public void handleConnection(Connection connection)
                      throws ConnectionException
This template method allows connection to be wrapped and then processes sequential requests/commands while socket is open or an exception occurs.

Specified by:
handleConnection in interface ConnectionHandler
Parameters:
connection - socket connection
Throws:
ConnectionException

processConnection

protected void processConnection(Connection connection)
Template method for processing of connection. Override it to perform what is needed. This method invokes given connection handler

Parameters:
connection - decorated

decorateConnection

protected Connection decorateConnection(Connection connection)
This method can "decorate" connection wrapping it with own. This implementation does nothing

Parameters:
connection - original conneciton
Returns:
decorated connection

postProcessing

protected boolean postProcessing(Connection connection)
Post processing that should determine shell we persist connection (invoke handler again) or leave connection handler.

Parameters:
connection - decorated connection
Returns:
true if we should persist connection

closeConnection

protected void closeConnection(Connection connection)
Closes connection. This method is called if there was an error and connection should not remain open. Can be overridden if something else needs to be performed before or after closing connection or to prevent closing connection.

Parameters:
connection - decorated connection

finishProcessingConnection

protected void finishProcessingConnection(Connection connection,
                                          boolean closedConnection)
Finishes connection for this server connection handler. This method can do some last minute clean up on decorated connection.

Parameters:
connection - decorated connection
closedConnection - has closeConnection(Connection) method called before


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