Search in sources :

Example 1 with NotificationType

use of org.apache.pulsar.metadata.api.NotificationType in project pulsar by apache.

the class ZKMetadataStore method handleWatchEvent.

private void handleWatchEvent(WatchedEvent event) {
    if (log.isDebugEnabled()) {
        log.debug("Received ZK watch : {}", event);
    }
    String path = event.getPath();
    if (path == null) {
        // Ignore Session events
        return;
    }
    String parent = parent(path);
    Notification childrenChangedNotification = null;
    NotificationType type;
    switch(event.getType()) {
        case NodeCreated:
            type = NotificationType.Created;
            if (parent != null) {
                childrenChangedNotification = new Notification(NotificationType.ChildrenChanged, parent);
            }
            break;
        case NodeDataChanged:
            type = NotificationType.Modified;
            break;
        case NodeChildrenChanged:
            type = NotificationType.ChildrenChanged;
            break;
        case NodeDeleted:
            type = NotificationType.Deleted;
            if (parent != null) {
                childrenChangedNotification = new Notification(NotificationType.ChildrenChanged, parent);
            }
            break;
        default:
            return;
    }
    receivedNotification(new Notification(type, event.getPath()));
    if (childrenChangedNotification != null) {
        receivedNotification(childrenChangedNotification);
    }
}
Also used : NotificationType(org.apache.pulsar.metadata.api.NotificationType) Notification(org.apache.pulsar.metadata.api.Notification)

Example 2 with NotificationType

use of org.apache.pulsar.metadata.api.NotificationType in project pulsar by apache.

the class AbstractMetadataStore method accept.

@Override
public void accept(Notification n) {
    String path = n.getPath();
    NotificationType type = n.getType();
    if (type == NotificationType.Created || type == NotificationType.Deleted) {
        existsCache.synchronous().invalidate(path);
        String parent = parent(path);
        if (parent != null) {
            childrenCache.synchronous().invalidate(parent);
        }
    }
    if (type == NotificationType.ChildrenChanged) {
        childrenCache.synchronous().invalidate(path);
    }
    if (type == NotificationType.Created || type == NotificationType.Deleted || type == NotificationType.Modified) {
        metadataCaches.forEach(c -> c.accept(n));
    }
}
Also used : NotificationType(org.apache.pulsar.metadata.api.NotificationType)

Example 3 with NotificationType

use of org.apache.pulsar.metadata.api.NotificationType in project pulsar by apache.

the class AbstractMetadataStore method put.

@Override
public final CompletableFuture<Stat> put(String path, byte[] data, Optional<Long> optExpectedVersion, EnumSet<CreateOption> options) {
    if (!isValidPath(path)) {
        return FutureUtil.failedFuture(new MetadataStoreException.InvalidPathException(path));
    }
    // Ensure caches are invalidated before the operation is confirmed
    return storePut(path, data, optExpectedVersion, options).thenApply(stat -> {
        NotificationType type = stat.getVersion() == 0 ? NotificationType.Created : NotificationType.Modified;
        if (type == NotificationType.Created) {
            existsCache.synchronous().invalidate(path);
            String parent = parent(path);
            if (parent != null) {
                childrenCache.synchronous().invalidate(parent);
            }
        }
        metadataCaches.forEach(c -> c.refresh(path));
        return stat;
    });
}
Also used : MetadataStoreException(org.apache.pulsar.metadata.api.MetadataStoreException) NotificationType(org.apache.pulsar.metadata.api.NotificationType)

Example 4 with NotificationType

use of org.apache.pulsar.metadata.api.NotificationType in project pulsar by yahoo.

the class ZKMetadataStore method handleWatchEvent.

private void handleWatchEvent(WatchedEvent event) {
    if (log.isDebugEnabled()) {
        log.debug("Received ZK watch : {}", event);
    }
    String path = event.getPath();
    if (path == null) {
        // Ignore Session events
        return;
    }
    String parent = parent(path);
    Notification childrenChangedNotification = null;
    NotificationType type;
    switch(event.getType()) {
        case NodeCreated:
            type = NotificationType.Created;
            if (parent != null) {
                childrenChangedNotification = new Notification(NotificationType.ChildrenChanged, parent);
            }
            break;
        case NodeDataChanged:
            type = NotificationType.Modified;
            break;
        case NodeChildrenChanged:
            type = NotificationType.ChildrenChanged;
            break;
        case NodeDeleted:
            type = NotificationType.Deleted;
            if (parent != null) {
                childrenChangedNotification = new Notification(NotificationType.ChildrenChanged, parent);
            }
            break;
        default:
            return;
    }
    receivedNotification(new Notification(type, event.getPath()));
    if (childrenChangedNotification != null) {
        receivedNotification(childrenChangedNotification);
    }
}
Also used : NotificationType(org.apache.pulsar.metadata.api.NotificationType) Notification(org.apache.pulsar.metadata.api.Notification)

Example 5 with NotificationType

use of org.apache.pulsar.metadata.api.NotificationType in project pulsar by yahoo.

the class AbstractMetadataStore method put.

@Override
public final CompletableFuture<Stat> put(String path, byte[] data, Optional<Long> optExpectedVersion, EnumSet<CreateOption> options) {
    if (!isValidPath(path)) {
        return FutureUtil.failedFuture(new MetadataStoreException.InvalidPathException(path));
    }
    // Ensure caches are invalidated before the operation is confirmed
    return storePut(path, data, optExpectedVersion, options).thenApply(stat -> {
        NotificationType type = stat.getVersion() == 0 ? NotificationType.Created : NotificationType.Modified;
        if (type == NotificationType.Created) {
            existsCache.synchronous().invalidate(path);
            String parent = parent(path);
            if (parent != null) {
                childrenCache.synchronous().invalidate(parent);
            }
        }
        metadataCaches.forEach(c -> c.refresh(path));
        return stat;
    });
}
Also used : MetadataStoreException(org.apache.pulsar.metadata.api.MetadataStoreException) NotificationType(org.apache.pulsar.metadata.api.NotificationType)

Aggregations

NotificationType (org.apache.pulsar.metadata.api.NotificationType)12 MetadataStoreException (org.apache.pulsar.metadata.api.MetadataStoreException)6 Notification (org.apache.pulsar.metadata.api.Notification)6 BadVersionException (org.apache.pulsar.metadata.api.MetadataStoreException.BadVersionException)3 Stat (org.apache.pulsar.metadata.api.Stat)3 CompletableFuture (java.util.concurrent.CompletableFuture)1