Skip to content

Commit

Permalink
Copy FlowOperationsProcessor defensively for thread safety
Browse files Browse the repository at this point in the history
Change-Id: Ic5c920b0efc40d472d454b0e1a0305f16b39e98c
  • Loading branch information
Sho SHIMIZU committed Sep 7, 2016
1 parent 283eb2f commit f752afc
Showing 1 changed file with 11 additions and 3 deletions.
Expand Up @@ -582,12 +582,20 @@ private class FlowOperationsProcessor implements Runnable {

// Mutable
private final List<Set<FlowRuleOperation>> stages;
private final Set<DeviceId> pendingDevices = new HashSet<>();
private final Set<DeviceId> pendingDevices;
private boolean hasFailed = false;

FlowOperationsProcessor(FlowRuleOperations ops) {
this.stages = Lists.newArrayList(ops.stages());
this.fops = ops;
this.pendingDevices = new HashSet<>();
}

FlowOperationsProcessor(FlowOperationsProcessor src) {
this.fops = src.fops;
this.stages = Lists.newArrayList(src.stages);
this.pendingDevices = new HashSet<>(src.pendingDevices);
this.hasFailed = src.hasFailed;
}

@Override
Expand Down Expand Up @@ -620,15 +628,15 @@ private void process(Set<FlowRuleOperation> ops) {
synchronized void satisfy(DeviceId devId) {
pendingDevices.remove(devId);
if (pendingDevices.isEmpty()) {
operationsService.execute(this);
operationsService.execute(new FlowOperationsProcessor(this));
}
}

synchronized void fail(DeviceId devId, Set<? extends FlowRule> failures) {
hasFailed = true;
pendingDevices.remove(devId);
if (pendingDevices.isEmpty()) {
operationsService.execute(this);
operationsService.execute(new FlowOperationsProcessor(this));
}

FlowRuleOperations.Builder failedOpsBuilder = FlowRuleOperations.builder();
Expand Down

0 comments on commit f752afc

Please sign in to comment.