Search in sources :

Example 1 with StreamNotification

use of io.pravega.controller.server.retention.BucketChangeListener.StreamNotification 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);
}
Also used : SneakyThrows(lombok.SneakyThrows) StreamImpl(io.pravega.client.stream.impl.StreamImpl) RetentionPolicy(io.pravega.client.stream.RetentionPolicy) SerializationUtils(org.apache.commons.lang3.SerializationUtils) CompletableFuture(java.util.concurrent.CompletableFuture) StreamNotification(io.pravega.controller.server.retention.BucketChangeListener.StreamNotification) PathChildrenCacheListener(org.apache.curator.framework.recipes.cache.PathChildrenCacheListener) AtomicReference(java.util.concurrent.atomic.AtomicReference) ConcurrentMap(java.util.concurrent.ConcurrentMap) BucketOwnershipListener(io.pravega.controller.server.retention.BucketOwnershipListener) ZKPaths(org.apache.curator.utils.ZKPaths) BucketNotification(io.pravega.controller.server.retention.BucketOwnershipListener.BucketNotification) Data(io.pravega.controller.store.stream.tables.Data) NotificationType(io.pravega.controller.server.retention.BucketChangeListener.StreamNotification.NotificationType) BucketChangeListener(io.pravega.controller.server.retention.BucketChangeListener) Executor(java.util.concurrent.Executor) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) IOException(java.io.IOException) CompletionException(java.util.concurrent.CompletionException) Collectors(java.util.stream.Collectors) Slf4j(lombok.extern.slf4j.Slf4j) Base64(java.util.Base64) List(java.util.List) CuratorFramework(org.apache.curator.framework.CuratorFramework) Config(io.pravega.controller.util.Config) PathChildrenCache(org.apache.curator.framework.recipes.cache.PathChildrenCache) Preconditions(com.google.common.base.Preconditions) ZKHostIndex(io.pravega.controller.store.index.ZKHostIndex) PathChildrenCacheListener(org.apache.curator.framework.recipes.cache.PathChildrenCacheListener) StreamImpl(io.pravega.client.stream.impl.StreamImpl) PathChildrenCache(org.apache.curator.framework.recipes.cache.PathChildrenCache) StreamNotification(io.pravega.controller.server.retention.BucketChangeListener.StreamNotification) SneakyThrows(lombok.SneakyThrows)

Aggregations

Preconditions (com.google.common.base.Preconditions)1 RetentionPolicy (io.pravega.client.stream.RetentionPolicy)1 StreamImpl (io.pravega.client.stream.impl.StreamImpl)1 BucketChangeListener (io.pravega.controller.server.retention.BucketChangeListener)1 StreamNotification (io.pravega.controller.server.retention.BucketChangeListener.StreamNotification)1 NotificationType (io.pravega.controller.server.retention.BucketChangeListener.StreamNotification.NotificationType)1 BucketOwnershipListener (io.pravega.controller.server.retention.BucketOwnershipListener)1 BucketNotification (io.pravega.controller.server.retention.BucketOwnershipListener.BucketNotification)1 ZKHostIndex (io.pravega.controller.store.index.ZKHostIndex)1 Data (io.pravega.controller.store.stream.tables.Data)1 Config (io.pravega.controller.util.Config)1 IOException (java.io.IOException)1 Base64 (java.util.Base64)1 List (java.util.List)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 CompletionException (java.util.concurrent.CompletionException)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 ConcurrentMap (java.util.concurrent.ConcurrentMap)1 Executor (java.util.concurrent.Executor)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1