/** * Returns the next "free" id. If a defragged id exist it will be returned * else the next free id that hasn't been used yet is returned. If no id * exist the capacity is exceeded (all values <= max are taken) and a * {@link UnderlyingStorageException} will be thrown. * * @return The next free id * @throws UnderlyingStorageException * If the capacity is exceeded * @throws IllegalStateException if this id generator has been closed */ @Override public synchronized long nextId() { assertStillOpen(); long nextDefragId = idContainer.getReusableId(); if ( nextDefragId != IdContainer.NO_RESULT ) { return nextDefragId; } if ( IdValidator.isReservedId( highId ) ) { highId++; } IdValidator.assertValidId( idType, highId, max ); return highId++; }
private long getReusableId() { idContainerLock.lock(); try { return idContainer.getReusableId(); } finally { idContainerLock.unlock(); } }
/** * Returns the next "free" id. If a defragged id exist it will be returned * else the next free id that hasn't been used yet is returned. If no id * exist the capacity is exceeded (all values <= max are taken) and a * {@link UnderlyingStorageException} will be thrown. * * @return The next free id * @throws UnderlyingStorageException * If the capacity is exceeded * @throws IllegalStateException if this id generator has been closed */ @Override public synchronized long nextId() { assertStillOpen(); long nextDefragId = idContainer.getReusableId(); if ( nextDefragId != IdContainer.NO_RESULT ) { return nextDefragId; } if ( IdValidator.isReservedId( highId ) ) { highId++; } IdValidator.assertValidId( idType, highId, max ); return highId++; }