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/intent/IIntentRuntimeService.java b/src/main/java/net/onrc/onos/api/intent/IIntentRuntimeService.java
index fc9d788..890bb7f 100644
--- a/src/main/java/net/onrc/onos/api/intent/IIntentRuntimeService.java
+++ b/src/main/java/net/onrc/onos/api/intent/IIntentRuntimeService.java
@@ -3,7 +3,6 @@
import java.util.Collection;
import java.util.EventListener;
-import net.onrc.onos.api.batchoperation.BatchOperation;
import net.onrc.onos.api.flowmanager.ConflictDetectionPolicy;
import net.onrc.onos.api.flowmanager.IFlow;
@@ -63,7 +62,7 @@
* @param ops BatchOperations to be executed.
* @return true if succeeded, false otherwise.
*/
- boolean executeBatch(BatchOperation<Intent> ops);
+ boolean executeBatch(IntentBatchOperation ops);
/**
* Adds an IntentResolver associated with a given intent type.
diff --git a/src/main/java/net/onrc/onos/api/intent/Intent.java b/src/main/java/net/onrc/onos/api/intent/Intent.java
index 418346a..f8ec5c2 100644
--- a/src/main/java/net/onrc/onos/api/intent/Intent.java
+++ b/src/main/java/net/onrc/onos/api/intent/Intent.java
@@ -42,7 +42,6 @@
*
* @return ID for this Intent object.
*/
- @Override
public IntentId getId() {
return id;
}
diff --git a/src/main/java/net/onrc/onos/api/intent/IntentBatchOperation.java b/src/main/java/net/onrc/onos/api/intent/IntentBatchOperation.java
new file mode 100644
index 0000000..b5ca1aa
--- /dev/null
+++ b/src/main/java/net/onrc/onos/api/intent/IntentBatchOperation.java
@@ -0,0 +1,42 @@
+package net.onrc.onos.api.intent;
+
+import net.onrc.onos.api.batchoperation.BatchOperation;
+import net.onrc.onos.api.batchoperation.BatchOperationEntry;
+
+/**
+ * A list of intent operations.
+ */
+public class IntentBatchOperation extends
+ BatchOperation<BatchOperationEntry<IntentBatchOperation.Operator, ?>> {
+ /**
+ * The intent operators.
+ */
+ public enum Operator {
+ ADD,
+ REMOVE,
+ }
+
+ /**
+ * Adds an add-intent operation.
+ *
+ * @param intent the intent to be added
+ * @return the IntentBatchOperation object if succeeded, null otherwise
+ */
+ public IntentBatchOperation addAddIntentOperation(Intent intent) {
+ return (null == super.addOperation(
+ new BatchOperationEntry<Operator, Intent>(Operator.ADD, intent)))
+ ? null : this;
+ }
+
+ /**
+ * Adds a remove-intent operation.
+ *
+ * @param id the ID of intent to be removed
+ * @return the IntentBatchOperation object if succeeded, null otherwise
+ */
+ public IntentBatchOperation addRemoveIntentOperation(IntentId id) {
+ return (null == super.addOperation(
+ new BatchOperationEntry<Operator, IntentId>(Operator.REMOVE, id)))
+ ? null : this;
+ }
+}
diff --git a/src/main/java/net/onrc/onos/api/intent/IntentId.java b/src/main/java/net/onrc/onos/api/intent/IntentId.java
index a9a9c78..327f2cb 100644
--- a/src/main/java/net/onrc/onos/api/intent/IntentId.java
+++ b/src/main/java/net/onrc/onos/api/intent/IntentId.java
@@ -1,6 +1,6 @@
package net.onrc.onos.api.intent;
-import net.onrc.onos.api.batchoperation.BatchOperationTargetId;
+import net.onrc.onos.api.batchoperation.IBatchOperationTarget;
/**
* The class representing intent's ID.
@@ -9,7 +9,7 @@
* This class is immutable.
* </p>
*/
-public final class IntentId extends BatchOperationTargetId {
+public final class IntentId implements IBatchOperationTarget {
private final long id;
/**