net.kwfgrid.gwes.uiproxy
Class SequenceBuffer

java.lang.Object
  extended by net.kwfgrid.gwes.uiproxy.AbstractBuffer
      extended by net.kwfgrid.gwes.uiproxy.SequenceBuffer
All Implemented Interfaces:
Buffer, Consumer
Direct Known Subclasses:
JDOMSequenceBuffer

public abstract class SequenceBuffer
extends AbstractBuffer

An abstract buffer implementation to order messages with sequence numbers. Subclasses must implement getSequenceNumber(message) to access the sequence number of an incoming message. A SequenceBuffer's client must explicitly initialize the buffer by setting the SequenceBuffer.first property to the first valid sequence number. The buffer will not return any messages on read() before this property has been set. This buffer supports the following properties:


Field Summary
protected  LinkedList _content
           
protected  BufferException _exception
           
protected  int _first
           
protected  boolean _initialized
           
protected  LinkedList _precontent
           
static String FIRST_PROPERTY_KEY
           
 
Fields inherited from class net.kwfgrid.gwes.uiproxy.AbstractBuffer
_id, _size, DEFAULT_SIZE, SIZE_PROPERTY_KEY
 
Constructor Summary
SequenceBuffer()
           
 
Method Summary
protected abstract  int getSequenceNumber(Object message)
          Generic method to access the sequence number of the specified message.
 void handle(Object message)
          Handle a message.
protected  void initialize(int first)
           
 Object[] read()
          Will always return messages in correct order.
 void setProperty(String key, String value)
          This implementation only interprets the Buffer.size property.
protected  void setSize(int size)
          Size should be set by setting property Buffer.size.
protected abstract  boolean shouldHandle(Object message)
          Determine if this buffer should handle the specified message.
 
Methods inherited from class net.kwfgrid.gwes.uiproxy.AbstractBuffer
getID, getSize, setID, setProperties
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

FIRST_PROPERTY_KEY

public static final String FIRST_PROPERTY_KEY
See Also:
Constant Field Values

_first

protected int _first

_initialized

protected boolean _initialized

_exception

protected BufferException _exception

_content

protected LinkedList _content

_precontent

protected LinkedList _precontent
Constructor Detail

SequenceBuffer

public SequenceBuffer()
Method Detail

getSequenceNumber

protected abstract int getSequenceNumber(Object message)
                                  throws Exception
Generic method to access the sequence number of the specified message. Sequence numbers are expected to be positive integers.

Throws:
Exception

setSize

protected void setSize(int size)
                throws BufferException
Description copied from class: AbstractBuffer
Size should be set by setting property Buffer.size.

Overrides:
setSize in class AbstractBuffer
Throws:
BufferException

initialize

protected void initialize(int first)
                   throws BufferException
Throws:
BufferException

setProperty

public void setProperty(String key,
                        String value)
                 throws BufferException
Description copied from class: AbstractBuffer
This implementation only interprets the Buffer.size property.

Specified by:
setProperty in interface Buffer
Overrides:
setProperty in class AbstractBuffer
Throws:
BufferException

handle

public void handle(Object message)
Description copied from interface: Buffer
Handle a message. The buffer itself determines if it is responsible for buffering the specified Message. Buffer overflows or other exceptions must be remembered internally and notified on forthcoming calls of read().

Specified by:
handle in interface Buffer
Specified by:
handle in interface Consumer
Specified by:
handle in class AbstractBuffer
Parameters:
message - The message.

shouldHandle

protected abstract boolean shouldHandle(Object message)
                                 throws Exception
Determine if this buffer should handle the specified message. Subclasses must override this method in order to sort out messages of interest.

Throws:
Exception

read

public Object[] read()
              throws BufferException
Will always return messages in correct order.

Specified by:
read in interface Buffer
Specified by:
read in class AbstractBuffer
Throws:
BufferException - If a message could not be handled for some reason.


Copyright © 2005-2011 Fraunhofer FIRST. All Rights Reserved.