Brian O'Connor | dee2e6b | 2014-08-12 11:34:51 -0700 | [diff] [blame] | 1 | package net.onrc.onos.core.matchaction; |
| 2 | |
Brian O'Connor | 0efc906 | 2014-09-02 14:47:28 -0700 | [diff] [blame] | 3 | import static com.google.common.base.Preconditions.checkNotNull; |
Brian O'Connor | dee2e6b | 2014-08-12 11:34:51 -0700 | [diff] [blame] | 4 | |
Ray Milkey | 18b44ac | 2014-08-22 08:29:47 -0700 | [diff] [blame] | 5 | import java.util.HashSet; |
| 6 | import java.util.Set; |
| 7 | |
Brian O'Connor | 0efc906 | 2014-09-02 14:47:28 -0700 | [diff] [blame] | 8 | import net.onrc.onos.api.batchoperation.BatchOperation; |
Ray Milkey | c127a5a | 2014-08-20 11:22:12 -0700 | [diff] [blame] | 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 { |
Ray Milkey | a313cde | 2014-09-05 09:02:52 -0700 | [diff] [blame^] | 25 | /** Add a new match action. */ |
Brian O'Connor | dee2e6b | 2014-08-12 11:34:51 -0700 | [diff] [blame] | 26 | ADD, |
Ray Milkey | a313cde | 2014-09-05 09:02:52 -0700 | [diff] [blame^] | 27 | |
| 28 | /** Remove an existing match action. */ |
Brian O'Connor | dee2e6b | 2014-08-12 11:34:51 -0700 | [diff] [blame] | 29 | REMOVE, |
| 30 | } |
| 31 | |
Ray Milkey | c127a5a | 2014-08-20 11:22:12 -0700 | [diff] [blame] | 32 | /** |
| 33 | * Constructs a MatchActionOperations object from an id. Internal |
| 34 | * constructor called by a public factory method. |
| 35 | * |
| 36 | * @param newId match action operations identifier for this instance |
| 37 | */ |
Ray Milkey | 9ed4b96 | 2014-08-20 15:43:40 -0700 | [diff] [blame] | 38 | public MatchActionOperations(final MatchActionOperationsId newId) { |
Ray Milkey | c127a5a | 2014-08-20 11:22:12 -0700 | [diff] [blame] | 39 | id = checkNotNull(newId); |
Ray Milkey | 18b44ac | 2014-08-22 08:29:47 -0700 | [diff] [blame] | 40 | state = MatchActionOperationsState.INIT; |
| 41 | dependencies = new HashSet<>(); |
Ray Milkey | c127a5a | 2014-08-20 11:22:12 -0700 | [diff] [blame] | 42 | } |
| 43 | |
| 44 | /** |
Brian O'Connor | 0efc906 | 2014-09-02 14:47:28 -0700 | [diff] [blame] | 45 | * no-arg constructor for Kryo. |
| 46 | */ |
| 47 | protected MatchActionOperations() { |
| 48 | id = null; |
| 49 | dependencies = null; |
| 50 | } |
| 51 | |
| 52 | /** |
Ray Milkey | c127a5a | 2014-08-20 11:22:12 -0700 | [diff] [blame] | 53 | * Gets the identifier for the Match Action Operations object. |
| 54 | * |
| 55 | * @return identifier for the Opertions object |
| 56 | */ |
| 57 | public MatchActionOperationsId getOperationsId() { |
| 58 | return id; |
| 59 | } |
| 60 | |
Ray Milkey | 18b44ac | 2014-08-22 08:29:47 -0700 | [diff] [blame] | 61 | /** |
| 62 | * Gets the state of the Match Action Operations. |
| 63 | * |
| 64 | * @return state of the operations |
| 65 | */ |
| 66 | public MatchActionOperationsState getState() { |
| 67 | return state; |
| 68 | } |
| 69 | |
| 70 | /** |
| 71 | * Sets the state of the Match Action Operations. |
| 72 | * |
| 73 | * @param newState new state of the operations |
| 74 | */ |
| 75 | public void setState(final MatchActionOperationsState newState) { |
| 76 | state = newState; |
| 77 | } |
| 78 | |
| 79 | /** |
| 80 | * Gets the set of IDs of operations that are dependent on this |
| 81 | * operation. |
| 82 | * |
| 83 | * @return set of operations IDs of dependent operations |
| 84 | */ |
| 85 | public Set<MatchActionOperationsId> getDependencies() { |
| 86 | return dependencies; |
| 87 | } |
| 88 | |
Ray Milkey | a313cde | 2014-09-05 09:02:52 -0700 | [diff] [blame^] | 89 | /** |
| 90 | * Adds a dependency to this set of Operations. |
| 91 | * |
| 92 | * @param dependentOperationId Identifier of the Operations that must |
| 93 | * complete before this one can be installed |
| 94 | */ |
Ray Milkey | 18b44ac | 2014-08-22 08:29:47 -0700 | [diff] [blame] | 95 | public void addDependency(MatchActionOperationsId dependentOperationId) { |
| 96 | dependencies.add(dependentOperationId); |
| 97 | } |
| 98 | |
Ray Milkey | c127a5a | 2014-08-20 11:22:12 -0700 | [diff] [blame] | 99 | @Override |
| 100 | public int hashCode() { |
| 101 | return id.hashCode(); |
| 102 | } |
| 103 | |
| 104 | @Override |
| 105 | public boolean equals(Object obj) { |
| 106 | if (obj instanceof MatchActionOperations) { |
| 107 | final MatchActionOperations other = (MatchActionOperations) obj; |
| 108 | return (id.equals(other.id)); |
| 109 | } |
| 110 | return false; |
| 111 | } |
Brian O'Connor | dee2e6b | 2014-08-12 11:34:51 -0700 | [diff] [blame] | 112 | } |