org.jnetstream.protocol
Class NullProtocol

java.lang.Object
  extended by org.jnetstream.protocol.NullProtocol
All Implemented Interfaces:
ProtocolInfo

public class NullProtocol
extends java.lang.Object
implements ProtocolInfo

An empty, no action, stub stand-in. All methods throw UnsupportedOperationException.

Author:
Mark Bednarczyk, Sly Technologies, Inc.

Nested Class Summary
 
Nested classes/interfaces inherited from interface org.jnetstream.protocol.ProtocolInfo
ProtocolInfo.Binding, ProtocolInfo.ID, ProtocolInfo.Info, ProtocolInfo.Registry, ProtocolInfo.Suite
 
Field Summary
 
Fields inherited from interface org.jnetstream.protocol.ProtocolInfo
NO_BIT_INDEX
 
Constructor Summary
NullProtocol()
           
 
Method Summary
 void addBinding(ProtocolInfo.Binding binding)
           
 Codec[] getAvailableCodecs()
          Returns all available codecs for this protocol.
 ProtocolInfo.Binding[] getBindings()
          Gets all of the bindings current attached to this protocol
 int getBitIndex()
          Returns a special bit index for core protocols.
 java.util.Set getCharacteristics()
          Gets a set of special characteristics for this protocol.
 int getCharacteristicsValue()
          Retrieves various characteristics for this protocol.
 HeaderCodec getCodec()
          Returns the current Codec that is responsible for Encoding/Decoding the packet's data buffer to a decomposed state accessible using the Packet public API.
 ProtocolInfo.ID getID()
          Gets the ID, Identification object which uniquely identifies this protocol.
 int getLength(com.slytechs.utils.memory.BitBuffer bits, int offset)
           
 java.lang.String getName()
          Returns the name of this protocol.
 java.util.Set getProtocolReferences()
          Gets a list of all the protocols this protocol references either inside a codec or a binding.
 ProtocolInfo.Suite getSuite()
          Returns the protocol suite this protocol belongs to.
 java.lang.Class getType()
           
 boolean isLoaded()
          Checks if any of the current protocol's codecs have been loaded.
 boolean isProtocolGroup()
          Method which checks if this protocol is actually a protocol group.
 boolean prioritiseBindings()
          Forces the protocol to reprioritize its bindings.
 void pushCodec(HeaderCodec codec)
          Pushes codec on to a prioritised queue where the highest priority codec is used for actively decoding header content.
 int setBindingWeight(int weight)
          Changes the prioritisation weight of bindings for this protocol.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

NullProtocol

public NullProtocol()
Method Detail

addBinding

public void addBinding(ProtocolInfo.Binding binding)
Specified by:
addBinding in interface ProtocolInfo

getAvailableCodecs

public Codec[] getAvailableCodecs()
Description copied from interface: ProtocolInfo
Returns all available codecs for this protocol. All the available codecs have already been loaded into memory.

Specified by:
getAvailableCodecs in interface ProtocolInfo
Returns:
array of currently available codecs
See Also:
ProtocolInfo.isLoaded()

getBindings

public ProtocolInfo.Binding[] getBindings()
Description copied from interface: ProtocolInfo
Gets all of the bindings current attached to this protocol

Specified by:
getBindings in interface ProtocolInfo
Returns:
array of bindinds

getBitIndex

public int getBitIndex()
Description copied from interface: ProtocolInfo
Returns a special bit index for core protocols. Bit indexes are used to significantly speedup the process of caching certain protocol information within a packet. Only the core protocols can provide a bit index. All other non-core protocols must return value of 0.

Specified by:
getBitIndex in interface ProtocolInfo
Returns:
bit index if this is a core protocol, otherwise 0

getCharacteristics

public java.util.Set getCharacteristics()
Description copied from interface: ProtocolInfo
Gets a set of special characteristics for this protocol. The set contains various types of characteristics such as Frame and Physical. Each class of characteristics is defined in its own enum structure which can be used to check against the set.
 Protocol ethernet = // from some source
 Set<Characteristics> ch = ethernet.getCharacteristics();
 if (ch.contains(Frame.HasCRC)) {
   // Do something
 } else if (ch.contains(Physical.Serial)) {
   // Do something with a serial line based protocol
 }
 

Specified by:
getCharacteristics in interface ProtocolInfo
Returns:
a set containing any special characteristics that this protocol has

getCharacteristicsValue

public int getCharacteristicsValue()
Description copied from interface: ProtocolInfo
Retrieves various characteristics for this protocol.

Specified by:
getCharacteristicsValue in interface ProtocolInfo
Returns:
a 32-bit unsigned integer value whos bits are encoded with various characteristics for this protocol
See Also:
method for description of how decode characteristic enum constants out of the integer representation

getCodec

