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);
}
}
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));
}
}
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;
});
}
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);
}
}
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;
});
}
Aggregations