@Override public synchronized IdRange nextIdBatch( int size ) { assertStillOpen(); long[] reusableIds = idContainer.getReusableIds( size ); int sizeLeftForRange = size - reusableIds.length; long start = highId; setHighId( start + sizeLeftForRange ); return new IdRange( reusableIds, start, sizeLeftForRange ); }
/** * 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++; }
@Override public synchronized IdRange nextIdBatch( int size ) { assertStillOpen(); long[] reusableIds = idContainer.getReusableIds( size ); int sizeLeftForRange = size - reusableIds.length; long start = highId; setHighId( start + sizeLeftForRange ); return new IdRange( reusableIds, start, sizeLeftForRange ); }
/** * 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++; }