simtools.util
Class PacketBufferFactory

java.lang.Object
  extended by simtools.util.PacketBufferFactory

public abstract class PacketBufferFactory
extends java.lang.Object

A packet buffer factory holds a predefined list of packet buffers identified by a key (one per buffer) The key allows to the buffer used to store and retrieve the packets


Field Summary
protected  java.util.HashMap map
           
 
Constructor Summary
protected PacketBufferFactory()
          Creates an empty factory to be filled by overiding
 
Method Summary
 java.lang.Object add(java.nio.ByteBuffer bb)
          Add a new packet to a packet buffer according to the key returned by getKey
 void addDataError(java.lang.String data, java.lang.String error)
          Add a data error
 java.lang.Object addPacketBuffer(java.lang.Object key, PacketBuffer packetBuffer)
          Method addPacketBuffer Summary: Use this method to add a packetBuffer to the factory.
protected  void addRejectedPacket(java.lang.Object key)
          Add a rejected packet to the given key.
protected abstract  PacketBuffer contructPacketBuffer(java.lang.Object key)
          Method contructPacketBuffer.
 java.lang.String getDataErrorMessage()
          Returns the message that contains the errors for each data name.
 int getDataErrorNumber()
          return the total number of data errors.
 PacketBufferFactory getFactory(java.lang.Class factoryClass)
          Method getFactory Summary: return the Factory instance, that correspond with the given class.
abstract  PacketBufferFactory getInnerFactory()
          Method getInnerFactory Summary: This method return the inner factory, if exists.
protected abstract  java.lang.Object getInnerKey(java.lang.Object localKey)
          Return the key to be used in the inner factory computed from a local key.
abstract  java.lang.Object getKey(java.nio.ByteBuffer bb)
          Return the packet key
protected  java.lang.String getKeyStringDisplay(java.lang.Object key)
          Return a String representation of the given key.
 PacketBuffer getPacketBuffer(java.lang.Object key, boolean createIfNotFound)
          Method getPacketBuffer Summary: Use this method to get a packetBuffer from the facotry, using the given key.
 java.lang.String getRejectedPacketMessage()
          Returns the message that contains the number of errors for each filter.
 int getRejectedPacketNumber()
          return the total number of rejected packet for this factory.
protected  java.lang.String logByteBuffer(java.nio.ByteBuffer bb)
          Returns the String representation of a byteBuffer, with a byte content view, displayed as hexadecimal content.
 void registerListener(PacketBuffer.Listener listener, java.lang.Object key)
          register the given listener to the corresponding key.
 void reset()
          Reset all the buffers available in this factory and the inner factories if any
 void resetDataErrorMap()
          Resets the error and rejected maps.
 void resetRejectedPacketMap()
          Resets the error and rejected maps.
 void unregisterListener(PacketBuffer.Listener listener, java.lang.Object key)
          Unregister the given listener to the corresponding key.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

map

protected java.util.HashMap map
Constructor Detail

PacketBufferFactory

protected PacketBufferFactory()
Creates an empty factory to be filled by overiding

Method Detail

add

public java.lang.Object add(java.nio.ByteBuffer bb)
                     throws PacketBufferValidationError
Add a new packet to a packet buffer according to the key returned by getKey

Parameters:
bb - The byteBuffer to add to factory.
Returns:
the key The key of the packetBuffer that received the byteBuffer.
Throws:
PacketBufferValidationError

addRejectedPacket

protected void addRejectedPacket(java.lang.Object key)
Add a rejected packet to the given key.

Parameters:
key - The key of the rejected packet.

addDataError

public void addDataError(java.lang.String data,
                         java.lang.String error)
Add a data error

Parameters:
data - The dataName concerned by this error
error - The message of the error.

getRejectedPacketNumber

public int getRejectedPacketNumber()
return the total number of rejected packet for this factory.

Returns:
int the total number of rejected packet for this factory.

getRejectedPacketMessage

