FileDocCategorySizeDatePackage
UniqueValueGeneratorBackendImpl.javaAPI DocGlassfish v2 API4465Fri May 04 22:32:08 BST 2007com.sun.enterprise.util

UniqueValueGeneratorBackendImpl

public class UniqueValueGeneratorBackendImpl extends javax.rmi.PortableRemoteObject implements UniqueValueGeneratorBackend
Doles out blocks of unique numbers for each context. A single instance of this object is registered per server instance(single-vm mode or multi-vm mode).
author
Kenneth Saks

Fields Summary
static Logger
_logger
private static final boolean
debug
private static final long
BLOCK_SIZE
private static final long
NUM_BLOCKS_PER_CONTEXT
private String
id_
private Hashtable
contexts_
Constructors Summary
public UniqueValueGeneratorBackendImpl()


        
        contexts_ = new Hashtable();
        id_       = System.currentTimeMillis() + "";
    
Methods Summary
public java.lang.StringgetGeneratorId()

        return id_;
    
public UniqueValueBlockgetNextValueBlock(java.lang.String context)


        int blockIndex = 0;

        synchronized( this ) {
            if( contexts_.containsKey(context) ) {
                Integer currentBlock = (Integer) contexts_.get(context);
                blockIndex = currentBlock.intValue();
            } 
            contexts_.put(context, Integer.valueOf(blockIndex + 1));
        }

        if( blockIndex >= NUM_BLOCKS_PER_CONTEXT ) {
            throw new RemoteException("Block overflow");
        } 

        if( debug ) {
	          /** IASRI 4660742
            System.out.println("Returning block " + blockIndex + 
                               " of size " + BLOCK_SIZE + " for context " +
                               context);
	          **/
	          // START OF IASRI 4660742
	          if (_logger.isLoggable(Level.FINE)) {
	              _logger.log(Level.FINE,"Returning block " + blockIndex +
                       " of size " + BLOCK_SIZE + " for context " + context);

	           }
	          // END OF IASRI 4660742

        }
        return new UniqueValueBlock((blockIndex * BLOCK_SIZE), BLOCK_SIZE);