Change FlowBatchHandle to be interface class.
- Users can access to the shared flow batch operation map
using the FlowBatchHandle.
- FlowBatchHandle is an interface and the instance of it
can be obtained from APIs defined by FlowManagerService.
- The implementation of the map can be accessed only from
the implementation of the FlowBatchHandle.
- This task is a part of ONOS-1692 and ONOS-1842.
Change-Id: I651a2886d166765ca5aae6abcc2b844153ffb2bc
diff --git a/src/main/java/net/onrc/onos/core/flowmanager/FlowBatchHandleImpl.java b/src/main/java/net/onrc/onos/core/flowmanager/FlowBatchHandleImpl.java
new file mode 100644
index 0000000..61a450f
--- /dev/null
+++ b/src/main/java/net/onrc/onos/core/flowmanager/FlowBatchHandleImpl.java
@@ -0,0 +1,51 @@
+package net.onrc.onos.core.flowmanager;
+
+
+import static com.google.common.base.Preconditions.*;
+
+import net.onrc.onos.api.flowmanager.FlowBatchHandle;
+import net.onrc.onos.api.flowmanager.FlowBatchId;
+import net.onrc.onos.api.flowmanager.FlowBatchOperation;
+import net.onrc.onos.api.flowmanager.FlowBatchState;
+
+public class FlowBatchHandleImpl implements FlowBatchHandle {
+ private final FlowOperationMap flowOperationMap;
+ private final FlowBatchId batchId;
+
+ /**
+ * Creates a handle using batch operation ID.
+ * <p>
+ * The ID is automatically generated and assigned by FlowManager, and used
+ * as an internal key for the flow batch operation map.
+ *
+ * @param opMap the FlowOperationMap object which maintains the flow batch
+ * operation
+ * @param id the batch operation ID
+ */
+ public FlowBatchHandleImpl(FlowOperationMap opMap, FlowBatchId id) {
+ flowOperationMap = opMap;
+ batchId = id;
+ }
+
+ @Override
+ public FlowBatchOperation getFlowBatchOperation() {
+ FlowBatchOperation op = checkNotNull(flowOperationMap.getBatchOperation(batchId),
+ "The requested flow batch operation does not exist in the map.");
+
+ // TODO: should be an instance of immutable batch operation class.
+ return new FlowBatchOperation(op.getOperations());
+ }
+
+ @Override
+ public FlowBatchState getState() {
+ return flowOperationMap.getState(batchId);
+ }
+
+ @Override
+ public void purge() {
+ FlowBatchState state = getState();
+ if (state == FlowBatchState.COMPLETED || state == FlowBatchState.FAILED) {
+ flowOperationMap.removeBatchOperation(batchId);
+ }
+ }
+}