@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; }
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()); } }
@SafeVarargs public final void assertReceivesBatch(ChangeNotification<InstanceInfo>... dataNotifications) { assertReceives(dataNotifications); assertThat(takeNextOrFail().getKind(), is(equalTo(Kind.BufferSentinel))); } }
private static boolean isMatching(ChangeNotification<InstanceInfo> notification, Holder holder) { Long expectedTimestamp = getTimestamp(holder.getNotification()); Long incomingTimestamp = getTimestamp(notification); if (incomingTimestamp == null) { return false; } return notification.getKind() == holder.getNotification().getKind() && expectedTimestamp.equals(incomingTimestamp); }
@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()); } } });
Holder(ChangeNotification<InstanceInfo> notification) { this.notification = notification; this.timestamp = TopologyFunctions.getTimestamp(notification); this.startTime = notification.getKind() == Kind.Add ? timestamp : scheduler.now(); }
@Override public MembershipEvent<Server> call(ChangeNotification<Server> notification) { Server server = notification.getData(); switch (notification.getKind()) { case Add: return new MembershipEvent<>(EventType.ADD, server); case Modify: throw new IllegalStateException("Modify not expected"); case Delete: return new MembershipEvent<Server>(EventType.REMOVE, server); } return null; } });
@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 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()); }
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<InetSocketAddress> call(ChangeNotification<WriteServerAddress> notification) { WriteServerAddress data = notification.getData(); InetSocketAddress socketAddress = new InetSocketAddress(data.getHostName(), data.getReplicationPort()); switch (notification.getKind()) { case Add: return new ChangeNotification<InetSocketAddress>(Kind.Add, socketAddress); case Modify: throw new IllegalStateException("Modify not expected"); case Delete: return new ChangeNotification<InetSocketAddress>(Kind.Delete, socketAddress); } return null; } });
@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<InstanceInfo> notification) { switch (notification.getKind()) { // these are in-mem blocking ops case Add: case Modify: registry.register(notification.getData(), selfSource); break; case Delete: registry.unregister(notification.getData(), selfSource); break; case BufferSentinel: // No-op break; default: logger.error("Unrecognized notification kind"); } } });
@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); } }
@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 Observable<Void> call(ChangeNotification<InstanceInfo> notification) { switch (notification.getKind()) { case Add: return channel.register(notification.getData()); case Modify: return channel.register(notification.getData()); case Delete: return channel.unregister(notification.getData().getId()); default: logger.warn("Unrecognised notification kind {}", notification); return Observable.empty(); } } });
@Override public MembershipEvent<Server> call(ChangeNotification<WriteServerAddress> notification) { WriteServerAddress endpoints = notification.getData(); int port = portFunc.call(endpoints); switch (notification.getKind()) { case Add: return new MembershipEvent<>(EventType.ADD, new Server(endpoints.getHostName(), port)); case Modify: throw new IllegalStateException("Modify not expected"); case Delete: return new MembershipEvent<Server>(EventType.REMOVE, new Server(endpoints.getHostName(), port)); } return null; } });
private void findLatent() { long now = scheduler.now(); for (Holder next = expiryQueue.peek(); next != null; next = expiryQueue.peek()) { if (next.isDelivered()) { expiryQueue.poll(); } else if (next.getExpiryTime() <= now) { ChangeNotification<InstanceInfo> notification = next.getNotification(); logger.warn("Latent {} notification with id {} by {}ms", notification.getKind(), notification.getData().getId(), next.getLatency()); expiryQueue.poll(); scoreBoard.latentNotificationIncrement(); } else { break; } } }