public java.lang.String getRejectedPacketMessage()
Returns the message that contains the number of errors for each filter.

Returns:
The message that contains the number of errors for each filter.

getKeyStringDisplay

protected java.lang.String getKeyStringDisplay(java.lang.Object key)
Return a String representation of the given key. For message display.

Parameters:
key - The key to return the String representation.
Returns:
the String representation of the given key.

getDataErrorNumber

public int getDataErrorNumber()
return the total number of data errors.

Returns:
int the total number of rejected packet for this factory.

getDataErrorMessage

public java.lang.String getDataErrorMessage()
Returns the message that contains the errors for each data name.

Returns:
The message that contains the errors for each data name.

logByteBuffer

protected java.lang.String logByteBuffer(java.nio.ByteBuffer bb)
Returns the String representation of a byteBuffer, with a byte content view, displayed as hexadecimal content.

Parameters:
bb - The byteBuffer to be displayed.
Returns:
(String) the String representation of a byteBuffer, with a byte content view , displayed as hexadecimal content.

getKey

public abstract java.lang.Object getKey(java.nio.ByteBuffer bb)
Return the packet key

Parameters:
bb -
Returns:

addPacketBuffer

public java.lang.Object addPacketBuffer(java.lang.Object key,
                                        PacketBuffer packetBuffer)
Method addPacketBuffer Summary: Use this method to add a packetBuffer to the factory.

Parameters:
key - To key to store the PacketBuffer.
packetBuffer - The PacketBuffer to store.
Returns:
Object The key used to insert the PacketBuffer, or null, if packet was not inserted.

getPacketBuffer

public PacketBuffer getPacketBuffer(java.lang.Object key,
                                    boolean createIfNotFound)
Method getPacketBuffer Summary: Use this method to get a packetBuffer from the facotry, using the given key. return null, if no packet buffer has been found using this key.

Parameters:
key - The key to found the PacketBuffer.
createIfNotFound - If true, the call to the method will create the packet buffer if not found.
Returns:
PacketBuffer The PacketBuffer at the given Key, or null if not found.

contructPacketBuffer

protected abstract PacketBuffer contructPacketBuffer(java.lang.Object key)
Method contructPacketBuffer. Summary: This method return a new PacketBuffer. This method is used by the geetPacketBuffer, when creation on demand behavior is activated.

Parameters:
key - The key used to contruct the new packetBuffer.
Returns:
PacketBuffer The new PacketBuffer just contruct with the given key.

getInnerFactory

public abstract PacketBufferFactory getInnerFactory()
Method getInnerFactory Summary: This method return the inner factory, if exists.

Returns:
PacketBufferFactory The inner factory, if exists.

getInnerKey

protected abstract java.lang.Object getInnerKey(java.lang.Object localKey)
Return the key to be used in the inner factory computed from a local key.

Parameters:
localKey - The local key to convert to the inner key.
Returns:
(Object) The inner's factory corresponding key.

getFactory

public PacketBufferFactory getFactory(java.lang.Class factoryClass)
Method getFactory Summary: return the Factory instance, that correspond with the given class. check in the inner factory if searched factory does not correspond to current one.

Parameters:
factoryClass - The Factory's class to find.
Returns:
PacketBufferFactory The Factory instance, that correspond with the given class.

reset

public void reset()
Reset all the buffers available in this factory and the inner factories if any


resetDataErrorMap

public void resetDataErrorMap()
Resets the error and rejected maps.


resetRejectedPacketMap

public void resetRejectedPacketMap()
Resets the error and rejected maps.


registerListener

public void registerListener(PacketBuffer.Listener listener,
                             java.lang.Object key)
register the given listener to the corresponding key.

Parameters:
listener - The listener to register.
key - The key to find the packetBuffer to register the listener.

unregisterListener

public void unregisterListener(PacketBuffer.Listener listener,
                               java.lang.Object key)
Unregister the given listener to the corresponding key.

Parameters:
listener - The listener to unregister.
key - The key to find the packetBuffer to register the listener.