Update BatchOperation class to be more generic and extensible.
- addAddOperation() and addRemoveOperation() methods are removed
from BatchOperation class, and now the class has just addOperation() method.
- Removed AddOperation and RemoveOperation classes,
and defined IntentBatchOperation, FlowBatchOperation and MatchActionPhase classes
as sub-classes of BatchOperation class, for Intent, IFlow and MatchAction objects
respectively.
- These classes include definitions of add/remove operators and helper methods
specific to Intent, IFlow and MatchAction objects.
- Removed BatchOperationTargetId class.
- Updated unit tests.
- This task is a part of ONOS-1692.
Change-Id: Iba2f737af1fef6a6555e0e0166836865ed070fa3
diff --git a/src/main/java/net/onrc/onos/api/flowmanager/FlowBatchOperation.java b/src/main/java/net/onrc/onos/api/flowmanager/FlowBatchOperation.java
new file mode 100644
index 0000000..42eb81d
--- /dev/null
+++ b/src/main/java/net/onrc/onos/api/flowmanager/FlowBatchOperation.java
@@ -0,0 +1,49 @@
+package net.onrc.onos.api.flowmanager;
+
+import net.onrc.onos.api.batchoperation.BatchOperation;
+import net.onrc.onos.api.batchoperation.BatchOperationEntry;
+
+/**
+ * A list of flow operations.
+ */
+public class FlowBatchOperation extends
+ BatchOperation<BatchOperationEntry<FlowBatchOperation.Operator, ?>> {
+ /**
+ * The flow operations' operators.
+ */
+ public enum Operator {
+ /**
+ * Adds new flow.
+ */
+ ADD,
+
+ /**
+ * Removes the existing flow.
+ */
+ REMOVE,
+ }
+
+ /**
+ * Adds an add-flow operation.
+ *
+ * @param flow the flow to be added
+ * @return the FlowBatchOperation object if succeeded, null otherwise
+ */
+ public FlowBatchOperation addAddFlowOperation(IFlow flow) {
+ return (null == super.addOperation(
+ new BatchOperationEntry<Operator, IFlow>(Operator.ADD, flow)))
+ ? null : this;
+ }
+
+ /**
+ * Adds a remove-flow operation.
+ *
+ * @param flowId the ID of flow to be removed
+ * @return the FlowBatchOperation object if succeeded, null otherwise
+ */
+ public FlowBatchOperation addRemoveFlowOperation(FlowId flowId) {
+ return (null == super.addOperation(
+ new BatchOperationEntry<Operator, FlowId>(Operator.REMOVE, flowId)))
+ ? null : this;
+ }
+}
diff --git a/src/main/java/net/onrc/onos/api/flowmanager/FlowId.java b/src/main/java/net/onrc/onos/api/flowmanager/FlowId.java
index b3c42d6..a0ebd2d 100644
--- a/src/main/java/net/onrc/onos/api/flowmanager/FlowId.java
+++ b/src/main/java/net/onrc/onos/api/flowmanager/FlowId.java
@@ -1,11 +1,11 @@
package net.onrc.onos.api.flowmanager;
-import net.onrc.onos.api.batchoperation.BatchOperationTargetId;
+import net.onrc.onos.api.batchoperation.IBatchOperationTarget;
/**
* Represents ID for IFlow objects.
*/
-public class FlowId extends BatchOperationTargetId {
+public class FlowId implements IBatchOperationTarget {
private final String value;
/**
diff --git a/src/main/java/net/onrc/onos/api/flowmanager/IFlow.java b/src/main/java/net/onrc/onos/api/flowmanager/IFlow.java
index 25b9aea..fbd6b2b 100644
--- a/src/main/java/net/onrc/onos/api/flowmanager/IFlow.java
+++ b/src/main/java/net/onrc/onos/api/flowmanager/IFlow.java
@@ -17,7 +17,6 @@
*
* @return ID for this object.
*/
- @Override
public FlowId getId();
/**
diff --git a/src/main/java/net/onrc/onos/api/flowmanager/IFlowManagerService.java b/src/main/java/net/onrc/onos/api/flowmanager/IFlowManagerService.java
index fcfaacb..efd7b98 100644
--- a/src/main/java/net/onrc/onos/api/flowmanager/IFlowManagerService.java
+++ b/src/main/java/net/onrc/onos/api/flowmanager/IFlowManagerService.java
@@ -3,8 +3,6 @@
import java.util.Collection;
import java.util.EventListener;
-import net.onrc.onos.api.batchoperation.BatchOperation;
-
/**
* An interface class for flow manager. The role of the flow manager is to
* manage a set of Match-Action entries based on the specified IFlow objects.
@@ -51,10 +49,10 @@
/**
* Executes batch operation of IFlow object.
*
- * @param ops FlowOperations to be executed
+ * @param ops flow operations to be executed
* @return true if succeeded, false otherwise
*/
- boolean executeBatch(BatchOperation<IFlow> ops);
+ boolean executeBatch(FlowBatchOperation ops);
/**
* Sets a conflict detection policy.