private long nextBase() throws IOException { long base = getNextHiId(); lo = 0; return base; }
/** * THe maximum "lo" ID is the increment of the hi ID. * @return */ @Override public long getMaxLo() { return delegate.getIncrement(); }
/** * Resets the generator */ public void reset() { lo = 0; base = -1; resetHiId(); }
public String getID() throws IOException { try { lock.lock(); // If ID is 0, read initial value from file if possible if (!minimizeReads || !used) { long readInitialValue = readInitialValue(getFilePath()); if (readInitialValue >= 0) { set(readInitialValue); } used = true; } String id = super.getID(); // The id held in the file is always <increment> larger so that // the ID is still unique after a restart. writeNextValue(Long.parseLong(id) + getIncrement()); return id; } finally { lock.unlock(); } }
public synchronized String getID() throws IOException { if (base < 0) { LOG.debug("Obtain next hi ID"); base = nextBase(); } if (getNextLoId() >= getMaxLo()) { LOG.debug("Obtain next hi ID"); base = nextBase(); } return Long.toString(base + lo); }
public void reset() { try { lock.lock(); super.reset(); writeNextValue(0l); } catch (IOException e) { throw new IllegalStateException("Cannot initialize persistent ID generator", e); } finally { lock.unlock(); } }
@Override protected void resetHiId() { delegate.reset(); }
public synchronized void reset() { set(0l); }
public FileBasedHiLoGenerator(long maxLo) { super(new FileBasedGenerator(maxLo)); }
@Override protected long getNextHiId() throws IOException { if (delegate == null) throw new NullPointerException( "Must initialize delegate IDGenerator"); return Long.parseLong(delegate.getID()); }
public String getID() throws IOException { try { lock.lock(); // If ID is 0, read initial value from file if possible if (!minimizeReads || !used) { long readInitialValue = readInitialValue(getFilePath()); if (readInitialValue >= 0) { set(readInitialValue); } used = true; } String id = super.getID(); // The id held in the file is always <increment> larger so that // the ID is still unique after a restart. writeNextValue(Long.parseLong(id) + getIncrement()); return id; } finally { lock.unlock(); } }
public synchronized String getID() throws IOException { if (base < 0) { LOG.debug("Obtain next hi ID"); base = nextBase(); } if (getNextLoId() >= getMaxLo()) { LOG.debug("Obtain next hi ID"); base = nextBase(); } return Long.toString(base + lo); }
public void reset() { try { lock.lock(); super.reset(); writeNextValue(0l); } catch (IOException e) { throw new IllegalStateException("Cannot initialize persistent ID generator", e); } finally { lock.unlock(); } }
private long nextBase() throws IOException { long base = getNextHiId(); lo = 0; return base; }
/** * THe maximum "lo" ID is the increment of the hi ID. * @return */ @Override public long getMaxLo() { return delegate.getIncrement(); }
/** * Resets the generator */ public void reset() { lo = 0; base = -1; resetHiId(); }
@Override protected void resetHiId() { delegate.reset(); }
public synchronized void reset() { set(0l); }
public FileBasedHiLoGenerator(long maxLo) { super(new FileBasedGenerator(maxLo)); }
@Override protected long getNextHiId() throws IOException { if (delegate == null) throw new NullPointerException( "Must initialize delegate IDGenerator"); return Long.parseLong(delegate.getID()); }