org.apache.lucene.gdata.storage
Class IDGenerator

java.lang.Object
  extended by org.apache.lucene.gdata.storage.IDGenerator

public class IDGenerator
extends Object

This is the main entry ID generator to generate unique ids for each entry. The Generator uses SecureRandom Numbers and the System.currentTimeMillis() to create a semi-unique sting; The string will be digested by a MessageDigest which returns a byte array. The generator encodes the byte array as a hex string.

The generated Id's will cached in a BlockingQueue and reproduced if an id has been removed.

Author:
Simon Willnauer

Field Summary
protected static org.apache.commons.logging.Log LOGGER
           
 
Constructor Summary
IDGenerator(int capacity)
          Constructs a new ID generator.
 
Method Summary
 int getQueueSize()
           
 String getUID()
          This method takes a gnerated id from the IDProducer queue and retruns it.
 void stopIDGenerator()
          Stops the id-producer
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LOGGER

protected static final org.apache.commons.logging.Log LOGGER
Constructor Detail

IDGenerator

public IDGenerator(int capacity)
            throws NoSuchAlgorithmException
Constructs a new ID generator. with a fixed capacity of prebuild ids. The default capacity is 10. Every given parameter less than 10 will be ignored.

Parameters:
capacity - - capacity of the prebuild id queue
Throws:
NoSuchAlgorithmException - - if the algorithm does not exist
Method Detail

getUID

public String getUID()
              throws InterruptedException
This method takes a gnerated id from the IDProducer queue and retruns it. If no ID is available this method will wait until an ID is produced. This implementation is thread-safe.

Returns:
a UID
Throws:
InterruptedException - - if interrupted while waiting

getQueueSize

public int getQueueSize()
Returns:
the current size of the queue

stopIDGenerator

public void stopIDGenerator()
Stops the id-producer



Copyright © 2000-2008 Apache Software Foundation. All Rights Reserved.