blob: b69a409fd1142f57777e7c9d0049e6825d0ed1e4 [file] [log] [blame]
Pavlin Radoslavov4eaab992014-07-03 18:39:42 -07001package net.onrc.onos.core.topology;
2
3import java.util.Collection;
Pavlin Radoslavov4eaab992014-07-03 18:39:42 -07004
Pavlin Radoslavov41633642014-08-11 14:24:52 -07005import static com.google.common.base.Preconditions.checkNotNull;
6import com.google.common.collect.ImmutableList;
Pavlin Radoslavov5cf1fe02014-07-03 22:52:25 -07007import net.onrc.onos.core.topology.web.serializers.TopologyEventsSerializer;
8import org.codehaus.jackson.map.annotate.JsonSerialize;
9
Pavlin Radoslavov4eaab992014-07-03 18:39:42 -070010/**
11 * Class for encapsulating multiple topology events.
Pavlin Radoslavov41633642014-08-11 14:24:52 -070012 * This class is immutable.
Pavlin Radoslavov4eaab992014-07-03 18:39:42 -070013 * <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 Radoslavovcac157d2014-07-31 13:54:08 -070020 * removedSwitchEvents, removedMastershipEvents
Pavlin Radoslavov4eaab992014-07-03 18:39:42 -070021 * <p/>
22 * (c) The processing order of the "added" events should be:
Pavlin Radoslavovcac157d2014-07-31 13:54:08 -070023 * addedMastershipEvents, addedSwitchEvents, addedPortEvents, addedLinkEvents,
Pavlin Radoslavov4eaab992014-07-03 18:39:42 -070024 * 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 Radoslavov5cf1fe02014-07-03 22:52:25 -070033@JsonSerialize(using = TopologyEventsSerializer.class)
Pavlin Radoslavov4eaab992014-07-03 18:39:42 -070034public final class TopologyEvents {
Pavlin Radoslavov41633642014-08-11 14:24:52 -070035 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 Radoslavov4eaab992014-07-03 18:39:42 -070045
46 /**
Pavlin Radoslavov054cd592014-08-07 20:57:16 -070047 * Constructor for added and removed events.
Pavlin Radoslavov4eaab992014-07-03 18:39:42 -070048 *
Pavlin Radoslavovcac157d2014-07-31 13:54:08 -070049 * @param addedMastershipEvents the collection of added Mastership Events.
Pavlin Radoslavov054cd592014-08-07 20:57:16 -070050 * @param removedMastershipEvents the collection of removed Mastership
51 * Events.
Pavlin Radoslavov4eaab992014-07-03 18:39:42 -070052 * @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 Radoslavovcac157d2014-07-31 13:54:08 -070061 public TopologyEvents(Collection<MastershipEvent> addedMastershipEvents,
62 Collection<MastershipEvent> removedMastershipEvents,
63 Collection<SwitchEvent> addedSwitchEvents,
Pavlin Radoslavov4eaab992014-07-03 18:39:42 -070064 Collection<SwitchEvent> removedSwitchEvents,
65 Collection<PortEvent> addedPortEvents,
66 Collection<PortEvent> removedPortEvents,
67 Collection<LinkEvent> addedLinkEvents,
68 Collection<LinkEvent> removedLinkEvents,
Yuta HIGUCHIbfc77f02014-07-14 22:50:25 -070069 Collection<HostEvent> addedHostEvents,
70 Collection<HostEvent> removedHostEvents) {
Pavlin Radoslavov41633642014-08-11 14:24:52 -070071 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 Radoslavov4eaab992014-07-03 18:39:42 -070091 }
92
93 /**
Pavlin Radoslavov054cd592014-08-07 20:57:16 -070094 * 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 Radoslavov41633642014-08-11 14:24:52 -0700107 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 Radoslavov054cd592014-08-07 20:57:16 -0700124 }
125
126 /**
Pavlin Radoslavov41633642014-08-11 14:24:52 -0700127 * Gets the immutable collection of added Mastership Events.
Pavlin Radoslavovcac157d2014-07-31 13:54:08 -0700128 *
Pavlin Radoslavov41633642014-08-11 14:24:52 -0700129 * @return the immutable collection of added Mastership Events.
Pavlin Radoslavovcac157d2014-07-31 13:54:08 -0700130 */
131 public Collection<MastershipEvent> getAddedMastershipEvents() {
132 return addedMastershipEvents;
133 }
134
135 /**
Pavlin Radoslavov41633642014-08-11 14:24:52 -0700136 * Gets the immutable collection of removed Mastership Events.
Pavlin Radoslavovcac157d2014-07-31 13:54:08 -0700137 *
Pavlin Radoslavov41633642014-08-11 14:24:52 -0700138 * @return the immutable collection of removed Mastership Events.
Pavlin Radoslavovcac157d2014-07-31 13:54:08 -0700139 */
140 public Collection<MastershipEvent> getRemovedMastershipEvents() {
141 return removedMastershipEvents;
142 }
143
144 /**
Pavlin Radoslavov41633642014-08-11 14:24:52 -0700145 * Gets the immutable collection of added Switch Events.
Pavlin Radoslavov4eaab992014-07-03 18:39:42 -0700146 *
Pavlin Radoslavov41633642014-08-11 14:24:52 -0700147 * @return the immutable collection of added Switch Events.
Pavlin Radoslavov4eaab992014-07-03 18:39:42 -0700148 */
149 public Collection<SwitchEvent> getAddedSwitchEvents() {
150 return addedSwitchEvents;
151 }
152
153 /**
Pavlin Radoslavov41633642014-08-11 14:24:52 -0700154 * Gets the immutable collection of removed Switch Events.
Pavlin Radoslavov4eaab992014-07-03 18:39:42 -0700155 *
Pavlin Radoslavov41633642014-08-11 14:24:52 -0700156 * @return the immutable collection of removed Switch Events.
Pavlin Radoslavov4eaab992014-07-03 18:39:42 -0700157 */
158 public Collection<SwitchEvent> getRemovedSwitchEvents() {
159 return removedSwitchEvents;
160 }
161
162 /**
Pavlin Radoslavov41633642014-08-11 14:24:52 -0700163 * Gets the immutable collection of added Port Events.
Pavlin Radoslavov4eaab992014-07-03 18:39:42 -0700164 *
Pavlin Radoslavov41633642014-08-11 14:24:52 -0700165 * @return the immutable collection of added Port Events.
Pavlin Radoslavov4eaab992014-07-03 18:39:42 -0700166 */
167 public Collection<PortEvent> getAddedPortEvents() {
168 return addedPortEvents;
169 }
170
171 /**
Pavlin Radoslavov41633642014-08-11 14:24:52 -0700172 * Gets the immutable collection of removed Port Events.
Pavlin Radoslavov4eaab992014-07-03 18:39:42 -0700173 *
Pavlin Radoslavov41633642014-08-11 14:24:52 -0700174 * @return the immutable collection of removed Port Events.
Pavlin Radoslavov4eaab992014-07-03 18:39:42 -0700175 */
176 public Collection<PortEvent> getRemovedPortEvents() {
177 return removedPortEvents;
178 }
179
180 /**
Pavlin Radoslavov41633642014-08-11 14:24:52 -0700181 * Gets the immutable collection of added Link Events.
Pavlin Radoslavov4eaab992014-07-03 18:39:42 -0700182 *
Pavlin Radoslavov41633642014-08-11 14:24:52 -0700183 * @return the immutable collection of added Link Events.
Pavlin Radoslavov4eaab992014-07-03 18:39:42 -0700184 */
185 public Collection<LinkEvent> getAddedLinkEvents() {
186 return addedLinkEvents;
187 }
188
189 /**
Pavlin Radoslavov41633642014-08-11 14:24:52 -0700190 * Gets the immutable collection of removed Link Events.
Pavlin Radoslavov4eaab992014-07-03 18:39:42 -0700191 *
Pavlin Radoslavov41633642014-08-11 14:24:52 -0700192 * @return the immutable collection of removed Link Events.
Pavlin Radoslavov4eaab992014-07-03 18:39:42 -0700193 */
194 public Collection<LinkEvent> getRemovedLinkEvents() {
195 return removedLinkEvents;
196 }
197
198 /**
Pavlin Radoslavov41633642014-08-11 14:24:52 -0700199 * Gets the immutable collection of added Host Events.
Pavlin Radoslavov4eaab992014-07-03 18:39:42 -0700200 *
Pavlin Radoslavov41633642014-08-11 14:24:52 -0700201 * @return the immutable collection of added Host Events.
Pavlin Radoslavov4eaab992014-07-03 18:39:42 -0700202 */
Yuta HIGUCHIbfc77f02014-07-14 22:50:25 -0700203 public Collection<HostEvent> getAddedHostEvents() {
Pavlin Radoslavov4eaab992014-07-03 18:39:42 -0700204 return addedHostEvents;
205 }
206
207 /**
Pavlin Radoslavov41633642014-08-11 14:24:52 -0700208 * Gets the immutable collection of removed Host Events.
Pavlin Radoslavov4eaab992014-07-03 18:39:42 -0700209 *
Pavlin Radoslavov41633642014-08-11 14:24:52 -0700210 * @return the immutable collection of removed Host Events.
Pavlin Radoslavov4eaab992014-07-03 18:39:42 -0700211 */
Yuta HIGUCHIbfc77f02014-07-14 22:50:25 -0700212 public Collection<HostEvent> getRemovedHostEvents() {
Pavlin Radoslavov4eaab992014-07-03 18:39:42 -0700213 return removedHostEvents;
214 }
215}