Brian O'Connor

ONOS-5271 pendingDevices is used to track installation progress,

thus it is mutable.

This reverts commit e38b866a.

Change-Id: Ie71a4cf2d795e2fd781e96fc1274cfcbfc659cb5
...@@ -16,7 +16,6 @@ ...@@ -16,7 +16,6 @@
16 package org.onosproject.net.flow.impl; 16 package org.onosproject.net.flow.impl;
17 17
18 import com.google.common.collect.ArrayListMultimap; 18 import com.google.common.collect.ArrayListMultimap;
19 -import com.google.common.collect.ImmutableSet;
20 import com.google.common.collect.Iterables; 19 import com.google.common.collect.Iterables;
21 import com.google.common.collect.Lists; 20 import com.google.common.collect.Lists;
22 import com.google.common.collect.Maps; 21 import com.google.common.collect.Maps;
...@@ -601,22 +600,22 @@ public class FlowRuleManager ...@@ -601,22 +600,22 @@ public class FlowRuleManager
601 private class FlowOperationsProcessor implements Runnable { 600 private class FlowOperationsProcessor implements Runnable {
602 // Immutable 601 // Immutable
603 private final FlowRuleOperations fops; 602 private final FlowRuleOperations fops;
604 - private final ImmutableSet<DeviceId> pendingDevices;
605 603
606 // Mutable 604 // Mutable
607 private final List<Set<FlowRuleOperation>> stages; 605 private final List<Set<FlowRuleOperation>> stages;
606 + private final Set<DeviceId> pendingDevices;
608 private boolean hasFailed = false; 607 private boolean hasFailed = false;
609 608
610 FlowOperationsProcessor(FlowRuleOperations ops) { 609 FlowOperationsProcessor(FlowRuleOperations ops) {
611 this.stages = Lists.newArrayList(ops.stages()); 610 this.stages = Lists.newArrayList(ops.stages());
612 this.fops = ops; 611 this.fops = ops;
613 - this.pendingDevices = ImmutableSet.of(); 612 + this.pendingDevices = new HashSet<>();
614 } 613 }
615 614
616 - FlowOperationsProcessor(FlowOperationsProcessor src, boolean hasFailed, Set<DeviceId> pendingDevices) { 615 + FlowOperationsProcessor(FlowOperationsProcessor src, boolean hasFailed) {
617 this.fops = src.fops; 616 this.fops = src.fops;
618 this.stages = Lists.newArrayList(src.stages); 617 this.stages = Lists.newArrayList(src.stages);
619 - this.pendingDevices = ImmutableSet.copyOf(pendingDevices); 618 + this.pendingDevices = new HashSet<>(src.pendingDevices);
620 this.hasFailed = hasFailed; 619 this.hasFailed = hasFailed;
621 } 620 }
622 621
...@@ -636,33 +635,28 @@ public class FlowRuleManager ...@@ -636,33 +635,28 @@ public class FlowRuleManager
636 perDeviceBatches.put(op.rule().deviceId(), 635 perDeviceBatches.put(op.rule().deviceId(),
637 new FlowRuleBatchEntry(mapOperationType(op.type()), op.rule())); 636 new FlowRuleBatchEntry(mapOperationType(op.type()), op.rule()));
638 } 637 }
639 - ImmutableSet<DeviceId> newPendingDevices = ImmutableSet.<DeviceId>builder() 638 + pendingDevices.addAll(perDeviceBatches.keySet());
640 - .addAll(pendingDevices)
641 - .addAll(perDeviceBatches.keySet())
642 - .build();
643 639
644 for (DeviceId deviceId : perDeviceBatches.keySet()) { 640 for (DeviceId deviceId : perDeviceBatches.keySet()) {
645 long id = idGenerator.getNewId(); 641 long id = idGenerator.getNewId();
646 final FlowRuleBatchOperation b = new FlowRuleBatchOperation(perDeviceBatches.get(deviceId), 642 final FlowRuleBatchOperation b = new FlowRuleBatchOperation(perDeviceBatches.get(deviceId),
647 deviceId, id); 643 deviceId, id);
648 - pendingFlowOperations.put(id, new FlowOperationsProcessor(this, hasFailed, newPendingDevices)); 644 + pendingFlowOperations.put(id, this);
649 deviceInstallers.execute(() -> store.storeBatch(b)); 645 deviceInstallers.execute(() -> store.storeBatch(b));
650 } 646 }
651 } 647 }
652 648
653 synchronized void satisfy(DeviceId devId) { 649 synchronized void satisfy(DeviceId devId) {
654 - Set<DeviceId> newPendingDevices = new HashSet<>(pendingDevices); 650 + pendingDevices.remove(devId);
655 - newPendingDevices.remove(devId); 651 + if (pendingDevices.isEmpty()) {
656 - if (newPendingDevices.isEmpty()) { 652 + operationsService.execute(new FlowOperationsProcessor(this, hasFailed));
657 - operationsService.execute(new FlowOperationsProcessor(this, hasFailed, newPendingDevices));
658 } 653 }
659 } 654 }
660 655
661 synchronized void fail(DeviceId devId, Set<? extends FlowRule> failures) { 656 synchronized void fail(DeviceId devId, Set<? extends FlowRule> failures) {
662 - Set<DeviceId> newPendingDevices = new HashSet<>(pendingDevices); 657 + pendingDevices.remove(devId);
663 - newPendingDevices.remove(devId); 658 + if (pendingDevices.isEmpty()) {
664 - if (newPendingDevices.isEmpty()) { 659 + operationsService.execute(new FlowOperationsProcessor(this, true));
665 - operationsService.execute(new FlowOperationsProcessor(this, true, newPendingDevices));
666 } 660 }
667 661
668 FlowRuleOperations.Builder failedOpsBuilder = FlowRuleOperations.builder(); 662 FlowRuleOperations.Builder failedOpsBuilder = FlowRuleOperations.builder();
......