diff --git a/core/api/src/main/java/org/onosproject/net/flow/FlowRuleOperations.java b/core/api/src/main/java/org/onosproject/net/flow/FlowRuleOperations.java index 545651341d..1bf80070f1 100644 --- a/core/api/src/main/java/org/onosproject/net/flow/FlowRuleOperations.java +++ b/core/api/src/main/java/org/onosproject/net/flow/FlowRuleOperations.java @@ -23,6 +23,7 @@ import com.google.common.collect.Lists; import java.util.List; import java.util.Set; +import static com.google.common.base.Preconditions.checkNotNull; import static org.onosproject.net.flow.FlowRuleOperation.Type.*; /** @@ -32,7 +33,7 @@ import static org.onosproject.net.flow.FlowRuleOperation.Type.*; public class FlowRuleOperations { private final List> stages; - private final FlowRuleOperationsContext callback; // TODO consider Optional + private final FlowRuleOperationsContext callback; private FlowRuleOperations(List> stages, FlowRuleOperationsContext cb) { @@ -164,7 +165,7 @@ public class FlowRuleOperations { * @return flow rule operations */ public FlowRuleOperations build() { - return build(null); + return build(NullFlowRuleOperationsContext.getInstance()); } /** @@ -174,6 +175,8 @@ public class FlowRuleOperations { * @return flow rule operations */ public FlowRuleOperations build(FlowRuleOperationsContext cb) { + checkNotNull(cb); + closeStage(); return new FlowRuleOperations(listBuilder.build(), cb); } diff --git a/core/api/src/main/java/org/onosproject/net/flow/NullFlowRuleOperationsContext.java b/core/api/src/main/java/org/onosproject/net/flow/NullFlowRuleOperationsContext.java new file mode 100644 index 0000000000..a452f22da4 --- /dev/null +++ b/core/api/src/main/java/org/onosproject/net/flow/NullFlowRuleOperationsContext.java @@ -0,0 +1,35 @@ +/* + * Copyright 2016-present Open Networking Laboratory + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onosproject.net.flow; + +/** + * Represents FlowRuleOperations that does nothing on success or on error. + */ +final class NullFlowRuleOperationsContext implements FlowRuleOperationsContext { + private static final FlowRuleOperationsContext INSTANCE = new NullFlowRuleOperationsContext(); + + private NullFlowRuleOperationsContext() {} + + /** + * Returns an instance of this class. + * + * @return instance + */ + public static FlowRuleOperationsContext getInstance() { + return INSTANCE; + } +} diff --git a/core/net/src/main/java/org/onosproject/net/flow/impl/FlowRuleManager.java b/core/net/src/main/java/org/onosproject/net/flow/impl/FlowRuleManager.java index 40829be330..82c1c439b5 100644 --- a/core/net/src/main/java/org/onosproject/net/flow/impl/FlowRuleManager.java +++ b/core/net/src/main/java/org/onosproject/net/flow/impl/FlowRuleManager.java @@ -614,7 +614,7 @@ public class FlowRuleManager public synchronized void run() { if (stages.size() > 0) { process(stages.remove(0)); - } else if (!hasFailed && fops.callback() != null) { + } else if (!hasFailed) { fops.callback().onSuccess(fops); } } @@ -651,13 +651,10 @@ public class FlowRuleManager operationsService.execute(this); } - if (fops.callback() != null) { - final FlowRuleOperations.Builder failedOpsBuilder = - FlowRuleOperations.builder(); - failures.forEach(failedOpsBuilder::add); + FlowRuleOperations.Builder failedOpsBuilder = FlowRuleOperations.builder(); + failures.forEach(failedOpsBuilder::add); - fops.callback().onError(failedOpsBuilder.build()); - } + fops.callback().onError(failedOpsBuilder.build()); } }