Sea 0.2.1

gov.lbl.dsd.sea.nio.util
Class SequenceNumberGenerator

java.lang.Object
  extended bygov.lbl.dsd.sea.nio.util.SequenceNumberGenerator
All Implemented Interfaces:
Serializable

public class SequenceNumberGenerator
extends Object
implements Serializable

Utility to create long sequence numbers in a thread safe manner; useful for packet or event tagging or session/message IDs.

Sequence numbers start from a fixed seed or random seed, and then are incremented on each invocation of nextSequenceNumber. Random seeds can be obtained from an insecure (but fast) source, or from a secure (but slow) source.

Version:
$Revision: 1.5 $, $Date: 2004/05/31 22:36:30 $
See Also:
Serialized Form

Method Summary
static SequenceNumberGenerator createWithFixedSeed(long seqNum)
          Creates and returns an instance with the given fixed seed
static SequenceNumberGenerator createWithRandomSeed(boolean secure)
          Creates and returns an instance with a secure or insecure random seed
static int hashCode(long seqNum)
          Returns a hashcode fo the given sequence number
 long nextSequenceNumber()
          Increments the sequence number and returns the incremented value
 String toString()
          Returns a string representation of the receiver
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Method Detail

createWithFixedSeed

public static SequenceNumberGenerator createWithFixedSeed(long seqNum)
Creates and returns an instance with the given fixed seed

Parameters:
seqNum - the fixed seed

createWithRandomSeed

public static SequenceNumberGenerator createWithRandomSeed(boolean secure)
Creates and returns an instance with a secure or insecure random seed

Parameters:
secure - shall it be secure or not?

nextSequenceNumber

public long nextSequenceNumber()
Increments the sequence number and returns the incremented value

Returns:
the next sequence number

toString

public String toString()
Returns a string representation of the receiver


hashCode

public static int hashCode(long seqNum)
Returns a hashcode fo the given sequence number

Parameters:
seqNum - the sequence number
Returns:
the hash code

Sea 0.2.1