private Set<ChangeNotification<String>> cancellationSet(Set<ChangeNotification<String>> currentSnapshot, Set<ChangeNotification<String>> newAddresses) { Set<ChangeNotification<String>> cancelled = new HashSet<>(); for (ChangeNotification<String> entry : currentSnapshot) { if (!newAddresses.contains(entry)) { cancelled.add(new ChangeNotification<String>(Kind.Delete, entry.getData())); } } return cancelled; } }
private Set<ChangeNotification<Server>> cancellationSet(Set<ChangeNotification<Server>> currentSnapshot, Set<ChangeNotification<Server>> newAddresses) { Set<ChangeNotification<Server>> cancelled = new HashSet<>(); for (ChangeNotification<Server> entry : currentSnapshot) { if (!newAddresses.contains(entry)) { cancelled.add(new ChangeNotification<Server>(Kind.Delete, entry.getData())); } } return cancelled; }
@Override public Boolean call(ChangeNotification<T> notification) { return interest.matches(notification.getData()); } }).subscribe(toReturn); // data source sends all notifications irrespective of the interest set. Here we filter based on interest.
void stop() { latentTrackerSubscription.unsubscribe(); long left = 0; for (List<Holder> holderList : expectedNotificationsById.values()) { left += holderList.size(); for (Holder holder : holderList) { logger.debug("Releasing instance {}", System.identityHashCode(holder.getNotification().getData())); } } logger.info("Left {} notifications when stopped", left); }
private Set<ChangeNotification<Server>> cancellationSet(Set<ChangeNotification<Server>> currentSnapshot, Set<ChangeNotification<Server>> newAddresses) { Set<ChangeNotification<Server>> cancelled = new HashSet<>(); for (ChangeNotification<Server> entry : currentSnapshot) { if (!newAddresses.contains(entry)) { cancelled.add(new ChangeNotification<Server>(ChangeNotification.Kind.Delete, entry.getData())); } } return cancelled; }
@Override protected void addNotification(ChangeNotification<InstanceInfo> notification) { String id = notification.getData().getId(); ChangeNotification<InstanceInfo> current = notificationMap.get(id); ChangeNotification<InstanceInfo> updated = processNext(current, notification); if (updated != null) { notificationMap.put(id, updated); } else if (current != null) { notificationMap.remove(id); } }
private void removeServerAddress(int idx) { ChangeNotification<A> addChange = clusterAddresses.remove(idx); clusterAddressUpdates.onNext(new ChangeNotification<A>(Kind.Delete, addChange.getData())); } }
private void removeServerAddress(int idx) { ChangeNotification<A> addChange = clusterAddresses.remove(idx); clusterAddressUpdates.onNext(new ChangeNotification<A>(Kind.Delete, addChange.getData())); } }
public InstanceInfoInitStateHolder(Iterator<ChangeNotification<InstanceInfo>> initialRegistry, Interest<InstanceInfo> interest) { super(PauseableSubject.<ChangeNotification<InstanceInfo>>create()); this.bufferStartNotification = new StreamStateNotification<>(BufferState.BufferStart, interest); this.bufferEndNotification = new StreamStateNotification<>(BufferState.BufferEnd, interest); notificationMap = new ConcurrentHashMap<>(); while (initialRegistry.hasNext()) { ChangeNotification<InstanceInfo> next = initialRegistry.next(); notificationMap.put(next.getData().getId(), next); // Always Kind.Add } }
@Override public void call(ChangeNotification<InstanceInfo> notification) { if (interest.matches(notification.getData())) { notificationTracker.addExpectation(notification); } } }
@Override public ChangeNotification<InetSocketAddress> call(ChangeNotification<String> notification) { return new ChangeNotification<>( notification.getKind(), new InetSocketAddress(notification.getData(), sb.getReplicationPort()) ); } });
@Override public void call(ChangeNotification<InstanceInfo> changeNotification) { final ChangeNotification.Kind notificationKind = changeNotification.getKind(); final InstanceInfo instInfo = changeNotification.getData(); if (notificationKind == ChangeNotification.Kind.Add || notificationKind == ChangeNotification.Kind.Modify) { registryCache.put(instInfo.getId(), instInfo); } else if (notificationKind == ChangeNotification.Kind.Delete) { registryCache.remove(instInfo.getId()); } } });
@Override public void onNext(ChangeNotification<InstanceInfo> notification) { if (notification.isDataNotification() && interest.matches(notification.getData())) { notificationTracker.verifyWithExpectations(notification); logger.debug("Notification={}", notification); } } });
@Override public void onNext(ChangeNotification<InstanceInfo> notification) { metrics.incrementApplicationNotificationCounter(notification.getData().getApp()); Observable<Void> sendResult = sendNotification(notification); if(sendResult != null) { subscribeToTransportSend(sendResult, "notification"); } else { // TODO: how to report effectively invariant violations that should never happen in a valid code, but are not errors? logger.warn("No-effect modify in the interest channel: {}", notification); } } });
@Override public void onNext(ChangeNotification<InstanceInfo> notification) { if (notification.isDataNotification() && interest.matches(notification.getData())) { finalSubject.onNext(notification); } } });
public static AuditRecord forChangeNotification(String auditServerId, long timestamp, boolean userTriggered, ChangeNotification<InstanceInfo> changeNotification) { switch (changeNotification.getKind()) { case Add: return forInstanceAdd(auditServerId, timestamp, userTriggered, changeNotification.getData()); case Modify: ModifyNotification<InstanceInfo> modifyNotification = (ModifyNotification<InstanceInfo>) changeNotification; return forInstanceUpdate(auditServerId, timestamp, userTriggered, modifyNotification.getData(), modifyNotification.getDelta()); case Delete: return forInstanceDelete(auditServerId, timestamp, userTriggered, changeNotification.getData()); } throw new IllegalStateException("unhadled enum value " + changeNotification.getKind()); }
public static AuditRecord forChangeNotification(String auditServerId, long timestamp, boolean userTriggered, ChangeNotification<InstanceInfo> changeNotification) { switch (changeNotification.getKind()) { case Add: return forInstanceAdd(auditServerId, timestamp, userTriggered, changeNotification.getData()); case Modify: ModifyNotification<InstanceInfo> modifyNotification = (ModifyNotification<InstanceInfo>) changeNotification; return forInstanceUpdate(auditServerId, timestamp, userTriggered, modifyNotification.getData(), modifyNotification.getDelta()); case Delete: return forInstanceDelete(auditServerId, timestamp, userTriggered, changeNotification.getData()); } throw new IllegalStateException("unhadled enum value " + changeNotification.getKind()); }
@Override public ChangeNotification<Server> call(ChangeNotification<ClusterAddress> notification) { if (notification.getKind() == Kind.BufferSentinel) { return ChangeNotification.bufferSentinel(); } Server server = new Server( notification.getData().getHostName(), notification.getData().getPortFor(serviceType) ); return new ChangeNotification<Server>(notification.getKind(), server); } });
@Override public void onNext(ChangeNotification<E> notification) { R converted = converter.call(notification.getData()); switch (notification.getKind()) { case Add: case Modify: servers.add(converted); break; case Delete: servers.remove(converted); } }
public static ChangeNotification<InstanceInfo> addTimeStamp(ChangeNotification<InstanceInfo> notification, long timeStamp) { InstanceInfo timeStamped = addTimeStamp(notification.getData(), timeStamp); switch (notification.getKind()) { case Add: case Delete: return new ChangeNotification<>(notification.getKind(), timeStamped); case Modify: return new ModifyNotification<>(timeStamped, ((ModifyNotification) notification).getDelta()); default: throw new IllegalArgumentException("Unexpected enum value " + notification.getKind()); } }