@Override public boolean matches(Object item) { if (!(item instanceof ChangeNotification)) { return false; } if (!(((ChangeNotification<?>) item).getData() instanceof InstanceInfo)) { return false; } ChangeNotification<InstanceInfo> actualNotif = (ChangeNotification<InstanceInfo>) item; if (actualNotif.getKind() != notificationKind) { return false; } return EurekaMatchers.sameInstanceInfoAs(expectedValue).matches(actualNotif.getData()); }
@Override public ChangeNotification<ClusterAddress> call(ChangeNotification<String> hostNotification) { Kind kind = hostNotification.getKind(); if (kind == Kind.BufferSentinel) { return BUFFER_SENTINEL_NOTIFICATION; } ClusterAddress address = createClusterAddress(hostNotification.getData()); if (kind == Kind.Add || kind == Kind.Modify) { return new ChangeNotification<ClusterAddress>(Kind.Add, address); } return new ChangeNotification<ClusterAddress>(Kind.Delete, address); } });
@Override public ChangeNotification<Server> call(ChangeNotification<InstanceInfo> notification) { switch (notification.getKind()) { case BufferSentinel: return ChangeNotification.bufferSentinel(); // type change case Add: case Modify: case Delete: Server newServer = instanceInfoToServer(notification.getData()); if (newServer != null) { return new ChangeNotification<>(notification.getKind(), newServer); } break; default: // no-op } return null; }
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 ChangeNotification<InstanceInfo> newNotification(InstanceInfo seed) { return new ChangeNotification<>(ChangeNotification.Kind.Add, seed); } },
@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.
private static <T> void collapse(List<ChangeNotification<T>> notifications, Map<T, Integer> markers, List<ChangeNotification<T>> result) { for (int i = notifications.size() - 1; i >= 0; i--) { ChangeNotification<T> next = notifications.get(i); if(next.isDataNotification()) { T data = next.getData(); if (markers.keySet().contains(data)) { int idx = markers.get(data); if (next.getKind() == Kind.Add && result.get(idx).getKind() == Kind.Modify) { result.set(idx, next); } } else { markers.put(data, result.size()); result.add(next); } } } } }
@Override public boolean matches(Object item) { if (!(item instanceof ChangeNotification)) { return false; } ChangeNotification<InstanceInfo> notification = (ChangeNotification<InstanceInfo>) item; for (Kind kind : notificationKinds) { if (notification.getKind() == kind) { return true; } } return false; }
@Override public void onNext(ChangeNotification<InstanceInfo> notification) { if (notification.isDataNotification() && interest.matches(notification.getData())) { finalSubject.onNext(notification); } } });
public StaticEurekaClusterResolver(List<ClusterAddress> clusterAddresses) { List<ChangeNotification<ClusterAddress>> addNotifications = new ArrayList<>(clusterAddresses.size()); for (ClusterAddress address : clusterAddresses) { addNotifications.add(new ChangeNotification<ClusterAddress>(Kind.Add, address)); } addNotifications.add(ChangeNotification.<ClusterAddress>bufferSentinel()); this.clusterObserver = Observable.from(addNotifications); }
protected Observable<ChangeNotification<A>> clusterChangeObservable() { ChangeNotification<A> sentinel = ChangeNotification.bufferSentinel(); return Observable.from(clusterAddresses) .concatWith(Observable.just(sentinel)) .concatWith(clusterAddressUpdates); }
@Override public Boolean call(ChangeNotification<?> notification) { return notification.isDataNotification(); } };
@Override public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; if (!super.equals(o)) return false; StreamStateNotification that = (StreamStateNotification) o; if (bufferState != that.bufferState) return false; if (!interest.equals(that.interest)) return false; return true; }
@Override public ChangeNotification<T> call(T data) { return new ChangeNotification<>(Kind.Add, data); } };
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; } }
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); }
@Override public boolean matches(Object item) { actualObject = item; if (!(item instanceof List)) { errorType = ErrorType.InvalidArgument; return false; } List<ChangeNotification<T>> actual = (List<ChangeNotification<T>>) item; // Verify there is buffer notification if (actual.isEmpty() || actual.get(0).getKind() != Kind.BufferSentinel) { errorType = ErrorType.NoBufferStart; return false; } // Verify there is finish buffering notification ChangeNotification<T> lastItem = actual.get(actual.size() - 1); if (actual.size() == 1 || lastItem.getKind() != Kind.BufferSentinel) { errorType = ErrorType.NoBufferEnd; return false; } // Verify we have all expected data List<ChangeNotification<T>> actualData = actual.subList(1, actual.size() - 1); dataMatcher = containsInAnyOrder(expectedData.toArray(new ChangeNotification[expectedData.size()])); if (dataMatcher.matches(actualData)) { return true; } errorType = ErrorType.NotMatchingData; return false; }
@Override public void onNext(ChangeNotification<InstanceInfo> notification) { if (notification.isDataNotification() && interest.matches(notification.getData())) { notificationTracker.verifyWithExpectations(notification); logger.debug("Notification={}", notification); } } });
@Override public boolean equals(Object o) { if (this == o) return true; if (!(o instanceof SourcedChangeNotification)) return false; if (!super.equals(o)) return false; SourcedChangeNotification that = (SourcedChangeNotification) o; if (source != null ? !source.equals(that.source) : that.source != null) return false; return true; }
@Override public boolean matches(Object item) { if (!(item instanceof ChangeNotification)) { return false; } ChangeNotification<InstanceInfo> actualNotif = (ChangeNotification<InstanceInfo>) item; if (actualNotif.getKind() != notificationKind) { return false; } if (expectedValue == null) { return true; } if (!(((ChangeNotification<?>) item).getData() instanceof InstanceInfo)) { return false; } return EurekaMatchers.sameInstanceInfoAs(expectedValue).matches(actualNotif.getData()); }