public ModifyNotification<T> toBaseNotification() { return new ModifyNotification<>(getData(), getDelta()); }
/** * For an UpdateInstanceInfo msg, * - if it does not exist in cache, we ignore this message as we do not have enough information to restore it * - if it exist in cache but is different, this is a modify notification to the store. * We only apply changes to cached instance if it has a version number GREATER THAN the cached * version number. */ @SuppressWarnings("unchecked") private ChangeNotification<InstanceInfo> updateMessageToChangeNotification(UpdateInstanceInfo msg) { ModifyNotification<InstanceInfo> notification = null; Delta delta = msg.getDelta(); InstanceInfo cached = idVsInstance.get(delta.getId()); if (cached == null) { if (logger.isWarnEnabled()) { logger.warn("Update notification received for non-existent instance id " + delta.getId()); } } else { InstanceInfo updatedInfo = cached.applyDelta(delta); idVsInstance.put(updatedInfo.getId(), updatedInfo); notification = new ModifyNotification(updatedInfo, Collections.singleton(delta)); } return notification; }
@Override public Observable<Void> update(InstanceInfo updatedInfo, Set<Delta<?>> deltas) { InstanceInfo previous = internalStore.put(updatedInfo.getId(), updatedInfo); if (previous == null) { notificationSubject.onNext(new ChangeNotification<>(Kind.Add, updatedInfo)); } else { notificationSubject.onNext(new ModifyNotification<>(updatedInfo, deltas)); } return Observable.empty(); }
/** * For an UpdateInstanceInfo msg, * - if it does not exist in cache, we ignore this message as we do not have enough information to restore it * - if it exist in cache but is different, this is a modify notification to the store. * We only apply changes to cached instance if it has a version number GREATER THAN the cached * version number. */ @SuppressWarnings("unchecked") private ChangeNotification<InstanceInfo> updateMessageToChangeNotification(UpdateInstanceInfo msg) { ModifyNotification<InstanceInfo> notification = null; Delta delta = msg.getDelta(); InstanceInfo cached = idVsInstance.get(delta.getId()); if (cached == null) { if (logger.isWarnEnabled()) { logger.warn("Update notification received for non-existent instance id " + delta.getId()); } } else if (delta.getVersion() <= cached.getVersion()) { logger.debug("Skipping <= version of the delta. Cached: {}, Delta: {}", cached, delta); } else { InstanceInfo updatedInfo = cached.applyDelta(delta); idVsInstance.put(updatedInfo.getId(), updatedInfo); notification = new ModifyNotification(updatedInfo, Collections.singleton(delta)); } return notification; }
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()); } }