Pavlin Radoslavov | 4eaab99 | 2014-07-03 18:39:42 -0700 | [diff] [blame] | 1 | package net.onrc.onos.core.topology; |
| 2 | |
| 3 | import java.util.Collection; |
Pavlin Radoslavov | 4eaab99 | 2014-07-03 18:39:42 -0700 | [diff] [blame] | 4 | |
Pavlin Radoslavov | 4163364 | 2014-08-11 14:24:52 -0700 | [diff] [blame] | 5 | import static com.google.common.base.Preconditions.checkNotNull; |
| 6 | import com.google.common.collect.ImmutableList; |
Pavlin Radoslavov | 5cf1fe0 | 2014-07-03 22:52:25 -0700 | [diff] [blame] | 7 | import net.onrc.onos.core.topology.web.serializers.TopologyEventsSerializer; |
| 8 | import org.codehaus.jackson.map.annotate.JsonSerialize; |
| 9 | |
Pavlin Radoslavov | 4eaab99 | 2014-07-03 18:39:42 -0700 | [diff] [blame] | 10 | /** |
| 11 | * Class for encapsulating multiple topology events. |
Pavlin Radoslavov | 4163364 | 2014-08-11 14:24:52 -0700 | [diff] [blame] | 12 | * This class is immutable. |
Pavlin Radoslavov | 4eaab99 | 2014-07-03 18:39:42 -0700 | [diff] [blame] | 13 | * <p/> |
| 14 | * The recommended ordering rules for applying/processing the events are: |
| 15 | * <p/> |
| 16 | * (a) Process "removed" events before "added" events. |
| 17 | * <p/> |
| 18 | * (b) The processing order of the "removed" events should be: |
| 19 | * removedHostEvents, removedLinkEvents, removedPortEvents, |
Pavlin Radoslavov | cac157d | 2014-07-31 13:54:08 -0700 | [diff] [blame] | 20 | * removedSwitchEvents, removedMastershipEvents |
Pavlin Radoslavov | 4eaab99 | 2014-07-03 18:39:42 -0700 | [diff] [blame] | 21 | * <p/> |
| 22 | * (c) The processing order of the "added" events should be: |
Pavlin Radoslavov | cac157d | 2014-07-31 13:54:08 -0700 | [diff] [blame] | 23 | * addedMastershipEvents, addedSwitchEvents, addedPortEvents, addedLinkEvents, |
Pavlin Radoslavov | 4eaab99 | 2014-07-03 18:39:42 -0700 | [diff] [blame] | 24 | * addedHostEvents |
| 25 | * <p/> |
| 26 | * The above ordering guarantees that removing a port for example |
| 27 | * will be processed before the corresponding switch itself is |
| 28 | * removed. |
| 29 | * <p/> |
| 30 | * The above ordering guarantees that adding a port for example |
| 31 | * will be processed after the corresponding switch itself is added. |
| 32 | */ |
Pavlin Radoslavov | 5cf1fe0 | 2014-07-03 22:52:25 -0700 | [diff] [blame] | 33 | @JsonSerialize(using = TopologyEventsSerializer.class) |
Pavlin Radoslavov | 4eaab99 | 2014-07-03 18:39:42 -0700 | [diff] [blame] | 34 | public final class TopologyEvents { |
Pavlin Radoslavov | 4163364 | 2014-08-11 14:24:52 -0700 | [diff] [blame] | 35 | private final ImmutableList<MastershipEvent> addedMastershipEvents; |
| 36 | private final ImmutableList<MastershipEvent> removedMastershipEvents; |
| 37 | private final ImmutableList<SwitchEvent> addedSwitchEvents; |
| 38 | private final ImmutableList<SwitchEvent> removedSwitchEvents; |
| 39 | private final ImmutableList<PortEvent> addedPortEvents; |
| 40 | private final ImmutableList<PortEvent> removedPortEvents; |
| 41 | private final ImmutableList<LinkEvent> addedLinkEvents; |
| 42 | private final ImmutableList<LinkEvent> removedLinkEvents; |
| 43 | private final ImmutableList<HostEvent> addedHostEvents; |
| 44 | private final ImmutableList<HostEvent> removedHostEvents; |
Pavlin Radoslavov | 4eaab99 | 2014-07-03 18:39:42 -0700 | [diff] [blame] | 45 | |
| 46 | /** |
Pavlin Radoslavov | 054cd59 | 2014-08-07 20:57:16 -0700 | [diff] [blame] | 47 | * Constructor for added and removed events. |
Pavlin Radoslavov | 4eaab99 | 2014-07-03 18:39:42 -0700 | [diff] [blame] | 48 | * |
Pavlin Radoslavov | cac157d | 2014-07-31 13:54:08 -0700 | [diff] [blame] | 49 | * @param addedMastershipEvents the collection of added Mastership Events. |
Pavlin Radoslavov | 054cd59 | 2014-08-07 20:57:16 -0700 | [diff] [blame] | 50 | * @param removedMastershipEvents the collection of removed Mastership |
| 51 | * Events. |
Pavlin Radoslavov | 4eaab99 | 2014-07-03 18:39:42 -0700 | [diff] [blame] | 52 | * @param addedSwitchEvents the collection of added Switch Events. |
| 53 | * @param removedSwitchEvents the collection of removed Switch Events. |
| 54 | * @param addedPortEvents the collection of added Port Events. |
| 55 | * @param removedPortEvents the collection of removed Port Events. |
| 56 | * @param addedLinkEvents the collection of added Link Events. |
| 57 | * @param removedLinkEvents the collection of removed Link Events. |
| 58 | * @param addedHostEvents the collection of added Host Events. |
| 59 | * @param removedHostEvents the collection of removed Host Events. |
| 60 | */ |
Pavlin Radoslavov | cac157d | 2014-07-31 13:54:08 -0700 | [diff] [blame] | 61 | public TopologyEvents(Collection<MastershipEvent> addedMastershipEvents, |
| 62 | Collection<MastershipEvent> removedMastershipEvents, |
| 63 | Collection<SwitchEvent> addedSwitchEvents, |
Pavlin Radoslavov | 4eaab99 | 2014-07-03 18:39:42 -0700 | [diff] [blame] | 64 | Collection<SwitchEvent> removedSwitchEvents, |
| 65 | Collection<PortEvent> addedPortEvents, |
| 66 | Collection<PortEvent> removedPortEvents, |
| 67 | Collection<LinkEvent> addedLinkEvents, |
| 68 | Collection<LinkEvent> removedLinkEvents, |
Yuta HIGUCHI | bfc77f0 | 2014-07-14 22:50:25 -0700 | [diff] [blame] | 69 | Collection<HostEvent> addedHostEvents, |
| 70 | Collection<HostEvent> removedHostEvents) { |
Pavlin Radoslavov | 4163364 | 2014-08-11 14:24:52 -0700 | [diff] [blame] | 71 | this.addedMastershipEvents = ImmutableList.<MastershipEvent>copyOf( |
| 72 | checkNotNull(addedMastershipEvents)); |
| 73 | this.removedMastershipEvents = ImmutableList.<MastershipEvent>copyOf( |
| 74 | checkNotNull(removedMastershipEvents)); |
| 75 | this.addedSwitchEvents = ImmutableList.<SwitchEvent>copyOf( |
| 76 | checkNotNull(addedSwitchEvents)); |
| 77 | this.removedSwitchEvents = ImmutableList.<SwitchEvent>copyOf( |
| 78 | checkNotNull(removedSwitchEvents)); |
| 79 | this.addedPortEvents = ImmutableList.<PortEvent>copyOf( |
| 80 | checkNotNull(addedPortEvents)); |
| 81 | this.removedPortEvents = ImmutableList.<PortEvent>copyOf( |
| 82 | checkNotNull(removedPortEvents)); |
| 83 | this.addedLinkEvents = ImmutableList.<LinkEvent>copyOf( |
| 84 | checkNotNull(addedLinkEvents)); |
| 85 | this.removedLinkEvents = ImmutableList.<LinkEvent>copyOf( |
| 86 | checkNotNull(removedLinkEvents)); |
| 87 | this.addedHostEvents = ImmutableList.<HostEvent>copyOf( |
| 88 | checkNotNull(addedHostEvents)); |
| 89 | this.removedHostEvents = ImmutableList.<HostEvent>copyOf( |
| 90 | checkNotNull(removedHostEvents)); |
Pavlin Radoslavov | 4eaab99 | 2014-07-03 18:39:42 -0700 | [diff] [blame] | 91 | } |
| 92 | |
| 93 | /** |
Pavlin Radoslavov | 054cd59 | 2014-08-07 20:57:16 -0700 | [diff] [blame] | 94 | * Constructor for added events only. |
| 95 | * |
| 96 | * @param addedMastershipEvents the collection of added Mastership Events. |
| 97 | * @param addedSwitchEvents the collection of added Switch Events. |
| 98 | * @param addedPortEvents the collection of added Port Events. |
| 99 | * @param addedLinkEvents the collection of added Link Events. |
| 100 | * @param addedHostEvents the collection of added Host Events. |
| 101 | */ |
| 102 | public TopologyEvents(Collection<MastershipEvent> addedMastershipEvents, |
| 103 | Collection<SwitchEvent> addedSwitchEvents, |
| 104 | Collection<PortEvent> addedPortEvents, |
| 105 | Collection<LinkEvent> addedLinkEvents, |
| 106 | Collection<HostEvent> addedHostEvents) { |
Pavlin Radoslavov | 4163364 | 2014-08-11 14:24:52 -0700 | [diff] [blame] | 107 | this.addedMastershipEvents = ImmutableList.<MastershipEvent>copyOf( |
| 108 | checkNotNull(addedMastershipEvents)); |
| 109 | this.addedSwitchEvents = ImmutableList.<SwitchEvent>copyOf( |
| 110 | checkNotNull(addedSwitchEvents)); |
| 111 | this.addedPortEvents = ImmutableList.<PortEvent>copyOf( |
| 112 | checkNotNull(addedPortEvents)); |
| 113 | this.addedLinkEvents = ImmutableList.<LinkEvent>copyOf( |
| 114 | checkNotNull(addedLinkEvents)); |
| 115 | this.addedHostEvents = ImmutableList.<HostEvent>copyOf( |
| 116 | checkNotNull(addedHostEvents)); |
| 117 | |
| 118 | // Assign empty lists to the removed events |
| 119 | this.removedMastershipEvents = ImmutableList.<MastershipEvent>of(); |
| 120 | this.removedSwitchEvents = ImmutableList.<SwitchEvent>of(); |
| 121 | this.removedPortEvents = ImmutableList.<PortEvent>of(); |
| 122 | this.removedLinkEvents = ImmutableList.<LinkEvent>of(); |
| 123 | this.removedHostEvents = ImmutableList.<HostEvent>of(); |
Pavlin Radoslavov | 054cd59 | 2014-08-07 20:57:16 -0700 | [diff] [blame] | 124 | } |
| 125 | |
| 126 | /** |
Pavlin Radoslavov | 4163364 | 2014-08-11 14:24:52 -0700 | [diff] [blame] | 127 | * Gets the immutable collection of added Mastership Events. |
Pavlin Radoslavov | cac157d | 2014-07-31 13:54:08 -0700 | [diff] [blame] | 128 | * |
Pavlin Radoslavov | 4163364 | 2014-08-11 14:24:52 -0700 | [diff] [blame] | 129 | * @return the immutable collection of added Mastership Events. |
Pavlin Radoslavov | cac157d | 2014-07-31 13:54:08 -0700 | [diff] [blame] | 130 | */ |
| 131 | public Collection<MastershipEvent> getAddedMastershipEvents() { |
| 132 | return addedMastershipEvents; |
| 133 | } |
| 134 | |
| 135 | /** |
Pavlin Radoslavov | 4163364 | 2014-08-11 14:24:52 -0700 | [diff] [blame] | 136 | * Gets the immutable collection of removed Mastership Events. |
Pavlin Radoslavov | cac157d | 2014-07-31 13:54:08 -0700 | [diff] [blame] | 137 | * |
Pavlin Radoslavov | 4163364 | 2014-08-11 14:24:52 -0700 | [diff] [blame] | 138 | * @return the immutable collection of removed Mastership Events. |
Pavlin Radoslavov | cac157d | 2014-07-31 13:54:08 -0700 | [diff] [blame] | 139 | */ |
| 140 | public Collection<MastershipEvent> getRemovedMastershipEvents() { |
| 141 | return removedMastershipEvents; |
| 142 | } |
| 143 | |
| 144 | /** |
Pavlin Radoslavov | 4163364 | 2014-08-11 14:24:52 -0700 | [diff] [blame] | 145 | * Gets the immutable collection of added Switch Events. |
Pavlin Radoslavov | 4eaab99 | 2014-07-03 18:39:42 -0700 | [diff] [blame] | 146 | * |
Pavlin Radoslavov | 4163364 | 2014-08-11 14:24:52 -0700 | [diff] [blame] | 147 | * @return the immutable collection of added Switch Events. |
Pavlin Radoslavov | 4eaab99 | 2014-07-03 18:39:42 -0700 | [diff] [blame] | 148 | */ |
| 149 | public Collection<SwitchEvent> getAddedSwitchEvents() { |
| 150 | return addedSwitchEvents; |
| 151 | } |
| 152 | |
| 153 | /** |
Pavlin Radoslavov | 4163364 | 2014-08-11 14:24:52 -0700 | [diff] [blame] | 154 | * Gets the immutable collection of removed Switch Events. |
Pavlin Radoslavov | 4eaab99 | 2014-07-03 18:39:42 -0700 | [diff] [blame] | 155 | * |
Pavlin Radoslavov | 4163364 | 2014-08-11 14:24:52 -0700 | [diff] [blame] | 156 | * @return the immutable collection of removed Switch Events. |
Pavlin Radoslavov | 4eaab99 | 2014-07-03 18:39:42 -0700 | [diff] [blame] | 157 | */ |
| 158 | public Collection<SwitchEvent> getRemovedSwitchEvents() { |
| 159 | return removedSwitchEvents; |
| 160 | } |
| 161 | |
| 162 | /** |
Pavlin Radoslavov | 4163364 | 2014-08-11 14:24:52 -0700 | [diff] [blame] | 163 | * Gets the immutable collection of added Port Events. |
Pavlin Radoslavov | 4eaab99 | 2014-07-03 18:39:42 -0700 | [diff] [blame] | 164 | * |
Pavlin Radoslavov | 4163364 | 2014-08-11 14:24:52 -0700 | [diff] [blame] | 165 | * @return the immutable collection of added Port Events. |
Pavlin Radoslavov | 4eaab99 | 2014-07-03 18:39:42 -0700 | [diff] [blame] | 166 | */ |
| 167 | public Collection<PortEvent> getAddedPortEvents() { |
| 168 | return addedPortEvents; |
| 169 | } |
| 170 | |
| 171 | /** |
Pavlin Radoslavov | 4163364 | 2014-08-11 14:24:52 -0700 | [diff] [blame] | 172 | * Gets the immutable collection of removed Port Events. |
Pavlin Radoslavov | 4eaab99 | 2014-07-03 18:39:42 -0700 | [diff] [blame] | 173 | * |
Pavlin Radoslavov | 4163364 | 2014-08-11 14:24:52 -0700 | [diff] [blame] | 174 | * @return the immutable collection of removed Port Events. |
Pavlin Radoslavov | 4eaab99 | 2014-07-03 18:39:42 -0700 | [diff] [blame] | 175 | */ |
| 176 | public Collection<PortEvent> getRemovedPortEvents() { |
| 177 | return removedPortEvents; |
| 178 | } |
| 179 | |
| 180 | /** |
Pavlin Radoslavov | 4163364 | 2014-08-11 14:24:52 -0700 | [diff] [blame] | 181 | * Gets the immutable collection of added Link Events. |
Pavlin Radoslavov | 4eaab99 | 2014-07-03 18:39:42 -0700 | [diff] [blame] | 182 | * |
Pavlin Radoslavov | 4163364 | 2014-08-11 14:24:52 -0700 | [diff] [blame] | 183 | * @return the immutable collection of added Link Events. |
Pavlin Radoslavov | 4eaab99 | 2014-07-03 18:39:42 -0700 | [diff] [blame] | 184 | */ |
| 185 | public Collection<LinkEvent> getAddedLinkEvents() { |
| 186 | return addedLinkEvents; |
| 187 | } |
| 188 | |
| 189 | /** |
Pavlin Radoslavov | 4163364 | 2014-08-11 14:24:52 -0700 | [diff] [blame] | 190 | * Gets the immutable collection of removed Link Events. |
Pavlin Radoslavov | 4eaab99 | 2014-07-03 18:39:42 -0700 | [diff] [blame] | 191 | * |
Pavlin Radoslavov | 4163364 | 2014-08-11 14:24:52 -0700 | [diff] [blame] | 192 | * @return the immutable collection of removed Link Events. |
Pavlin Radoslavov | 4eaab99 | 2014-07-03 18:39:42 -0700 | [diff] [blame] | 193 | */ |
| 194 | public Collection<LinkEvent> getRemovedLinkEvents() { |
| 195 | return removedLinkEvents; |
| 196 | } |
| 197 | |
| 198 | /** |
Pavlin Radoslavov | 4163364 | 2014-08-11 14:24:52 -0700 | [diff] [blame] | 199 | * Gets the immutable collection of added Host Events. |
Pavlin Radoslavov | 4eaab99 | 2014-07-03 18:39:42 -0700 | [diff] [blame] | 200 | * |
Pavlin Radoslavov | 4163364 | 2014-08-11 14:24:52 -0700 | [diff] [blame] | 201 | * @return the immutable collection of added Host Events. |
Pavlin Radoslavov | 4eaab99 | 2014-07-03 18:39:42 -0700 | [diff] [blame] | 202 | */ |
Yuta HIGUCHI | bfc77f0 | 2014-07-14 22:50:25 -0700 | [diff] [blame] | 203 | public Collection<HostEvent> getAddedHostEvents() { |
Pavlin Radoslavov | 4eaab99 | 2014-07-03 18:39:42 -0700 | [diff] [blame] | 204 | return addedHostEvents; |
| 205 | } |
| 206 | |
| 207 | /** |
Pavlin Radoslavov | 4163364 | 2014-08-11 14:24:52 -0700 | [diff] [blame] | 208 | * Gets the immutable collection of removed Host Events. |
Pavlin Radoslavov | 4eaab99 | 2014-07-03 18:39:42 -0700 | [diff] [blame] | 209 | * |
Pavlin Radoslavov | 4163364 | 2014-08-11 14:24:52 -0700 | [diff] [blame] | 210 | * @return the immutable collection of removed Host Events. |
Pavlin Radoslavov | 4eaab99 | 2014-07-03 18:39:42 -0700 | [diff] [blame] | 211 | */ |
Yuta HIGUCHI | bfc77f0 | 2014-07-14 22:50:25 -0700 | [diff] [blame] | 212 | public Collection<HostEvent> getRemovedHostEvents() { |
Pavlin Radoslavov | 4eaab99 | 2014-07-03 18:39:42 -0700 | [diff] [blame] | 213 | return removedHostEvents; |
| 214 | } |
| 215 | } |