public HeaderCodec getCodec()
Description copied from interface: ProtocolInfo
Returns the current Codec that is responsible for Encoding/Decoding the packet's data buffer to a decomposed state accessible using the Packet public API. Each codec is assigned a priority which determines which one is actively used, if more than one codec exists for a protocol. You can check codec priority with getPriority and change it using setPriority

Specified by:
getCodec in interface ProtocolInfo
Returns:
the currently assigned codec
See Also:
HeaderCodec#getPriority(), HeaderCodec#setPriority(org.jnetstream.protocol.codec.HeaderCodec.Priority)

getID

public ProtocolInfo.ID getID()
Description copied from interface: ProtocolInfo
Gets the ID, Identification object which uniquely identifies this protocol. Each protocol is assigned a unique ID object and a unique integer hash value. The ID structure can be used to uniquely identify a protocol.

Specified by:
getID in interface ProtocolInfo
Returns:
ID structure that uniquely identifies this protocol

getLength

public int getLength(com.slytechs.utils.memory.BitBuffer bits,
                     int offset)
Specified by:
getLength in interface ProtocolInfo
offset - TODO
Returns:

getName

public java.lang.String getName()
Description copied from interface: ProtocolInfo
Returns the name of this protocol. Protocol names are unique.

Specified by:
getName in interface ProtocolInfo
Returns:
name of this protocol
See Also:
ProtocolInfo.ID.getIdString()

getProtocolReferences

public java.util.Set getProtocolReferences()
Description copied from interface: ProtocolInfo
Gets a list of all the protocols this protocol references either inside a codec or a binding.

Specified by:
getProtocolReferences in interface ProtocolInfo
Returns:
list of all the referenced protocols

getSuite

public ProtocolInfo.Suite getSuite()
Description copied from interface: ProtocolInfo
Returns the protocol suite this protocol belongs to. Many protocol suites have been predefined for all standard and common protocols.

Specified by:
getSuite in interface ProtocolInfo
Returns:
protocol suite of this protocol
See Also:
ProtocolInfo.Suite

getType

public java.lang.Class getType()
Specified by:
getType in interface ProtocolInfo
Returns:

isLoaded

public boolean isLoaded()
Description copied from interface: ProtocolInfo
Checks if any of the current protocol's codecs have been loaded. Each protocol can have a number of codecs assigned to it. The codecs are first assigned by a reference ID, but not neccessarily loaded into memory. When the codec is needed for decoding of a packet, and its not currently loaded, the protocol will request that the codec be loaded into memory. This may take a slight amount of time to do, but only needs to be done once. After the codec has been loaded it remains in memory and is available for immediate utilization.

Specified by:
isLoaded in interface ProtocolInfo
Returns:
true if any of the protocol's codecs has been loaded, otherwise false.
See Also:
ProtocolInfo.pushCodec(HeaderCodec)

isProtocolGroup

public boolean isProtocolGroup()
Description copied from interface: ProtocolInfo
Method which checks if this protocol is actually a protocol group. Protocol groups do not have any codecs, only pure bindings. All CODEC related methods are disabled, therefore it is required to check first if this protocol is a normal or a group protocol.

Specified by:
isProtocolGroup in interface ProtocolInfo
Returns:
true means that this is a protocol group, otherwise false

prioritiseBindings

public boolean prioritiseBindings()
Description copied from interface: ProtocolInfo
Forces the protocol to reprioritize its bindings. Each binding keeps a hit counter which is incremented when a binding succeeds and decremented when it fails. The hit counter is used to place bindings that are successful more often at the front of the list. This allows a more popular binding to be at the top of the list which is more efficient in most cases. The protocol automatically reprioritises the binding list according to binding prioritisation weight setBindingWeight.

Specified by:
prioritiseBindings in interface ProtocolInfo
Returns:
true means that changes did occur as a result of the prioritization, otherwise false
See Also:
ProtocolInfo.setBindingWeight(int)

pushCodec

public void pushCodec(HeaderCodec codec)
Description copied from interface: ProtocolInfo
Pushes codec on to a prioritised queue where the highest priority codec is used for actively decoding header content. Each codec is assigned a priority which determines which one of the codecs is currently active.

Specified by:
pushCodec in interface ProtocolInfo
Parameters:
codec - codec to push on to the priority queue list
See Also:
HeaderCodec#getPriority(), HeaderCodec#setPriority(org.jnetstream.protocol.codec.HeaderCodec.Priority)

setBindingWeight

public int setBindingWeight(int weight)
Description copied from interface: ProtocolInfo
Changes the prioritisation weight of bindings for this protocol. The lower the value, the more often the protocol will reprioritize the bindings according to their usage.

Specified by:
setBindingWeight in interface ProtocolInfo
Parameters:
weight - A non negative value specifying the priority weight. The lower the value the more often reprioritization algorithm is run. A value of zero turns off prioritization completely.
Returns:
the previous weight value
See Also:
ProtocolInfo.prioritiseBindings()