com.mooapi.server.util
Class PooledIdProvider

java.lang.Object
  extended by com.mooapi.server.util.PooledIdProvider
All Implemented Interfaces:
IdProvider<java.lang.Integer>

public class PooledIdProvider
extends java.lang.Object
implements IdProvider<java.lang.Integer>

This class implements a pool-based integer ID provider.

Author:
Steve Taylor

Constructor Summary
PooledIdProvider(int size)
          Equivalent to PooledIdProvider(0, size).
PooledIdProvider(int firstId, int size)
          Initialize the ID pool with a sequence of size IDs starting at firstId and incrementing by 1.
 
Method Summary
 java.lang.Integer acquireId()
          Acquire a unique ID from this provider.
 void releaseId(java.lang.Integer id)
          Release an ID to this provider.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PooledIdProvider

public PooledIdProvider(int firstId,
                        int size)
Initialize the ID pool with a sequence of size IDs starting at firstId and incrementing by 1.

Parameters:
firstId - The value of the first ID.
size - The number of IDs to generate and pool.

PooledIdProvider

public PooledIdProvider(int size)
Equivalent to PooledIdProvider(0, size).

Parameters:
size - The number of IDs to generate and pool.
Method Detail

acquireId

public java.lang.Integer acquireId()
Acquire a unique ID from this provider. A unique ID is defined as an ID that is not found in the set of IDs currently on loan from this provider.

Specified by:
acquireId in interface IdProvider<java.lang.Integer>
Returns:
A unique ID.

releaseId

public void releaseId(java.lang.Integer id)

Release an ID to this provider.

For performance reasons, this method assumes that the specified ID came from this provider and is currently "on loan". If this assumption isn't satisfied, the user of this provider can no longer assume this provider will generate unique IDs.

Specified by:
releaseId in interface IdProvider<java.lang.Integer>
Parameters:
id - The ID to release.


Copyright © 2009. All Rights Reserved.