org.apache.james.socket
Class AbstractJamesHandler

java.lang.Object
  extended by org.apache.avalon.framework.logger.AbstractLogEnabled
      extended by org.apache.james.socket.AbstractJamesHandler
All Implemented Interfaces:
org.apache.avalon.cornerstone.services.connection.ConnectionHandler, org.apache.avalon.excalibur.pool.Poolable, org.apache.avalon.framework.logger.LogEnabled, org.apache.avalon.framework.service.Serviceable
Direct Known Subclasses:
DelegatingJamesHandler

public abstract class AbstractJamesHandler
extends org.apache.avalon.framework.logger.AbstractLogEnabled
implements org.apache.avalon.cornerstone.services.connection.ConnectionHandler, org.apache.avalon.excalibur.pool.Poolable, org.apache.avalon.framework.service.Serviceable

Common Handler code


Field Summary
protected  DNSService dnsServer
          The DNSService
protected  java.io.InputStream in
          The incoming stream of bytes coming from the socket.
protected  CRLFTerminatedReader inReader
          The reader associated with incoming characters.
protected  java.io.PrintWriter out
          The writer to which outgoing messages are written.
protected  java.io.OutputStream outs
          The socket's output stream
protected  java.lang.String remoteHost
          The remote host name obtained by lookup on the socket.
protected  java.lang.String remoteIP
          The remote IP address of the socket.
protected  java.net.Socket socket
          The TCP/IP socket over which the service interaction is occurring
protected  Watchdog theWatchdog
          The watchdog being used by this handler to deal with idle timeouts.
 
Constructor Summary
AbstractJamesHandler()
           
 
Method Summary
protected  void errorHandler(java.lang.RuntimeException e)
          Method which will be colled on error
 java.lang.String getName()
          The name of this handler.
 void handleConnection(java.net.Socket connection)
           
protected abstract  void handleProtocol()
          Handle the protocol
protected  void initHandler(java.net.Socket connection)
          Helper method for accepting connections.
protected abstract  void resetHandler()
          Resets the handler data to a basic state.
 void service(org.apache.avalon.framework.service.ServiceManager arg0)
           
abstract  void setConfigurationData(java.lang.Object theData)
          This method will be implemented checking for the correct class type.
 void setDnsServer(DNSService dnsServer)
           
 void setName(java.lang.String name)
          The name of this handler.
 void setStreamDumpDir(java.lang.String streamDumpDir)
          If not null, this will enable dump to file for tcp connections
 void setWatchdog(Watchdog theWatchdog)
          Set the Watchdog for use by this handler.
 java.lang.String toString()
          Use for context sensitive logging.
 void writeLoggedFlushedResponse(java.lang.String responseString)
          Write and flush a response string.
 void writeLoggedResponse(java.lang.String responseString)
          Write a response string.
 
Methods inherited from class org.apache.avalon.framework.logger.AbstractLogEnabled
enableLogging, getLogger, setupLogger, setupLogger, setupLogger
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

socket

protected java.net.Socket socket
The TCP/IP socket over which the service interaction is occurring


out

protected java.io.PrintWriter out
The writer to which outgoing messages are written.


in

protected java.io.InputStream in
The incoming stream of bytes coming from the socket.


inReader

protected CRLFTerminatedReader inReader
The reader associated with incoming characters.


outs

protected java.io.OutputStream outs
The socket's output stream


theWatchdog

protected Watchdog theWatchdog
The watchdog being used by this handler to deal with idle timeouts.


remoteHost

protected java.lang.String remoteHost
The remote host name obtained by lookup on the socket.


remoteIP

protected java.lang.String remoteIP
The remote IP address of the socket.


dnsServer

protected DNSService dnsServer
The DNSService

Constructor Detail

AbstractJamesHandler

public AbstractJamesHandler()
Method Detail

setConfigurationData

public abstract void setConfigurationData(java.lang.Object theData)
This method will be implemented checking for the correct class type.

Parameters:
theData - Configuration Bean.

service

public void service(org.apache.avalon.framework.service.ServiceManager arg0)
             throws org.apache.avalon.framework.service.ServiceException
Specified by:
service in interface org.apache.avalon.framework.service.Serviceable
Throws:
org.apache.avalon.framework.service.ServiceException
See Also:
Serviceable.service(org.apache.avalon.framework.service.ServiceManager)

initHandler

protected void initHandler(java.net.Socket connection)
                    throws java.io.IOException
Helper method for accepting connections. This MUST be called in the specializations.

Parameters:
connection - The Socket which belongs to the connection
Throws:
java.io.IOException - get thrown if an IO error is detected

handleConnection

public void handleConnection(java.net.Socket connection)
                      throws java.io.IOException
Specified by:
handleConnection in interface org.apache.avalon.cornerstone.services.connection.ConnectionHandler
Throws:
java.io.IOException
See Also:
ConnectionHandler.handleConnection(java.net.Socket)

errorHandler

protected void errorHandler(java.lang.RuntimeException e)
Method which will be colled on error

Parameters:
e - the RuntimeException

handleProtocol

protected abstract void handleProtocol()
                                throws java.io.IOException
Handle the protocol

Throws:
java.io.IOException - get thrown if an IO error is detected

resetHandler

protected abstract void resetHandler()
Resets the handler data to a basic state.


setWatchdog

public void setWatchdog(Watchdog theWatchdog)
Set the Watchdog for use by this handler.

Parameters:
theWatchdog - the watchdog

writeLoggedFlushedResponse

public final void writeLoggedFlushedResponse(java.lang.String responseString)
Write and flush a response string. The response is also logged. Should be used for the last line of a multi-line response or for a single line response.

Parameters:
responseString - the response string sent to the client

writeLoggedResponse

public final void writeLoggedResponse(java.lang.String responseString)
Write a response string. The response is also logged. Used for multi-line responses.

Parameters:
responseString - the response string sent to the client

setStreamDumpDir

public void setStreamDumpDir(java.lang.String streamDumpDir)
If not null, this will enable dump to file for tcp connections

Parameters:
streamDumpDir - the dir

setDnsServer

public void setDnsServer(DNSService dnsServer)

getName

public final java.lang.String getName()
The name of this handler. Used for context sensitive logging.

Returns:
the name, not null

setName

public final void setName(java.lang.String name)
The name of this handler. Note that this name should be file-system safe. Used for context sensitive logging.

Parameters:
name - the name to set

toString

public java.lang.String toString()
Use for context sensitive logging.

Overrides:
toString in class java.lang.Object
Returns:
the name of the handler


Copyright ? 2002-2009 The Apache Software Foundation. All Rights Reserved.