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()); } }
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 void onNext(ChangeNotification<InstanceInfo> notification) { switch (notification.getKind()) { // these are in-mem blocking ops case Add: registry.register(notification.getData()); break; case Modify: ModifyNotification<InstanceInfo> modifyNotification = (ModifyNotification<InstanceInfo>) notification; registry.update(modifyNotification.getData(), modifyNotification.getDelta()); break; case Delete: registry.unregister(notification.getData()); break; default: logger.error("Unrecognized notification kind"); } } });
public Observable<Void> sendNotification(ChangeNotification<InstanceInfo> notification) { switch (notification.getKind()) { case Add: return transport.submitWithAck(new AddInstance(notification.getData())); case Delete: return transport.submitWithAck(new DeleteInstance(notification.getData().getId())); case Modify: final ModifyNotification<InstanceInfo> modifyNotification = (ModifyNotification<InstanceInfo>) notification; /** * Below will only work correctly if {@link MessageBroker#submitWithAck(Object)} is a lazy submit i.e. * the message is only sent over the wire when subscribed. If it is eager i.e. the message is written * to the underlying connection without subscription then {@link Observable#concatWith(Observable)} * will eagerly write all the messages without waiting for an ack. */ Observable<Void> toReturn = null; for (final Delta<?> delta : modifyNotification.getDelta()) { if (null == toReturn) { toReturn = transport.submitWithAck(new UpdateInstanceInfo(delta)); } else { toReturn.concatWith(transport.submitWithAck(new UpdateInstanceInfo(delta))); } } return toReturn; } return Observable.error(new IllegalArgumentException("Unknown change notification type: " + notification.getKind())); }
private Observable<Void> sendNotification(ChangeNotification<InstanceInfo> notification) { switch (notification.getKind()) { case Add: return transport.submitWithAck(new AddInstance(notification.getData())); case Delete: return transport.submitWithAck(new DeleteInstance(notification.getData().getId())); case Modify: final ModifyNotification<InstanceInfo> modifyNotification = (ModifyNotification<InstanceInfo>) notification; /** * Below will only work correctly if {@link MessageBroker#submitWithAck(Object)} is a lazy submit i.e. * the message is only sent over the wire when subscribed. If it is eager i.e. the message is written * to the underlying connection without subscription then {@link Observable#concatWith(Observable)} * will eagerly write all the messages without waiting for an ack. */ Observable<Void> toReturn = null; for (final Delta<?> delta : modifyNotification.getDelta()) { if (null == toReturn) { toReturn = transport.submitWithAck(new UpdateInstanceInfo(delta)); } else { toReturn.concatWith(transport.submitWithAck(new UpdateInstanceInfo(delta))); } } return toReturn; case BufferSentinel: return transport.submitWithAck(new StreamStateUpdate((StreamStateNotification<InstanceInfo>) notification)); } return Observable.error(new IllegalArgumentException("Unknown change notification type: " + notification.getKind())); }