1 18 19 package sync4j.framework.protocol; 20 21 import sync4j.framework.protocol.IdGenerator; 22 import sync4j.framework.protocol.SimpleIdGenerator; 23 import sync4j.framework.core.CmdID; 24 25 36 public class CommandIdGenerator 37 implements java.io.Serializable { 38 39 41 44 private IdGenerator idGenerator = null; 45 46 49 private CmdID currentId = null; 50 51 53 54 public CommandIdGenerator() { 55 this(new SimpleIdGenerator()); 56 57 } 58 59 64 public CommandIdGenerator(IdGenerator idGenerator) { 65 if (idGenerator == null) { 66 throw new NullPointerException ("idGenerator cannot be null!"); 67 } 68 this.idGenerator = idGenerator; 69 } 70 71 73 78 public synchronized CmdID next() { 79 return (currentId = new CmdID(idGenerator.next())); 80 } 81 82 85 public synchronized void reset() { 86 idGenerator.reset(); 87 } 88 89 94 public synchronized CmdID current() { 95 return currentId; 96 } 97 } | Popular Tags |