/** * Apply the delta instance to the current InstanceInfo * * @param delta the delta changes to applyTo * @return a new InstanceInfo with the deltas applied */ public InstanceInfo applyDelta(Delta delta) { if (!id.equals(delta.getId())) { throw new UnsupportedOperationException("Cannot apply delta to instanceInfo with non-matching id: " + delta.getId() + ", " + id); } InstanceInfo.Builder newInstanceInfoBuilder = new InstanceInfo.Builder().withInstanceInfo(this); return delta.applyTo(newInstanceInfoBuilder).build(); }
/** * 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; }
protected DeltaDTO(Delta<T> delta) { this.id = delta.getId(); this.fieldName = delta.getField().getFieldName().name(); }
private ChangeNotification<InstanceInfo> toChangeNotification(InterestSetNotification message) { if (message instanceof AddInstance) { return new ChangeNotification<>(Kind.Add, ((AddInstance) message).getInstanceInfo()); } if (message instanceof UpdateInstanceInfo) { InstanceInfo instanceInfo = new Builder().withId(((UpdateInstanceInfo) message).getDelta().getId()).build(); return new ChangeNotification<>(Kind.Modify, instanceInfo); } if (message instanceof DeleteInstance) { InstanceInfo instanceInfo = new Builder().withId(((DeleteInstance) message).getInstanceId()).build(); return new ChangeNotification<>(Kind.Delete, instanceInfo); } return null; } }