- public void store(final FlowRegistryKey flowRegistryKey, final FlowDescriptor flowDescriptor) {
- LOG.trace("Storing flowDescriptor with table ID : {} and flow ID : {} for flow hash : {}",
- flowDescriptor.getTableKey().getId(), flowDescriptor.getFlowId().getValue(), flowRegistryKey.hashCode());
- synchronized (flowRegistryKey) {
- try {
- flowRegistry.put(flowRegistryKey, flowDescriptor);
- } catch (IllegalArgumentException ex) {
- LOG.error("Flow with flowId {} already exists in table {}", flowDescriptor.getFlowId().getValue(),
- flowDescriptor.getTableKey().getId());
- final FlowId newFlowId = createAlienFlowId(flowDescriptor.getTableKey().getId());
- final FlowDescriptor newFlowDescriptor = FlowDescriptorFactory.
- create(flowDescriptor.getTableKey().getId(), newFlowId);
- flowRegistry.put(flowRegistryKey, newFlowDescriptor);
+ @GuardedBy("this")
+ public synchronized void storeDescriptor(final FlowRegistryKey flowRegistryKey, final FlowDescriptor flowDescriptor) {
+ final FlowRegistryKey correctFlowRegistryKey = correctFlowRegistryKey(flowRegistry.keySet(), flowRegistryKey);
+
+ try {
+ if (hasMark(correctFlowRegistryKey)) {
+ // We are probably doing update of flow ID or table ID, so remove mark for removal of this flow
+ // and replace it with new value
+ marks.remove(correctFlowRegistryKey(marks, correctFlowRegistryKey));
+ flowRegistry.forcePut(correctFlowRegistryKey, flowDescriptor);
+ return;
+ }
+
+ LOG.trace("Storing flowDescriptor with table ID : {} and flow ID : {} for flow hash : {}",
+ flowDescriptor.getTableKey().getId(), flowDescriptor.getFlowId().getValue(), correctFlowRegistryKey.hashCode());
+
+ flowRegistry.put(correctFlowRegistryKey, flowDescriptor);
+ } catch (IllegalArgumentException ex) {
+ if (hasMark(flowRegistry.inverse().get(flowDescriptor))) {
+ // We are probably doing update of flow, but without changing flow ID or table ID, so we need to replace
+ // old value with new value, but keep the old value marked for removal
+ flowRegistry.forcePut(correctFlowRegistryKey, flowDescriptor);
+ return;