org.sadun.util
Interface SequentialUniqueIdGenerator.IdStorage

Enclosing interface:
SequentialUniqueIdGenerator

public static interface SequentialUniqueIdGenerator.IdStorage

Classes implementing this interface allow access to a shared storage of ids to use with a SequentialUniqueIdGenerator.

The storage can be slow, for example based on a remote object access or a database.

Version:
1.0
Author:
Cristiano Sadun

Nested Class Summary
static class SequentialUniqueIdGenerator.IdStorage.IdStorageException
           
 
Method Summary
 java.util.Iterator getNextIdBlock()
          Return an iterator over the next block of ids.
 void lock()
          Lock the storage.
 void unlock()
          Unlock the storage.
 

Method Detail

lock

public void lock()
          throws SequentialUniqueIdGenerator.IdStorage.IdStorageException
Lock the storage.

This method attempts to gain control of the storage and must block until the control is obtained or a timeout is expired.

Throws:
SequentialUniqueIdGenerator.IdStorage.IdStorageException - if the lock cannot be obtained

getNextIdBlock

public java.util.Iterator getNextIdBlock()
                                  throws SequentialUniqueIdGenerator.IdStorage.IdStorageException,
                                         java.lang.IllegalStateException
Return an iterator over the next block of ids. The next() operation of the iterator may return any object, but their string representation will be used. Therefore, the iterator must return a sequence of objects whose string representation is unique.

The storage must be left in a state such another process will not retrieve the same block.

Returns:
an iterator over the next block of ids.
Throws:
SequentialUniqueIdGenerator.IdStorage.IdStorageException - if an exception occurs while using the SequentialUniqueIdGenerator.IdStorage
java.lang.IllegalStateException - if the storage is unlocked

unlock

public void unlock()
            throws SequentialUniqueIdGenerator.IdStorage.IdStorageException
Unlock the storage.

This method must release control of the storage.

Throws:
SequentialUniqueIdGenerator.IdStorage.IdStorageException