Brian O'Connor | dee2e6b | 2014-08-12 11:34:51 -0700 | [diff] [blame] | 1 | package net.onrc.onos.core.matchaction; |
| 2 | |
| 3 | import net.onrc.onos.api.batchoperation.BatchOperation; |
| 4 | |
Ray Milkey | 18b44ac | 2014-08-22 08:29:47 -0700 | [diff] [blame] | 5 | import java.util.HashSet; |
| 6 | import java.util.Set; |
| 7 | |
Ray Milkey | c127a5a | 2014-08-20 11:22:12 -0700 | [diff] [blame] | 8 | import 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 Milkey | c127a5a | 2014-08-20 11:22:12 -0700 | [diff] [blame] | 13 | */ |
Ray Milkey | 18b44ac | 2014-08-22 08:29:47 -0700 | [diff] [blame] | 14 | public class MatchActionOperations |
Brian O'Connor | dee2e6b | 2014-08-12 11:34:51 -0700 | [diff] [blame] | 15 | extends BatchOperation<MatchActionOperationEntry> { |
Ray Milkey | c127a5a | 2014-08-20 11:22:12 -0700 | [diff] [blame] | 16 | |
| 17 | private final MatchActionOperationsId id; |
Ray Milkey | 18b44ac | 2014-08-22 08:29:47 -0700 | [diff] [blame] | 18 | private MatchActionOperationsState state; |
| 19 | private final Set<MatchActionOperationsId> dependencies; |
| 20 | |
Brian O'Connor | dee2e6b | 2014-08-12 11:34:51 -0700 | [diff] [blame] | 21 | /** |
| 22 | * The MatchAction operators. |
| 23 | */ |
| 24 | public enum Operator { |
| 25 | ADD, |
| 26 | REMOVE, |
| 27 | } |
| 28 | |
Ray Milkey | c127a5a | 2014-08-20 11:22:12 -0700 | [diff] [blame] | 29 | /** |
| 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 Milkey | 9ed4b96 | 2014-08-20 15:43:40 -0700 | [diff] [blame] | 35 | public MatchActionOperations(final MatchActionOperationsId newId) { |
Ray Milkey | c127a5a | 2014-08-20 11:22:12 -0700 | [diff] [blame] | 36 | id = checkNotNull(newId); |
Ray Milkey | 18b44ac | 2014-08-22 08:29:47 -0700 | [diff] [blame] | 37 | state = MatchActionOperationsState.INIT; |
| 38 | dependencies = new HashSet<>(); |
Ray Milkey | c127a5a | 2014-08-20 11:22:12 -0700 | [diff] [blame] | 39 | } |
| 40 | |
| 41 | /** |
Ray Milkey | c127a5a | 2014-08-20 11:22:12 -0700 | [diff] [blame] | 42 | * 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 Milkey | 18b44ac | 2014-08-22 08:29:47 -0700 | [diff] [blame] | 50 | /** |
| 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 Milkey | c127a5a | 2014-08-20 11:22:12 -0700 | [diff] [blame] | 82 | @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'Connor | dee2e6b | 2014-08-12 11:34:51 -0700 | [diff] [blame] | 95 | } |