com.voytechs.jnetstream.codec.event
Class DecoderSupport

java.lang.Object
  extended by com.voytechs.jnetstream.codec.event.DecoderSupport
Direct Known Subclasses:
FlowDecoder, PlaybackDecoder

public class DecoderSupport
extends java.lang.Object

This is a dispatcher support class for Decoder decodes. This class maintains a list of listeners on certain events. When that event occures it is dispatched to all of the listeners. Events are fired off only when the entire structure is complete. For example when a Packet is created and all of the headers are added into it and no more Headers can be added to it, then as the last step event is fired off to all of the listeners. For Header event, it is fired only when the top-level header is completed. Any subheaders that are completed, but are being merged into the top level header do not generate events.


Field Summary
static java.lang.String EVENT_ALL
           
 
Constructor Summary
DecoderSupport()
          Initializes the support object.
 
Method Summary
 void addListener(DecoderListener listener)
          Adds a new listener for all event types.
 void addListener(DecoderListener listener, java.lang.String eventType)
          Adds a new listener for a specific event type.
 void fireDecoderEvent(DecoderEvent event)
          Fire event when new Packet is created and finalized.
 java.util.List getListeners(java.lang.String eventType)
          Returns the list of listeners for specific event.
 java.util.List getListenersForAll()
          Returns the list of listeners for all events.
 boolean hasListeners()
          Returns true if support object has registered listeners.
 boolean hasListeners(java.lang.String eventType)
          Returns true if support object has registered listeners for specific event.
static void main(java.lang.String[] args)
          Test function for DecoderSupport
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

EVENT_ALL

public static final java.lang.String EVENT_ALL
See Also:
Constant Field Values
Constructor Detail

DecoderSupport

public DecoderSupport()
Initializes the support object.

Method Detail

addListener

public void addListener(DecoderListener listener)
Adds a new listener for all event types. To see complete list of events see DecoderEvent class.

Parameters:
listener - Listener to dispatch. Every event will cause a dispatch to the listener.
See Also:
DecoderEvent

addListener

public void addListener(DecoderListener listener,
                        java.lang.String eventType)
Adds a new listener for a specific event type.

Parameters:
listener - Listener for the event.
eventType - Event type to register the listener for. Only this specific event will trigger a dispatch to the listener.

getListeners

public java.util.List getListeners(java.lang.String eventType)
Returns the list of listeners for specific event. This method never returns null.

Parameters:
eventType - The even type for which to get listeners. This list will not include listeners that are listening to all events. Use the method getListenersForAll() to get that list.
Returns:
A list of listeners that are registered for a specific event.

getListenersForAll

public java.util.List getListenersForAll()
Returns the list of listeners for all events. This method never returns null.

Returns:
A list of listeners that are registered for all events.

fireDecoderEvent

public void fireDecoderEvent(DecoderEvent event)
                      throws AssertFailure
Fire event when new Packet is created and finalized.

Throws:
AssertFailure

hasListeners

public boolean hasListeners()
Returns true if support object has registered listeners.

Returns:
True if listeners are registered, otherwise false.*

hasListeners

public boolean hasListeners(java.lang.String eventType)
Returns true if support object has registered listeners for specific event.

Returns:
True if listeners are registered, otherwise false.*

main

public static void main(java.lang.String[] args)
Test function for DecoderSupport

Parameters:
args - command line arguments