org.apache.directory.shared.asn1.codec.stateful
Class CallbackHistory

java.lang.Object
  extended byorg.apache.directory.shared.asn1.codec.stateful.CallbackHistory
All Implemented Interfaces:
DecoderCallback, EncoderCallback

public class CallbackHistory
extends java.lang.Object
implements DecoderCallback, EncoderCallback

A convenience callback which collects decoded or encoded objects to audit a codecs's activity. The callback also comes in handy when data is to be pushed through a codec and grabed immediately afterwords to serialize codec operation.

Version:
$Rev: 379008 $
Author:
Apache Directory Project

Field Summary
private  java.util.LinkedList history
          history of decoded objects in cronological order
private  int length
          the length of callback history stored
 
Constructor Summary
CallbackHistory()
          Creates an auditing callback that manages a history of indefinite length.
CallbackHistory(int length)
          Creates an auditing callback that manages a history of fixed or indefinite length.
 
Method Summary
 void clear()
          Clears the history of decoded items.
 void decodeOccurred(StatefulDecoder decoder, java.lang.Object decoded)
          Callback to deliver a fully decoded object.
 void encodeOccurred(StatefulEncoder encoder, java.lang.Object encoded)
          Callback to deliver a fully encoded object.
 java.lang.Object getMostRecent()
          Gets the most recent decoded object if one exists.
 java.lang.Object getOldest()
          Gets the oldest decoded object if one exists.
 boolean isEmpty()
          Tests to see if the history is empty.
 int size()
          Gets the number of decoded items in the callback history.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

history

private final java.util.LinkedList history
history of decoded objects in cronological order


length

private final int length
the length of callback history stored

Constructor Detail

CallbackHistory

public CallbackHistory()
Creates an auditing callback that manages a history of indefinite length.


CallbackHistory

public CallbackHistory(int length)
Creates an auditing callback that manages a history of fixed or indefinite length. If the length is fixed the history effectively becomes a FIFO structure.

Parameters:
length - the maximum length of callback history to store before dropping decoded items, a length of zero or 1 corresponds to indefinite history
Method Detail

decodeOccurred

public void decodeOccurred(StatefulDecoder decoder,
                           java.lang.Object decoded)
Description copied from interface: DecoderCallback
Callback to deliver a fully decoded object.

Specified by:
decodeOccurred in interface DecoderCallback
Parameters:
decoder - the stateful decoder driving the callback
decoded - the object that was decoded

encodeOccurred

public void encodeOccurred(StatefulEncoder encoder,
                           java.lang.Object encoded)
Callback to deliver a fully encoded object.

Specified by:
encodeOccurred in interface EncoderCallback
Parameters:
encoder - the stateful encoder driving the callback
encoded - the object that was encoded

getMostRecent

public java.lang.Object getMostRecent()
Gets the most recent decoded object if one exists.

Returns:
the most recent decoded object
Throws:
java.util.NoSuchElementException - if the history is empty

getOldest

public java.lang.Object getOldest()
Gets the oldest decoded object if one exists.

Returns:
the oldest decoded object
Throws:
java.util.NoSuchElementException - if the history is empty

isEmpty

public boolean isEmpty()
Tests to see if the history is empty.

Returns:
true if the history is empty, false otherwise

clear

public void clear()
Clears the history of decoded items.


size

public int size()
Gets the number of decoded items in the callback history.

Returns:
the number of decoded items in the callback history


Copyright © 2003-2006 . All Rights Reserved.