org.mbari.siam.core
Class SequenceNumber

java.lang.Object
  extended by org.mbari.siam.core.SequenceNumber
All Implemented Interfaces:
SequenceGenerator

public class SequenceNumber
extends java.lang.Object
implements SequenceGenerator

SequenceNumber is an implementation of the SequenceGenerator interface used for generating packet sequence numbers. The packet sequence numbers should start at zero within a log file and increase by one each time a packet is logged; also, they should persist across power cycles. Thus, if a log file exists, when a power cycle occurs, the packet numbers should pick up where they left off in the log. The user is responsible for determining the initial values. IMPORTANT NOTES: This implementation assumes that sequence numbers will not be less than zero (uses only 0-Long.MAX_VALUE), and therefore doesn't suffer from overflow problems. This class will give incorrect results if you use it in a way that exceeds the range of a long.

Author:
Kent Headley

Constructor Summary
SequenceNumber(long least, long greatest, long start)
          Constructor for creating and (explicitly) initializing a SequenceNumber
 
Method Summary
 long getGreatest()
          Get maximum value in sequence
 long getLeast()
          Get minimum value in sequence
 long getNext()
          Get next number in sequence
 void initialize(long least, long greatest, long current)
          Set sequence range
static void main(java.lang.String[] args)
          Eine Kleine test code
 long peek(long offset, boolean wrap)
          Look at nth number in sequence (relative to the current number) without actually changing anything.
 void reset()
          Restart sequence from minimum value
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SequenceNumber

public SequenceNumber(long least,
                      long greatest,
                      long start)
               throws RangeException
Constructor for creating and (explicitly) initializing a SequenceNumber

Throws:
RangeException
Method Detail

getNext

public long getNext()
Get next number in sequence

Specified by:
getNext in interface SequenceGenerator

getLeast

public long getLeast()
Get minimum value in sequence

Specified by:
getLeast in interface SequenceGenerator

getGreatest

public long getGreatest()
Get maximum value in sequence

Specified by:
getGreatest in interface SequenceGenerator

initialize

public void initialize(long least,
                       long greatest,
                       long current)
                throws RangeException
Set sequence range

Specified by:
initialize in interface SequenceGenerator
Throws:
RangeException

reset

public void reset()
Restart sequence from minimum value

Specified by:
reset in interface SequenceGenerator

peek

public long peek(long offset,
                 boolean wrap)
Look at nth number in sequence (relative to the current number) without actually changing anything. The offset may be positive, negative or zero. Using an offset of 0 returns the most recent number returned. Using an offset beyond the sequence bounds optionally wraps around.

Specified by:
peek in interface SequenceGenerator

main

public static void main(java.lang.String[] args)
Eine Kleine test code



Copyright © 2003 MBARI.

The Monterey Bay Aquarium Research Institute (MBARI) provides this documentation and code "as is", with no warranty, express or implied, of its quality or consistency. It is provided without support and without obligation on the part of MBARI to assist in its use, correction, modification, or enhancement.