org.apache.catalina.connector.warp
Class WarpHandler

java.lang.Object
  |
  +--org.apache.catalina.connector.warp.WarpHandler
All Implemented Interfaces:
Lifecycle, java.lang.Runnable
Direct Known Subclasses:
WarpConnectionHandler, WarpRequestHandler

public abstract class WarpHandler
extends java.lang.Object
implements Lifecycle, java.lang.Runnable

Version:
CVS $Id: WarpHandler.java,v 1.9 2001/01/24 23:10:47 pier Exp $
Author:
Pier Fumagalli, Copyright © 1999, 2000 The Apache Software Foundation.

Field Summary
protected static boolean DEBUG
          Our debug flag status (Used to compile out debugging information).
 
Fields inherited from interface org.apache.catalina.Lifecycle
START_EVENT, STOP_EVENT
 
Constructor Summary
WarpHandler()
          Construct a new instance of a WarpHandler.
 
Method Summary
 void addLifecycleListener(LifecycleListener listener)
          Add a lifecycle event listener to this component.
protected  void debug(java.lang.Exception exc)
          Dump information for an Exception.
protected  void debug(java.lang.String msg)
          Dump a debug message.
protected  WarpConnection getConnection()
          Return the WarpConnection associated with this handler.
protected  WarpConnector getConnector()
          Return the WarpConnector associated with this handler.
protected  int getRequestID()
          Return the Request ID associated with this handler.
protected  void log(java.lang.Exception exc)
          Log an exception.
protected  void log(java.lang.String msg)
          Log a message.
abstract  boolean process(int type, byte[] buffer)
          Process a WARP packet.
protected  void processData(int type, byte[] buffer)
          Receive notification of data from a WarpConnection.
 void removeLifecycleListener(LifecycleListener listener)
          Remove a lifecycle event listener from this component.
 void run()
          Process WARP packets.
 void send(int type, byte[] buffer)
          Send a WARP packet.
 void send(int type, byte[] buffer, int offset, int len)
          Send a WARP packet.
 void send(int type, WarpPacket packet)
          Send a WARP packet.
protected  void setConnection(WarpConnection connection)
          Set the WarpConnection associated with this handler.
protected  void setRequestID(int rid)
          Set the Request ID associated with this handler.
 void start()
          Initialize this handler instance.
 void stop()
          Stop this handler.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEBUG

protected static final boolean DEBUG
Our debug flag status (Used to compile out debugging information).
Constructor Detail

WarpHandler

public WarpHandler()
Construct a new instance of a WarpHandler.
Method Detail

run

public final void run()
Process WARP packets.
This method will wait for data to be notified by a WarpConnection with the processData() method, and will handle it to the abstract process() method.
When process() returns false (meaning that there is no more data to process) this method will unregister this handler from the WarpConnection, and the thread created in init() will terminate.
Specified by:
run in interface java.lang.Runnable

start

public final void start()
                 throws LifecycleException
Initialize this handler instance.
This method will initialize this handler and starts the despooling thread that will handle the data to the processData() method.
NOTE: To receive data notification this WarpConnection must be registered in the WarpConnection. Only un-registration (when the thread exits) is performed.
Specified by:
start in interface Lifecycle
Following copied from interface: org.apache.catalina.Lifecycle
Throws:
IllegalStateException - if this component has already been started
LifecycleException - if this component detects a fatal error that prevents this component from being used

stop

public final void stop()
Stop this handler.
The thread associated with this handler is stopped and this instance is unregistered from the WarpConnection.
Specified by:
stop in interface Lifecycle
Following copied from interface: org.apache.catalina.Lifecycle
Throws:
IllegalStateException - if this component has not been started
LifecycleException - if this component detects a fatal error that needs to be reported

processData

protected final void processData(int type,
                                 byte[] buffer)
Receive notification of data from a WarpConnection.
Parameters:
type - The WARP packet type.
buffer - The WARP packet payload.

send

public final void send(int type,
                       byte[] buffer,
                       int offset,
                       int len)
                throws java.io.IOException
Send a WARP packet.
This method will send a WARP packet back to the client, invoking the send() method in the WarpConnection associated with this WarpHandler with the appropriate WARP RID.
Parameters:
type - The WARP packet type.
buffer - The buffer containing the data to send.
off - The offset in the buffer of the data to send.
len - The number of bytes to send.
Throws:
java.io.IOException - If something happened sending the data.

send

public final void send(int type,
                       WarpPacket packet)
                throws java.io.IOException
Send a WARP packet.
This method will send a WARP packet back to the client, invoking the send() method in the WarpConnection associated with this WarpHandler with the appropriate WARP RID.
Parameters:
type - The WARP packet type.
packet - The packet to write.
Throws:
java.io.IOException - If something happened sending the data.

send

public final void send(int type,
                       byte[] buffer)
                throws java.io.IOException
Send a WARP packet.
This method is equivalent to send(type, buffer, 0, buffer.length).
Parameters:
type - The WARP packet type.
buffer - The buffer containing the data to send.
Throws:
java.io.IOException - If something happened sending the data.

process

public abstract boolean process(int type,
                                byte[] buffer)
Process a WARP packet.
This method is the one which will actually perform the operation of analyzing the packet and doing whatever needs to be done.
This method will return true if another packet is expected for this RID, or it will return false if this was the last packet for this RID. When we return false this handler is unregistered, and the Thread started in the init() method is terminated.
Parameters:
type - The WARP packet type.
buffer - The WARP packet payload.
Returns:
If more packets are expected for this RID, true is returned, false if this was the last packet.

addLifecycleListener

public void addLifecycleListener(LifecycleListener listener)
Add a lifecycle event listener to this component.
Specified by:
addLifecycleListener in interface Lifecycle
Following copied from interface: org.apache.catalina.Lifecycle
Parameters:
listener - The listener to add

removeLifecycleListener

public void removeLifecycleListener(LifecycleListener listener)
Remove a lifecycle event listener from this component.
Specified by:
removeLifecycleListener in interface Lifecycle
Following copied from interface: org.apache.catalina.Lifecycle
Parameters:
listener - The listener to remove

getConnection

protected WarpConnection getConnection()
Return the WarpConnection associated with this handler.

getConnector

protected WarpConnector getConnector()
Return the WarpConnector associated with this handler.

setConnection

protected void setConnection(WarpConnection connection)
Set the WarpConnection associated with this handler.

getRequestID

protected int getRequestID()
Return the Request ID associated with this handler.

setRequestID

protected void setRequestID(int rid)
Set the Request ID associated with this handler.

log

protected void log(java.lang.String msg)
Log a message.
Parameters:
msg - The error message to log.

log

protected void log(java.lang.Exception exc)
Log an exception.
Parameters:
e - The exception to log.

debug

protected void debug(java.lang.String msg)
Dump a debug message.

debug

protected void debug(java.lang.Exception exc)
Dump information for an Exception.


Copyright ? 2000 Apache Software Foundation. All Rights Reserved.