use of org.apache.bookkeeper.versioning.LongVersion in project bookkeeper by apache.
the class LedgerAllocatorPool method initializeAllocators.
/**
* Initialize simple allocators with given list of allocator names <i>allocators</i>.
* It initializes a simple allocator with its simple allocator path.
*/
private void initializeAllocators(List<String> allocators) throws IOException, InterruptedException {
final AtomicInteger numPendings = new AtomicInteger(allocators.size());
final AtomicInteger numFailures = new AtomicInteger(0);
final CountDownLatch latch = new CountDownLatch(numPendings.get() > 0 ? 1 : 0);
AsyncCallback.DataCallback dataCallback = new AsyncCallback.DataCallback() {
@Override
public void processResult(int rc, String path, Object ctx, byte[] data, Stat stat) {
if (KeeperException.Code.OK.intValue() != rc) {
numFailures.incrementAndGet();
latch.countDown();
return;
}
Versioned<byte[]> allocatorData = new Versioned<byte[]>(data, new LongVersion(stat.getVersion()));
SimpleLedgerAllocator allocator = new SimpleLedgerAllocator(path, allocatorData, quorumConfigProvider, zkc, bkc);
allocator.start();
pendingList.add(allocator);
if (numPendings.decrementAndGet() == 0 && numFailures.get() == 0) {
latch.countDown();
}
}
};
for (String name : allocators) {
String path = poolPath + "/" + name;
zkc.get().getData(path, false, dataCallback, null);
}
latch.await();
if (numFailures.get() > 0) {
throw new IOException("Failed to initialize allocators : " + allocators);
}
}
Aggregations