use of io.pravega.controller.server.retention.BucketOwnershipListener in project pravega by pravega.
the class ZKStreamMetadataStore method registerBucketOwnershipListener.
@Override
@SneakyThrows
public void registerBucketOwnershipListener(BucketOwnershipListener listener) {
Preconditions.checkNotNull(listener);
PathChildrenCacheListener bucketListener = (client, event) -> {
switch(event.getType()) {
case CHILD_ADDED:
// no action required
break;
case CHILD_REMOVED:
int bucketId = Integer.parseInt(ZKPaths.getNodeFromPath(event.getData().getPath()));
listener.notify(new BucketNotification(bucketId, BucketNotification.NotificationType.BucketAvailable));
break;
case CONNECTION_LOST:
listener.notify(new BucketNotification(Integer.MIN_VALUE, BucketNotification.NotificationType.ConnectivityError));
break;
default:
log.warn("Received unknown event {}", event.getType());
}
};
bucketOwnershipCacheRef.compareAndSet(null, new PathChildrenCache(storeHelper.getClient(), ZKStoreHelper.BUCKET_OWNERSHIP_PATH, true));
bucketOwnershipCacheRef.get().getListenable().addListener(bucketListener);
bucketOwnershipCacheRef.get().start(PathChildrenCache.StartMode.BUILD_INITIAL_CACHE);
log.info("bucket ownership listener registered");
}
Aggregations