/** * For an AddInstance msg, * - if it does not exist in cache, this is an Add Notification to the store * - if it exist in cache but had a different version, this is a modify notification to the store. * For simplicity we treat this as an add if the new msg have a GREATER version number, * and ignore it otherwise */ private ChangeNotification<InstanceInfo> addMessageToChangeNotification(AddInstance msg) { ChangeNotification<InstanceInfo> notification = null; InstanceInfo incoming = msg.getInstanceInfo(); InstanceInfo cached = idVsInstance.get(incoming.getId()); if (cached == null) { idVsInstance.put(incoming.getId(), incoming); notification = new ChangeNotification<>(ChangeNotification.Kind.Add, incoming); } else if (incoming.getVersion() <= cached.getVersion()) { logger.debug("Skipping <= version of the instanceInfo. Cached: {}, Incoming: {}", cached, incoming); } else { logger.debug("Received newer version of an existing instanceInfo as Add"); idVsInstance.put(incoming.getId(), incoming); notification = new ChangeNotification<>(ChangeNotification.Kind.Add, incoming); } return notification; }
/** * 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; }
Builder newBuilder() { return new Builder() .withId(this.baseInstanceInfo.getId()) .withVersion(this.baseInstanceInfo.getVersion() + 1); } }
@Override public boolean matches(Object item) { if (!(item instanceof InstanceInfo)) { return false; } // Versions may be different InstanceInfo target = (InstanceInfo) item; if (!expectSameVersion) { target = new Builder() .withInstanceInfo(target) .withVersion(expectedValue.getVersion()) .build(); } return target.equals(expectedValue); }
if (prev != null && prev.getVersion() > data.getVersion()) { return Observable.just(Status.AddExpired);
Delta<?> delta = new Builder() .withId(lastInstanceInfo.getId()) .withVersion(lastInstanceInfo.getVersion()) .withDelta(field, value) .build();