+ private UpdateFlowCallback(UpdateFlowInput input) {
+ this.input = input;
+ }
+
+ @Override
+ public void onSuccess(final RpcResult<UpdateFlowOutput> o) {
+ final UpdatedFlow updated = input.getUpdatedFlow();
+ final OriginalFlow original = input.getOriginalFlow();
+ FlowRegistryKey flowRegistryKey = FlowRegistryKeyFactory.create(original);
+
+ FlowRegistryKey updatedflowRegistryKey = FlowRegistryKeyFactory.create(updated);
+ final FlowRef flowRef = input.getFlowRef();
+ final DeviceFlowRegistry deviceFlowRegistry = deviceContext.getDeviceFlowRegistry();
+
+ if (flowRef == null) {
+ // then this is equivalent to a delete
+ deviceFlowRegistry.removeDescriptor(flowRegistryKey);
+
+ if (itemLifecycleListener != null) {
+ final FlowDescriptor flowDescriptor =
+ deviceContext.getDeviceFlowRegistry().retrieveIdForFlow( flowRegistryKey);
+ KeyedInstanceIdentifier<Flow, FlowKey> flowPath = createFlowPath(flowDescriptor,
+ deviceContext.getDeviceInfo().getNodeInstanceIdentifier());
+ itemLifecycleListener.onRemoved(flowPath);
+ }
+ } else {
+ // this is either an add or an update
+ final FlowId flowId = flowRef.getValue().firstKeyOf(Flow.class, FlowKey.class).getId();
+ final FlowDescriptor flowDescriptor = FlowDescriptorFactory.create(updated.getTableId(), flowId);
+
+ deviceFlowRegistry.update(updatedflowRegistryKey, flowDescriptor);
+
+ if (itemLifecycleListener != null) {
+ KeyedInstanceIdentifier<Flow, FlowKey> flowPath = createFlowPath(flowDescriptor,
+ deviceContext.getDeviceInfo().getNodeInstanceIdentifier());
+ final FlowBuilder flowBuilder = new FlowBuilder(
+ input.getUpdatedFlow()).setId(flowDescriptor.getFlowId());
+
+ boolean isUpdate = null !=
+ deviceFlowRegistry.retrieveIdForFlow(flowRegistryKey);
+ if (isUpdate) {
+ itemLifecycleListener.onUpdated(flowPath, flowBuilder.build());
+ } else {
+ itemLifecycleListener.onAdded(flowPath, flowBuilder.build());
+ }
+ }