1 18 19 package sync4j.server.tools; 20 21 import sync4j.framework.protocol.IdGenerator; 22 import sync4j.framework.server.ID; 23 import sync4j.framework.server.store.*; 24 25 import sync4j.server.config.Configuration; 26 27 32 public class IdSpaceGenerator 33 implements IdGenerator, java.io.Serializable { 34 35 private ID id = null; 37 38 40 45 public IdSpaceGenerator(String idSpace) { 46 id = new ID(idSpace); 47 } 48 49 50 53 public void reset() { 54 id.setValue(0); 55 try { 56 Configuration.getConfiguration().getStore().store(id); 57 } catch (PersistentStoreException ex) { 58 throw new IllegalStateException ("Error resetting the counter '" + id.getIdSpace() + "': " + ex.getMessage()); 59 } 60 } 61 62 67 public synchronized String next() { 68 try { 69 Configuration.getConfiguration().getStore().read(id); 70 } catch (PersistentStoreException ex) { 71 throw new IllegalStateException ("Error reading the counter '" + id.getIdSpace() + "': " + ex.getMessage()); 72 } 73 return String.valueOf(id.getValue()); 74 } 75 76 81 public synchronized String current() { 82 return String.valueOf(id.getValue()); 83 } 84 } 85 | Popular Tags |