1 9 package org.ozoneDB.core; 10 11 import org.ozoneDB.Setup; 12 import org.ozoneDB.util.LogWriter; 13 14 15 19 public final class KeyGenerator extends ServerComponent { 20 21 private long idCount = 0; 22 23 private long idBorder = -1; 24 25 private long idRange = 5000; 26 27 28 public KeyGenerator( Env env ) { 29 super( env ); 30 } 31 32 33 public void startup() throws Exception { 34 env.logWriter.newEntry( this, "startup...", LogWriter.INFO ); 35 } 36 37 38 public void shutdown() throws Exception { 39 env.logWriter.newEntry( this, "shutdown...", LogWriter.INFO ); 40 } 41 42 43 public void save() throws Exception { 44 } 45 46 47 public long nextID() { 48 return nextID( 1 ); 49 } 50 51 52 public synchronized long nextID( long range ) { 53 if (idCount + range >= idBorder) { 54 try { 55 idCount = env.state.longProperty( Setup.XOID, -1 ); 56 if (idCount == -1) { 57 throw new Exception ( "Unable to access the " + Setup.XOID + " property." ); 58 } 59 idBorder = idCount + range + idRange; 60 61 env.state.setLongProperty( Setup.XOID, idBorder ); 62 setChanged(); 63 } catch (Exception e) { 64 env.fatalError( this, "nextID(): " + e.toString(), e ); 65 } 66 } 67 long result = idCount; 68 idCount += range; 69 70 return result; 71 } 72 73 } 74 | Popular Tags |