1 23 package com.sun.enterprise.util; 24 25 import javax.rmi.PortableRemoteObject ; 26 import java.rmi.RemoteException ; 27 import java.util.Hashtable ; 28 29 import java.util.logging.*; 31 import com.sun.logging.*; 32 34 35 42 public class UniqueValueGeneratorBackendImpl extends PortableRemoteObject implements UniqueValueGeneratorBackend { 43 44 static Logger _logger=LogDomains.getLogger(LogDomains.UTIL_LOGGER); 46 48 private static final boolean debug = com.sun.enterprise.util.logging.Debug.enabled; 51 53 private static final long BLOCK_SIZE = 100; 54 private static final long NUM_BLOCKS_PER_CONTEXT = 55 (Long.MAX_VALUE / BLOCK_SIZE); 56 57 private String id_; 58 private Hashtable contexts_; 59 60 public UniqueValueGeneratorBackendImpl() throws RemoteException { 61 contexts_ = new Hashtable (); 62 id_ = System.currentTimeMillis() + ""; 63 } 64 65 public String getGeneratorId() throws RemoteException { 66 return id_; 67 } 68 69 public UniqueValueBlock getNextValueBlock(String context) 70 throws RemoteException { 71 72 int blockIndex = 0; 73 74 synchronized( this ) { 75 if( contexts_.containsKey(context) ) { 76 Integer currentBlock = (Integer ) contexts_.get(context); 77 blockIndex = currentBlock.intValue(); 78 } 79 contexts_.put(context, new Integer (blockIndex + 1)); 80 } 81 82 if( blockIndex >= NUM_BLOCKS_PER_CONTEXT ) { 83 throw new RemoteException ("Block overflow"); 84 } 85 86 if( debug ) { 87 92 if (_logger.isLoggable(Level.FINE)) { 94 _logger.log(Level.FINE,"Returning block " + blockIndex + 95 " of size " + BLOCK_SIZE + " for context " + context); 96 97 } 98 100 } 101 return new UniqueValueBlock((blockIndex * BLOCK_SIZE), BLOCK_SIZE); 102 } 103 104 } 105 | Popular Tags |