blob: e87fcda0a31cf724e9728732d14ea86a16f1d450 [file] [log] [blame]
Brian O'Connordee2e6b2014-08-12 11:34:51 -07001package net.onrc.onos.core.matchaction;
2
3import net.onrc.onos.api.batchoperation.BatchOperation;
4
Ray Milkey18b44ac2014-08-22 08:29:47 -07005import java.util.HashSet;
6import java.util.Set;
7
Ray Milkeyc127a5a2014-08-20 11:22:12 -07008import static com.google.common.base.Preconditions.checkNotNull;
9
10/**
11 * The MatchActionOperations class holds a list of MatchActionOperationEntry
12 * objects to be executed together as one set.
Ray Milkeyc127a5a2014-08-20 11:22:12 -070013 */
Ray Milkey18b44ac2014-08-22 08:29:47 -070014public class MatchActionOperations
Brian O'Connordee2e6b2014-08-12 11:34:51 -070015 extends BatchOperation<MatchActionOperationEntry> {
Ray Milkeyc127a5a2014-08-20 11:22:12 -070016
17 private final MatchActionOperationsId id;
Ray Milkey18b44ac2014-08-22 08:29:47 -070018 private MatchActionOperationsState state;
19 private final Set<MatchActionOperationsId> dependencies;
20
Brian O'Connordee2e6b2014-08-12 11:34:51 -070021 /**
22 * The MatchAction operators.
23 */
24 public enum Operator {
25 ADD,
26 REMOVE,
27 }
28
Ray Milkeyc127a5a2014-08-20 11:22:12 -070029 /**
30 * Constructs a MatchActionOperations object from an id. Internal
31 * constructor called by a public factory method.
32 *
33 * @param newId match action operations identifier for this instance
34 */
Ray Milkey9ed4b962014-08-20 15:43:40 -070035 public MatchActionOperations(final MatchActionOperationsId newId) {
Ray Milkeyc127a5a2014-08-20 11:22:12 -070036 id = checkNotNull(newId);
Ray Milkey18b44ac2014-08-22 08:29:47 -070037 state = MatchActionOperationsState.INIT;
38 dependencies = new HashSet<>();
Ray Milkeyc127a5a2014-08-20 11:22:12 -070039 }
40
41 /**
Ray Milkeyc127a5a2014-08-20 11:22:12 -070042 * Gets the identifier for the Match Action Operations object.
43 *
44 * @return identifier for the Opertions object
45 */
46 public MatchActionOperationsId getOperationsId() {
47 return id;
48 }
49
Ray Milkey18b44ac2014-08-22 08:29:47 -070050 /**
51 * Gets the state of the Match Action Operations.
52 *
53 * @return state of the operations
54 */
55 public MatchActionOperationsState getState() {
56 return state;
57 }
58
59 /**
60 * Sets the state of the Match Action Operations.
61 *
62 * @param newState new state of the operations
63 */
64 public void setState(final MatchActionOperationsState newState) {
65 state = newState;
66 }
67
68 /**
69 * Gets the set of IDs of operations that are dependent on this
70 * operation.
71 *
72 * @return set of operations IDs of dependent operations
73 */
74 public Set<MatchActionOperationsId> getDependencies() {
75 return dependencies;
76 }
77
78 public void addDependency(MatchActionOperationsId dependentOperationId) {
79 dependencies.add(dependentOperationId);
80 }
81
Ray Milkeyc127a5a2014-08-20 11:22:12 -070082 @Override
83 public int hashCode() {
84 return id.hashCode();
85 }
86
87 @Override
88 public boolean equals(Object obj) {
89 if (obj instanceof MatchActionOperations) {
90 final MatchActionOperations other = (MatchActionOperations) obj;
91 return (id.equals(other.id));
92 }
93 return false;
94 }
Brian O'Connordee2e6b2014-08-12 11:34:51 -070095}