info.jedi.net
Class HandlerStack

java.lang.Object
  |
  +--info.jedi.net.HandlerStack

public class HandlerStack
extends java.lang.Object

Stors a stack of PacketHandlers and provides methods for accessing the PacketHandlers and sending messages/reporting errors.


Constructor Summary
HandlerStack()
          Creates an empty HandlerStack
 
Method Summary
 void add(PacketHandler nextHandler)
          Adds a PacketHandler to the top of this HandlerStack
 void initializePacket(OutputPacket packet)
          Initializes a packet to be sent.
 HandlerStackIterator iterator()
          Gets an iterator for this HandlerStack.
 void reportError(java.lang.Exception e, OutputPacket packet, HandlerStackIterator firstToReceive)
          Reports an error (given in the passed Exception).
 void sendPacket(OutputPacket packet)
          Sends a packet through this HandlerStack.
 void sendPacket(OutputPacket packet, HandlerStackIterator firstToSend)
          Sends a packet through this HandlerStack, starting with the location in the stack indicated by firstToSend.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

HandlerStack

public HandlerStack()
Creates an empty HandlerStack
Method Detail

add

public void add(PacketHandler nextHandler)
Adds a PacketHandler to the top of this HandlerStack

iterator

public HandlerStackIterator iterator()
Gets an iterator for this HandlerStack. The iterator is initialized to refer to the top PacketHandler in the stack.

sendPacket

public void sendPacket(OutputPacket packet)
                throws java.io.IOException
Sends a packet through this HandlerStack. Each PacketHandler in turn from the top down will be asked to send the packet, until we get to the bottom or one of them returns true (indicating that sending the packet is complete)

sendPacket

public void sendPacket(OutputPacket packet,
                       HandlerStackIterator firstToSend)
                throws java.io.IOException
Sends a packet through this HandlerStack, starting with the location in the stack indicated by firstToSend. Each PacketHandler in turn from there down will be asked to send the packet, until we get to the bottom or one of them returns true (indicating that sending the packet is complete)

reportError

public void reportError(java.lang.Exception e,
                        OutputPacket packet,
                        HandlerStackIterator firstToReceive)
Reports an error (given in the passed Exception). This error occurred in the sending of a particular OutputPacket. The first PacketHandler to have an opportunity to handle the error is passed in the firstToReceive iterator. Each PacketHandler in turn going up the stack will have a chance to process the error, until one of them returns true indicating that the error has been handled.

initializePacket

public void initializePacket(OutputPacket packet)
                      throws java.io.IOException
Initializes a packet to be sent. This writes all the appropriate headers to the packet. The PacketHandlers will have initializePacket() called on each one, starting from the bottom of the HandlerStack.