@Override
public Future<RpcResult<Void>> createIdPool(CreateIdPoolInput input) {
if (LOG.isDebugEnabled()) {
LOG.debug("createIdPool called with input {}", input);
}
String poolName = input.getPoolName();
long low = input.getLow();
long high = input.getHigh();
long blockSize = IdUtils.computeBlockSize(low, high);
RpcResultBuilder<Void> createIdPoolRpcBuilder;
IdUtils.lockPool(lockManager, poolName);
try {
WriteTransaction tx = broker.newWriteOnlyTransaction();
poolName = poolName.intern();
IdPool idPool;
idPool = createGlobalPool(tx, poolName, low, high, blockSize);
String localPoolName = IdUtils.getLocalPoolName(poolName);
createLocalPool(tx, localPoolName, idPool);
submitTransaction(tx);
createIdPoolRpcBuilder = RpcResultBuilder.success();
} catch (Exception ex) {
LOG.error("Creation of Id Pool {} failed due to {}", poolName, ex);
createIdPoolRpcBuilder = RpcResultBuilder.failed();
createIdPoolRpcBuilder.withError(ErrorType.APPLICATION, ex.getMessage());
} finally {
IdUtils.unlockPool(lockManager, poolName);
}
return Futures.immediateFuture(createIdPoolRpcBuilder.build());
}