org.sadun.util
Class SequentialUniqueIdGenerator

java.lang.Object
  extended byorg.sadun.util.SequentialUniqueIdGenerator

public class SequentialUniqueIdGenerator
extends java.lang.Object

An unique id generator which creates ids unique across different JVMs and sequential.

Version:
1.0
Author:
Cristiano Sadun

Nested Class Summary
static interface SequentialUniqueIdGenerator.IdStorage
          Classes implementing this interface allow access to a shared storage of ids to use with a SequentialUniqueIdGenerator.
 
Constructor Summary
protected SequentialUniqueIdGenerator()
          Create a sequential generator
  SequentialUniqueIdGenerator(SequentialUniqueIdGenerator.IdStorage storage)
          Create a sequential generator using the given SequentialUniqueIdGenerator.IdStorage.
 
Method Summary
 Broadcaster getFailureBroadcaster()
          Return the current failure broadcaster.
 java.lang.String getNextId()
          Return the next id.
 void setFailureBroadcaster(Broadcaster failureBroadcaster)
          Set the failure broadcaster.
protected  void setIdStorage(SequentialUniqueIdGenerator.IdStorage idStorage)
          Set the idStorage.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SequentialUniqueIdGenerator

public SequentialUniqueIdGenerator(SequentialUniqueIdGenerator.IdStorage storage)
Create a sequential generator using the given SequentialUniqueIdGenerator.IdStorage.

Parameters:
storage - the id storage to use

SequentialUniqueIdGenerator

protected SequentialUniqueIdGenerator()
Create a sequential generator

Method Detail

getNextId

public java.lang.String getNextId()
                           throws SequentialUniqueIdGenerator.IdStorage.IdStorageException
Return the next id. This operation is potentially blocking, or may trigger an OperationTimedoutExceptionif the SequentialUniqueIdGenerator.IdStorage used by this SequentialUniqueIdGeneratorimposes a timeout on the storage locking operation.

Returns:
the next id.
Throws:
OperationTimedoutException - if a timeout is raised when IdStorage#lock()locking the storage
SequentialUniqueIdGenerator.IdStorage.IdStorageException

setIdStorage

protected void setIdStorage(SequentialUniqueIdGenerator.IdStorage idStorage)
Set the idStorage.

Parameters:
idStorage -

getFailureBroadcaster

public Broadcaster getFailureBroadcaster()
Return the current failure broadcaster. This broadcaster is used if the SequentialUniqueIdGenerator.IdStorageused by this generator cannot be unlocked, potentially leaving other id generators in a deadlocked state.

Returns:
the current failure broadcaster.

setFailureBroadcaster

public void setFailureBroadcaster(Broadcaster failureBroadcaster)
Set the failure broadcaster. This broadcaster is used if the SequentialUniqueIdGenerator.IdStorageused by this generator cannot be unlocked, potentially leaving other id generators in a deadlocked state.

If set to null , the current broadcaster (if any) is removed.

Parameters:
failureBroadcaster -