org.jnetpcap.packet
Class JHeaderPool

java.lang.Object
  extended by org.jnetpcap.packet.JHeaderPool

public class JHeaderPool
extends java.lang.Object

A thread local pool of instances of headers. The header pool keeps track of instances of headers it allocates based on protocol and thread IDs. The class allows private pools and also provides a global singleton pool which can be referenced from anywhere.

Author:
Mark Bednarczyk, Sly Technologies, Inc.

Constructor Summary
JHeaderPool()
           
 
Method Summary
static JHeaderPool getDefault()
          Gets a default global instance of this header pool.
<T extends JHeader>
T
getHeader(java.lang.Class<T> clazz, int id)
          Gets an instance of a header for the given ID type.
 JHeader getHeader(int id)
          Gets an instance of a header for the given ID type.
<T extends JHeader>
T
getHeader(JProtocol protocol)
          Gets an instance of a header for the protocol constant.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JHeaderPool

public JHeaderPool()
Method Detail

getHeader

public JHeader getHeader(int id)
                  throws UnregisteredHeaderException
Gets an instance of a header for the given ID type. The headers are allocated on a per thread basis. Eath thread uses its own pool of instance headers. A call with the same ID and within the same thread will return the same exact instance of a header that was returned from a previous call using the same ID and thread.

Parameters:
id - numerical ID of the protocol header as assigned by JRegistry
Returns:
a shared instance of a header per thread per ID
Throws:
UnregisteredHeaderException - thrown if ID is invalid

getHeader

public <T extends JHeader> T getHeader(JProtocol protocol)
Gets an instance of a header for the protocol constant. The headers are allocated on a per thread basis. Eath thread uses its own pool of instance headers. A call with the same ID and within the same thread will return the same exact instance of a header that was returned from a previous call using the same ID and thread.

This method does not throw an exception since all core protocols are always registered and always accessible.

Parameters:
protocol - core protocol constant
Returns:
a shared instance of a header per thread per ID

getHeader

public <T extends JHeader> T getHeader(java.lang.Class<T> clazz,
                                       int id)
Gets an instance of a header for the given ID type. The headers are allocated on a per thread basis. Eath thread uses its own pool of instance headers. A call with the same ID and within the same thread will return the same exact instance of a header that was returned from a previous call using the same ID and thread.

Type Parameters:
T - header class name
Parameters:
clazz - parameterized class name that the retrieved header instance will be cast to
id - numerical ID of the protocol header as assigned by JRegistry
Returns:
a shared instance of a header per thread per ID
Throws:
UnregisteredHeaderException - thrown if ID is invalid

getDefault

public static JHeaderPool getDefault()
Gets a default global instance of this header pool.