org.dasein.persist
Class DaseinSequencer
java.lang.Object
org.dasein.persist.Sequencer
org.dasein.persist.DaseinSequencer
public class DaseinSequencer
- extends Sequencer
Provides a database-independent sequence generation scheme. This class
goes to the database once every MAX_KEYS requests to
get a new seed for the numbers it generates. This class is thread-safe,
meaning multiple threads can be safely requesting unique numbers from it.
It is also multi-process safe. In other words, multiple machines can
simultaneously be generating unique values and those values will
be guaranteed to be unique across all applications. The only caveat
is that they all must be using the same algorithm for generating
the numbers and getting seeds from the same database.
In order to access the database, this class reads the configuration
properties file dasein-persistence.properties to look up the DSN
for the sequencer database. This value should be set with the
name of the DSN that provides connections to the database with the
sequencer table. That table should have the
following CREATE:
CREATE TABLE sequencer (
name VARCHAR(20) NOT NULL,
spacing BIGINT UNSIGNED NOT NULL,
next_key BIGINT UNSIGNED NOT NULL,
last_update BIGINT UNSIGNED NOT NULL,
PRIMARY KEY ( name, lastUpdate )
);
Last modified $Date: 2009/02/07 18:11:51 $
- Version:
- $Revision: 1.4 $
- Author:
- George Reese
|
Method Summary |
long |
next()
Generates a new unique number. |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
DaseinSequencer
public DaseinSequencer()
next
public long next()
throws PersistenceException
- Generates a new unique number. The unique number is based on the
following algorithm:
unique number = seed multiple by
maximum keys per seed added to seed sequence
The method then increments the seed sequence for the next
ID to be generated. If the ID to be generated would exhaust
the seed, then a new seed is retrieved from the database.
- Specified by:
next in class Sequencer
- Returns:
- a unique number
- Throws:
PersistenceException - a data store error
occurred while generating the number
Copyright © 2011 enStratus Networks LLC. All Rights Reserved.