gov.nasa.gsfc.drl.rtstps.core.output.hdf5
Class PacketPoolBySize

java.lang.Object
  extended by gov.nasa.gsfc.drl.rtstps.core.output.hdf5.PacketPoolBySize
All Implemented Interfaces:
PacketPool

public class PacketPoolBySize
extends java.lang.Object
implements PacketPool

A very simplistic pooling class for packets for use by the HDF output module only. It assumes good behavior by the user -- packets are created and given away and then the expectation is the user will put them back in the pool when done... if not they are lost to the garbage collector. The packets are put on array of lists by packet size. When pulled off the queue the size is used as an index. If there are no packets at that size, the array is searched by adding one to size until it reaches the end. If some packet is found, it is reset to the requested size. This does not cost too much, no new memory is needed. If on the other hand this fails, then the search proceeds from the first smallest index (7) to the original size. If a packet is found, it is reset to the new size. This results in new memory being created inside of the Packet class itself. If both of these fail, then the Java heap is used.


Field Summary
private static int CCSDSMaxSize
           
private static int CCSDSMinSize
           
private  Packets[] pool
           
private  boolean sciencePool
           
private  Stats stats
           
private  int timeToClear
           
private  int timeToClearCounter
           
private  long totalCreated
           
private  long totalMemory
           
private  long totalOnPool
           
private  java.lang.String whoAmI
           
 
Constructor Summary
PacketPoolBySize(java.lang.String poolName, Stats stats)
          init, create and initialize the pool
 
Method Summary
 void drain()
          Return all packets in the pool back to the Java heap.
private  Packet findPacketBySize(int size)
           
 void flush(java.util.List<Packet> packetList)
          Take all the packets on the supplied list and hang them on the internal pool list
 Packet get(int size)
          Ask for a get a packet of size
 void preen()
          Send little used packets back to the heap
 void put(Packet packet)
          Give the packet to the pool for storage
private  void statMemoryUsed()
           
private  void statPacketPool()
           
private  void statPacketsCreated()
           
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

CCSDSMaxSize

private static final int CCSDSMaxSize
See Also:
Constant Field Values

CCSDSMinSize

private static final int CCSDSMinSize
See Also:
Constant Field Values

pool

private Packets[] pool

totalOnPool

private long totalOnPool

totalCreated

private long totalCreated

totalMemory

private long totalMemory

whoAmI

private java.lang.String whoAmI

stats

private Stats stats

sciencePool

private boolean sciencePool

timeToClearCounter

private int timeToClearCounter

timeToClear

private final int timeToClear
See Also:
Constant Field Values
Constructor Detail

PacketPoolBySize

public PacketPoolBySize(java.lang.String poolName,
                        Stats stats)
init, create and initialize the pool

Method Detail

get

public Packet get(int size)
           throws RtStpsException
Ask for a get a packet of size

Specified by:
get in interface PacketPool
Parameters:
size - size in bytes needed hold packet including header and body
Returns:
Packet
Throws:
RtStpsException - If size is not legal

put

public void put(Packet packet)
         throws RtStpsException
Give the packet to the pool for storage

Specified by:
put in interface PacketPool
Parameters:
packet -
Throws:
RtStpsException - If illegal size

flush

public void flush(java.util.List<Packet> packetList)
           throws RtStpsException
Take all the packets on the supplied list and hang them on the internal pool list

Specified by:
flush in interface PacketPool
Parameters:
packetList - the list of packets to put on the pool
Throws:
RtStpsException

preen

public void preen()
Send little used packets back to the heap

Specified by:
preen in interface PacketPool

drain

public void drain()
Description copied from interface: PacketPool
Return all packets in the pool back to the Java heap.

Specified by:
drain in interface PacketPool

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

findPacketBySize

private Packet findPacketBySize(int size)

statPacketPool

private void statPacketPool()

statMemoryUsed

private void statMemoryUsed()

statPacketsCreated

private void statPacketsCreated()