Search in sources :

Example 1 with BucketOwnershipListener

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");
}
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) PathChildrenCache(org.apache.curator.framework.recipes.cache.PathChildrenCache) BucketNotification(io.pravega.controller.server.retention.BucketOwnershipListener.BucketNotification) 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