org.abstracthorizon.danube.support.logging
Class LoggingConnectionHandler

java.lang.Object
  extended by org.abstracthorizon.danube.support.logging.LoggingConnectionHandler
All Implemented Interfaces:
ConnectionHandler

public class LoggingConnectionHandler
extends Object
implements ConnectionHandler

Connection handler that logs connection to a file.

Author:
Daniel Sendula

Nested Class Summary
static class LoggingConnectionHandler.InternalFileOutputStream
          This is helper class that adds reference to original File class passed in FileOutputStream.
 
Field Summary
protected  Pattern addressPattern
          Client socket address pattern
protected  String logFileNamePattern
          Log file name pattern
protected  org.slf4j.Logger logger
          Logger
 
Constructor Summary
LoggingConnectionHandler()
          Constructor
 
Method Summary
protected  void closeOutputStream(LoggingConnection loggingConnection, OutputStream logOutputStream)
          This method closes output stream and then checks if it needs to be removed or not.
protected  OutputStream createLogOutputStream(Connection connection, boolean temporary)
          This method creates log output stream.
 String getAddressPattern()
          Returns address pattern.
 ConnectionHandler getConnectionHandler()
          Returns connection handler
 String getLogFileNamePattern()
          Returns log file name pattern
 File getLogsPath()
          Returns log files path
 void handleConnection(Connection connection)
          This method wrapps connection to logging connection and passes it further.
 boolean isDirectional()
          Is logging directional or not
 boolean isLogging()
          Returns if logging is switched on or off.
 boolean isResolveRemoteHostNames()
          Returns if host names should be resolved or not.
 boolean isTempLogging()
          Returns if temporary logs be created or not.
 void setAddressPattern(String addressPatternString)
          Sets socket address pattern.
 void setConnectionHandler(ConnectionHandler connectionHandler)
          Sets connection handler
 void setDirectional(boolean directional)
          Sets for logging to be directional or not
 void setLogFileNamePattern(String logFileNamePatternString)
          Sets the log file name pattern.
 void setLogging(boolean logging)
          Switches logging on or off
 void setLogsPath(File logsPath)
          Sets log files path
 void setResolveRemoteHostNames(boolean resolveRemoteHostNames)
          Sets if remote host names are to be resolved or not.
 void setTempLogging(boolean tempLogging)
          Sets temporary logging.
 
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


addressPattern

protected Pattern addressPattern
Client socket address pattern


logFileNamePattern

protected String logFileNamePattern
Log file name pattern

Constructor Detail

LoggingConnectionHandler

public LoggingConnectionHandler()
Constructor

Method Detail

getAddressPattern

public String getAddressPattern()
Returns address pattern.

Returns:
returns address pattern.

setAddressPattern

public void setAddressPattern(String addressPatternString)
Sets socket address pattern. Only socket host addresses (or names, see {@link #setResolveRemoteHostNames(boolean)) that match this pattern will create log files or temporary log files.

Parameters:
addressPatternString -

getConnectionHandler

public ConnectionHandler getConnectionHandler()
Returns connection handler

Returns:
connection handler

setConnectionHandler

public void setConnectionHandler(ConnectionHandler connectionHandler)
Sets connection handler

Parameters:
connectionHandler - connection handler

isDirectional

public boolean isDirectional()
Is logging directional or not

Returns:
if logging is directional

setDirectional

public void setDirectional(boolean directional)
Sets for logging to be directional or not

Parameters:
directional - is logging directional or not

getLogFileNamePattern

public String getLogFileNamePattern()
Returns log file name pattern

Returns:
log file name pattern

setLogFileNamePattern

public void setLogFileNamePattern(String logFileNamePatternString)
Sets the log file name pattern. The following pattern codes are supported:


isLogging

public boolean isLogging()
Returns if logging is switched on or off. If it is switched off no logging will occur for current connection

Returns:
if logging is switched on or off

setLogging

public void setLogging(boolean logging)
Switches logging on or off

Parameters:
logging - true if logging is to be switched on

getLogsPath

public File getLogsPath()
Returns log files path

Returns:
log files path

setLogsPath

public void setLogsPath(File logsPath)
Sets log files path

Parameters:
logsPath - log files path

isTempLogging

public boolean isTempLogging()
Returns if temporary logs be created or not.

Returns:
is temporary logging switched on

setTempLogging

public void setTempLogging(boolean tempLogging)
Sets temporary logging. If address is matched then log is going to be permanent. If address is not matched and temporary logging is on then log is going to be created as temporary log. Temporary log is removed at the end of the connection handling unless its state is changed within LoggingConnection itself.

Parameters:
tempLogging -

isResolveRemoteHostNames

public boolean isResolveRemoteHostNames()
Returns if host names should be resolved or not. It is used in matching remote socket address (setAddressPattern(String))

Returns:
if host names should be resolved or not.

setResolveRemoteHostNames

public void setResolveRemoteHostNames(boolean resolveRemoteHostNames)
Sets if remote host names are to be resolved or not. It is used in matching remote socket address (setAddressPattern(String))

Parameters:
resolveRemoteHostNames -

handleConnection

public void handleConnection(Connection connection)
This method wrapps connection to logging connection and passes it further. Will connection be wrapped or not depetns on isLogging(), getAddressPattern() and isTempLogging().

Specified by:
handleConnection in interface ConnectionHandler
Parameters:
connection - original connection

createLogOutputStream

protected OutputStream createLogOutputStream(Connection connection,
                                             boolean temporary)
This method creates log output stream. This implementation returns LoggingConnectionHandler.InternalFileOutputStream but it can be overriden with any other output stream.

Parameters:
connection - original connection
temporary - is file supposed to be temporary or not
Returns:
log output stream

closeOutputStream

protected void closeOutputStream(LoggingConnection loggingConnection,
                                 OutputStream logOutputStream)
This method closes output stream and then checks if it needs to be removed or not.

Parameters:
loggingConnection - logging connection
logOutputStream - log output stream


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