use of io.pravega.controller.server.retention.BucketChangeListener in project pravega by pravega.
the class ZKStreamMetadataStore method registerBucketChangeListener.
@Override
@SneakyThrows
public void registerBucketChangeListener(int bucket, BucketChangeListener listener) {
Preconditions.checkNotNull(listener);
PathChildrenCacheListener bucketListener = (client, event) -> {
StreamImpl stream;
switch(event.getType()) {
case CHILD_ADDED:
stream = getStreamFromPath(event.getData().getPath());
listener.notify(new StreamNotification(stream.getScope(), stream.getStreamName(), NotificationType.StreamAdded));
break;
case CHILD_REMOVED:
stream = getStreamFromPath(event.getData().getPath());
listener.notify(new StreamNotification(stream.getScope(), stream.getStreamName(), NotificationType.StreamRemoved));
break;
case CHILD_UPDATED:
stream = getStreamFromPath(event.getData().getPath());
listener.notify(new StreamNotification(stream.getScope(), stream.getStreamName(), NotificationType.StreamUpdated));
break;
case CONNECTION_LOST:
listener.notify(new StreamNotification(null, null, NotificationType.ConnectivityError));
break;
default:
log.warn("Received unknown event {} on bucket", event.getType(), bucket);
}
};
String bucketRoot = String.format(ZKStoreHelper.BUCKET_PATH, bucket);
bucketCacheMap.put(bucket, new PathChildrenCache(storeHelper.getClient(), bucketRoot, true));
PathChildrenCache pathChildrenCache = bucketCacheMap.get(bucket);
pathChildrenCache.getListenable().addListener(bucketListener);
pathChildrenCache.start(PathChildrenCache.StartMode.NORMAL);
log.info("bucket {} change notification listener registered", bucket);
}
Aggregations