blob: 61a450f954b259e56c251131449e0d67b7c12752 [file] [log] [blame]
Toshio Koide3c846312014-08-21 19:47:15 -07001package net.onrc.onos.core.flowmanager;
2
3
4import static com.google.common.base.Preconditions.*;
5
6import net.onrc.onos.api.flowmanager.FlowBatchHandle;
7import net.onrc.onos.api.flowmanager.FlowBatchId;
8import net.onrc.onos.api.flowmanager.FlowBatchOperation;
9import net.onrc.onos.api.flowmanager.FlowBatchState;
10
11public class FlowBatchHandleImpl implements FlowBatchHandle {
12 private final FlowOperationMap flowOperationMap;
13 private final FlowBatchId batchId;
14
15 /**
16 * Creates a handle using batch operation ID.
17 * <p>
18 * The ID is automatically generated and assigned by FlowManager, and used
19 * as an internal key for the flow batch operation map.
20 *
21 * @param opMap the FlowOperationMap object which maintains the flow batch
22 * operation
23 * @param id the batch operation ID
24 */
25 public FlowBatchHandleImpl(FlowOperationMap opMap, FlowBatchId id) {
26 flowOperationMap = opMap;
27 batchId = id;
28 }
29
30 @Override
31 public FlowBatchOperation getFlowBatchOperation() {
32 FlowBatchOperation op = checkNotNull(flowOperationMap.getBatchOperation(batchId),
33 "The requested flow batch operation does not exist in the map.");
34
35 // TODO: should be an instance of immutable batch operation class.
36 return new FlowBatchOperation(op.getOperations());
37 }
38
39 @Override
40 public FlowBatchState getState() {
41 return flowOperationMap.getState(batchId);
42 }
43
44 @Override
45 public void purge() {
46 FlowBatchState state = getState();
47 if (state == FlowBatchState.COMPLETED || state == FlowBatchState.FAILED) {
48 flowOperationMap.removeBatchOperation(batchId);
49 }
50 }
51}