blob: 73cff284bdc614496ed6b9a644d48547d9efca47 [file] [log] [blame]
Brian O'Connordee2e6b2014-08-12 11:34:51 -07001package net.onrc.onos.core.matchaction;
2
Brian O'Connor0efc9062014-09-02 14:47:28 -07003import static com.google.common.base.Preconditions.checkNotNull;
Brian O'Connordee2e6b2014-08-12 11:34:51 -07004
Ray Milkey18b44ac2014-08-22 08:29:47 -07005import java.util.HashSet;
6import java.util.Set;
7
Brian O'Connor0efc9062014-09-02 14:47:28 -07008import net.onrc.onos.api.batchoperation.BatchOperation;
Ray Milkeyc127a5a2014-08-20 11:22:12 -07009
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 /**
Brian O'Connor0efc9062014-09-02 14:47:28 -070042 * no-arg constructor for Kryo.
43 */
44 protected MatchActionOperations() {
45 id = null;
46 dependencies = null;
47 }
48
49 /**
Ray Milkeyc127a5a2014-08-20 11:22:12 -070050 * Gets the identifier for the Match Action Operations object.
51 *
52 * @return identifier for the Opertions object
53 */
54 public MatchActionOperationsId getOperationsId() {
55 return id;
56 }
57
Ray Milkey18b44ac2014-08-22 08:29:47 -070058 /**
59 * Gets the state of the Match Action Operations.
60 *
61 * @return state of the operations
62 */
63 public MatchActionOperationsState getState() {
64 return state;
65 }
66
67 /**
68 * Sets the state of the Match Action Operations.
69 *
70 * @param newState new state of the operations
71 */
72 public void setState(final MatchActionOperationsState newState) {
73 state = newState;
74 }
75
76 /**
77 * Gets the set of IDs of operations that are dependent on this
78 * operation.
79 *
80 * @return set of operations IDs of dependent operations
81 */
82 public Set<MatchActionOperationsId> getDependencies() {
83 return dependencies;
84 }
85
86 public void addDependency(MatchActionOperationsId dependentOperationId) {
87 dependencies.add(dependentOperationId);
88 }
89
Ray Milkeyc127a5a2014-08-20 11:22:12 -070090 @Override
91 public int hashCode() {
92 return id.hashCode();
93 }
94
95 @Override
96 public boolean equals(Object obj) {
97 if (obj instanceof MatchActionOperations) {
98 final MatchActionOperations other = (MatchActionOperations) obj;
99 return (id.equals(other.id));
100 }
101 return false;
102 }
Brian O'Connordee2e6b2014-08-12 11:34:51 -0700103}