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

SimpleUniqueValueGenerator

public class SimpleUniqueValueGenerator extends Object implements UniqueValueGenerator
author
Kenneth Saks

Fields Summary
static Logger
_logger
private static Hashtable
contextBlocks_
private static UniqueValueGeneratorBackend
generatorBackend_
private static String
generatorBackendId_
private String
context_
Constructors Summary
SimpleUniqueValueGenerator(String context)
Use package-level access since clients should use a UniqueValueGeneratorFactory to create concrete instances this class.


     
        generatorBackendId_ = null;
        generatorBackend_   = null;
        contextBlocks_      = new Hashtable();
    
        context_    = context;
    
Methods Summary
private static synchronized UniqueValueGeneratorBackendgetBackendGenerator()

        if( generatorBackend_ == null ) {
            InitialContext jndiContext = new InitialContext();
            generatorBackend_   = (UniqueValueGeneratorBackend) 
                jndiContext.lookup(UniqueValueGeneratorBackend.JNDI_NAME);
        }
        return generatorBackend_;
    
public java.lang.StringgetContext()

        return context_;
    
private static synchronized java.lang.StringgetGeneratorBackendId()

        if( generatorBackendId_ == null ) {
            try {
                UniqueValueGeneratorBackend backend = getBackendGenerator();
                generatorBackendId_ = backend.getGeneratorId();
            } catch(Exception e) {
                /** IASRI 4660742
                Log.err.println(e); 
                **/
		            // START OF IASRI 4660742
                _logger.log(Level.SEVERE,"enterprise_util.excep_suidgen_getgenbackendid",e);
                // END OF IASRI 4660742

                throw new UniqueValueGeneratorException(e.getMessage());
            }
        }        
        return generatorBackendId_;
    
public java.lang.StringnextId()

        return getGeneratorBackendId() + "_" + nextNumber();
    
public longnextNumber()

        return nextNumberInternal(getContext());
    
private static synchronized longnextNumberInternal(java.lang.String context)


        UniqueValueBlock valueBlock = null;
        try {
            UniqueValueGeneratorBackend generatorBackend = 
                getBackendGenerator();

            valueBlock = (UniqueValueBlock) contextBlocks_.get(context);
            
            if( (valueBlock == null) || (!valueBlock.hasNext()) ) {
                valueBlock = generatorBackend.getNextValueBlock(context);
                contextBlocks_.put(context, valueBlock);
            }
        } catch(Exception e) {
            /** IASRI 4660742
            Log.err.println(e); 
            **/
	          // START OF IASRI 4660742
            _logger.log(Level.SEVERE,"enterprise_util.excep_suidgen_nextnuminternal",e);
            // END OF IASRI 4660742
            throw new UniqueValueGeneratorException(e.getMessage());
        }
        
        return valueBlock.next();