Provide pendingDevices explicitly
Change-Id: I2cc29d5672d11aa176c7fa774e9d66f32b2d300f
Showing
1 changed file
with
18 additions
and
12 deletions
... | @@ -16,6 +16,7 @@ | ... | @@ -16,6 +16,7 @@ |
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; | ||
19 | import com.google.common.collect.Iterables; | 20 | import com.google.common.collect.Iterables; |
20 | import com.google.common.collect.Lists; | 21 | import com.google.common.collect.Lists; |
21 | import com.google.common.collect.Maps; | 22 | import com.google.common.collect.Maps; |
... | @@ -579,22 +580,22 @@ public class FlowRuleManager | ... | @@ -579,22 +580,22 @@ public class FlowRuleManager |
579 | private class FlowOperationsProcessor implements Runnable { | 580 | private class FlowOperationsProcessor implements Runnable { |
580 | // Immutable | 581 | // Immutable |
581 | private final FlowRuleOperations fops; | 582 | private final FlowRuleOperations fops; |
583 | + private final ImmutableSet<DeviceId> pendingDevices; | ||
582 | 584 | ||
583 | // Mutable | 585 | // Mutable |
584 | private final List<Set<FlowRuleOperation>> stages; | 586 | private final List<Set<FlowRuleOperation>> stages; |
585 | - private final Set<DeviceId> pendingDevices; | ||
586 | private boolean hasFailed = false; | 587 | private boolean hasFailed = false; |
587 | 588 | ||
588 | FlowOperationsProcessor(FlowRuleOperations ops) { | 589 | FlowOperationsProcessor(FlowRuleOperations ops) { |
589 | this.stages = Lists.newArrayList(ops.stages()); | 590 | this.stages = Lists.newArrayList(ops.stages()); |
590 | this.fops = ops; | 591 | this.fops = ops; |
591 | - this.pendingDevices = new HashSet<>(); | 592 | + this.pendingDevices = ImmutableSet.of(); |
592 | } | 593 | } |
593 | 594 | ||
594 | - FlowOperationsProcessor(FlowOperationsProcessor src, boolean hasFailed) { | 595 | + FlowOperationsProcessor(FlowOperationsProcessor src, boolean hasFailed, Set<DeviceId> pendingDevices) { |
595 | this.fops = src.fops; | 596 | this.fops = src.fops; |
596 | this.stages = Lists.newArrayList(src.stages); | 597 | this.stages = Lists.newArrayList(src.stages); |
597 | - this.pendingDevices = new HashSet<>(src.pendingDevices); | 598 | + this.pendingDevices = ImmutableSet.copyOf(pendingDevices); |
598 | this.hasFailed = hasFailed; | 599 | this.hasFailed = hasFailed; |
599 | } | 600 | } |
600 | 601 | ||
... | @@ -614,28 +615,33 @@ public class FlowRuleManager | ... | @@ -614,28 +615,33 @@ public class FlowRuleManager |
614 | perDeviceBatches.put(op.rule().deviceId(), | 615 | perDeviceBatches.put(op.rule().deviceId(), |
615 | new FlowRuleBatchEntry(mapOperationType(op.type()), op.rule())); | 616 | new FlowRuleBatchEntry(mapOperationType(op.type()), op.rule())); |
616 | } | 617 | } |
617 | - pendingDevices.addAll(perDeviceBatches.keySet()); | 618 | + ImmutableSet<DeviceId> newPendingDevices = ImmutableSet.<DeviceId>builder() |
619 | + .addAll(pendingDevices) | ||
620 | + .addAll(perDeviceBatches.keySet()) | ||
621 | + .build(); | ||
618 | 622 | ||
619 | for (DeviceId deviceId : perDeviceBatches.keySet()) { | 623 | for (DeviceId deviceId : perDeviceBatches.keySet()) { |
620 | long id = idGenerator.getNewId(); | 624 | long id = idGenerator.getNewId(); |
621 | final FlowRuleBatchOperation b = new FlowRuleBatchOperation(perDeviceBatches.get(deviceId), | 625 | final FlowRuleBatchOperation b = new FlowRuleBatchOperation(perDeviceBatches.get(deviceId), |
622 | deviceId, id); | 626 | deviceId, id); |
623 | - pendingFlowOperations.put(id, this); | 627 | + pendingFlowOperations.put(id, new FlowOperationsProcessor(this, hasFailed, newPendingDevices)); |
624 | deviceInstallers.execute(() -> store.storeBatch(b)); | 628 | deviceInstallers.execute(() -> store.storeBatch(b)); |
625 | } | 629 | } |
626 | } | 630 | } |
627 | 631 | ||
628 | synchronized void satisfy(DeviceId devId) { | 632 | synchronized void satisfy(DeviceId devId) { |
629 | - pendingDevices.remove(devId); | 633 | + Set<DeviceId> newPendingDevices = new HashSet<>(pendingDevices); |
630 | - if (pendingDevices.isEmpty()) { | 634 | + newPendingDevices.remove(devId); |
631 | - operationsService.execute(new FlowOperationsProcessor(this, hasFailed)); | 635 | + if (newPendingDevices.isEmpty()) { |
636 | + operationsService.execute(new FlowOperationsProcessor(this, hasFailed, newPendingDevices)); | ||
632 | } | 637 | } |
633 | } | 638 | } |
634 | 639 | ||
635 | synchronized void fail(DeviceId devId, Set<? extends FlowRule> failures) { | 640 | synchronized void fail(DeviceId devId, Set<? extends FlowRule> failures) { |
636 | - pendingDevices.remove(devId); | 641 | + Set<DeviceId> newPendingDevices = new HashSet<>(pendingDevices); |
637 | - if (pendingDevices.isEmpty()) { | 642 | + newPendingDevices.remove(devId); |
638 | - operationsService.execute(new FlowOperationsProcessor(this, true)); | 643 | + if (newPendingDevices.isEmpty()) { |
644 | + operationsService.execute(new FlowOperationsProcessor(this, true, newPendingDevices)); | ||
639 | } | 645 | } |
640 | 646 | ||
641 | FlowRuleOperations.Builder failedOpsBuilder = FlowRuleOperations.builder(); | 647 | FlowRuleOperations.Builder failedOpsBuilder = FlowRuleOperations.builder(); | ... | ... |
-
Please register or login to post a comment