com.flat502.rox.processing
Class HttpMessageHandler

java.lang.Object
  extended by com.flat502.rox.processing.HttpMessageHandler
All Implemented Interfaces:
java.lang.Runnable

public abstract class HttpMessageHandler
extends java.lang.Object
implements java.lang.Runnable

An abstract base class used by the default client and server implementation to process complete HTTP messages.


Constructor Summary
protected HttpMessageHandler(BlockingQueue queue)
          Constructs a new instance coupled to a BlockingQueue.
 
Method Summary
protected  void handleHttpMessageException(HttpMessageBuffer msg, java.lang.Throwable exception)
          Called when an error occurs while handling an HTTP message.
protected abstract  void handleMessage(HttpMessageBuffer msg)
          Called to handle complete HTTP messages.
protected  void handleProcessingException(ProcessingException exception)
          Called when an error occurs that is not related to an HTTP message.
 void run()
          Processes work items dequeued from the BlockingQueue associated with this instance.
 void stop()
          Stops this instance.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

HttpMessageHandler

protected HttpMessageHandler(BlockingQueue queue)
Constructs a new instance coupled to a BlockingQueue.

Parameters:
queue - The queue from which this instance should fetch new work items.
Method Detail

run

public void run()
Processes work items dequeued from the BlockingQueue associated with this instance.

The default implementation of HttpRpcProcessor enqueues two types of items on the underlying queue:

  1. HttpMessageBuffer instances, representing complete HTTP messages received from a remote entity. These are passed to handleMessage(HttpMessageBuffer) for processing.
  2. HttpMessageException instances when an error occurs while compiling an HTTP message. These are unpacked and passed to handleHttpMessageException(HttpMessageBuffer, Throwable) for processing.

Specified by:
run in interface java.lang.Runnable

stop

public void stop()
Stops this instance.

If this instance is busy with a work item it is completed.


handleMessage

protected abstract void handleMessage(HttpMessageBuffer msg)
                               throws java.lang.Exception
Called to handle complete HTTP messages.

Parameters:
msg - The complete HTTP message.
Throws:
java.lang.Exception - Implementations may raise an exception if an error occurs during processing.

handleHttpMessageException

protected void handleHttpMessageException(HttpMessageBuffer msg,
                                          java.lang.Throwable exception)
Called when an error occurs while handling an HTTP message.

The default implementation raises an IllegalStateException.

Parameters:
msg - The HTTP message that was being processed when the exception was raised.
exception - The exception that was raised.

handleProcessingException

protected void handleProcessingException(ProcessingException exception)
Called when an error occurs that is not related to an HTTP message.

The default implementation raises an IllegalStateException.

Parameters:
exception - The exception that was raised.