blob: 0f8c9a081e73b5d965dce9b911fbafc73fcb9e64 [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 {
Toshio Koide7db3ce92014-08-27 16:57:43 -070012 private final FlowBatchMap flowBatchMap;
Toshio Koide3c846312014-08-21 19:47:15 -070013 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 *
Toshio Koide7db3ce92014-08-27 16:57:43 -070021 * @param map the {@link FlowBatchMap} object which maintains the flow batch
Toshio Koide3c846312014-08-21 19:47:15 -070022 * operation
Toshio Koide7db3ce92014-08-27 16:57:43 -070023 * @param id the Id for this batch operation
Toshio Koide3c846312014-08-21 19:47:15 -070024 */
Toshio Koide7db3ce92014-08-27 16:57:43 -070025 public FlowBatchHandleImpl(FlowBatchMap map, FlowBatchId id) {
26 flowBatchMap = map;
Toshio Koide3c846312014-08-21 19:47:15 -070027 batchId = id;
28 }
29
30 @Override
31 public FlowBatchOperation getFlowBatchOperation() {
Toshio Koide7db3ce92014-08-27 16:57:43 -070032 FlowBatchOperation op = checkNotNull(flowBatchMap.get(batchId),
Toshio Koide3c846312014-08-21 19:47:15 -070033 "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() {
Toshio Koide7db3ce92014-08-27 16:57:43 -070041 return flowBatchMap.getState(batchId);
Toshio Koide3c846312014-08-21 19:47:15 -070042 }
43
44 @Override
45 public void purge() {
46 FlowBatchState state = getState();
47 if (state == FlowBatchState.COMPLETED || state == FlowBatchState.FAILED) {
Toshio Koide7db3ce92014-08-27 16:57:43 -070048 flowBatchMap.remove(batchId);
Toshio Koide3c846312014-08-21 19:47:15 -070049 }
50 }
51}