blob: 9f75fc4c8850ee71422c4abd2ae4f445e4e23ebf [file] [log] [blame]
Yuta HIGUCHI80912e62014-10-12 00:15:47 -07001package org.onlab.onos.mastership;
Ayaka Koshibe8b3270f2014-09-22 13:44:42 -07002
Yuta HIGUCHI80912e62014-10-12 00:15:47 -07003import org.onlab.onos.cluster.NodeId;
Ayaka Koshibe8b3270f2014-09-22 13:44:42 -07004import org.onlab.onos.event.AbstractEvent;
5import org.onlab.onos.net.DeviceId;
6
7/**
Ayaka Koshibe8d504a92014-09-22 17:07:36 -07008 * Describes a device mastership event.
Ayaka Koshibe8b3270f2014-09-22 13:44:42 -07009 */
10public class MastershipEvent extends AbstractEvent<MastershipEvent.Type, DeviceId> {
11
Ayaka Koshibea7f044e2014-09-23 16:56:20 -070012 //do we worry about explicitly setting slaves/equals? probably not,
13 //to keep it simple
Ayaka Koshibe67af1f42014-10-20 15:26:37 -070014 NodeId node;
Ayaka Koshibe8b3270f2014-09-22 13:44:42 -070015
16 /**
17 * Type of mastership events.
18 */
19 public enum Type {
20 /**
21 * Signifies that the master for a device has changed.
22 */
Ayaka Koshibe67af1f42014-10-20 15:26:37 -070023 MASTER_CHANGED,
24
25 /**
26 * Signifies that the list of backup nodes has changed.
27 */
28 BACKUPS_CHANGED
Ayaka Koshibe8b3270f2014-09-22 13:44:42 -070029 }
30
31 /**
32 * Creates an event of a given type and for the specified device, master,
33 * and the current time.
34 *
35 * @param type device event type
36 * @param device event device subject
Ayaka Koshibe67af1f42014-10-20 15:26:37 -070037 * @param node master ID subject
Ayaka Koshibe8b3270f2014-09-22 13:44:42 -070038 */
Ayaka Koshibe67af1f42014-10-20 15:26:37 -070039 public MastershipEvent(Type type, DeviceId device, NodeId node) {
Ayaka Koshibe8b3270f2014-09-22 13:44:42 -070040 super(type, device);
Ayaka Koshibe67af1f42014-10-20 15:26:37 -070041 this.node = node;
Ayaka Koshibe8b3270f2014-09-22 13:44:42 -070042 }
43
44 /**
45 * Creates an event of a given type and for the specified device, master,
46 * and time.
47 *
48 * @param type mastership event type
49 * @param device event device subject
50 * @param master master ID subject
51 * @param time occurrence time
52 */
Ayaka Koshibea7f044e2014-09-23 16:56:20 -070053 public MastershipEvent(Type type, DeviceId device, NodeId master, long time) {
Ayaka Koshibe8b3270f2014-09-22 13:44:42 -070054 super(type, device, time);
Ayaka Koshibe67af1f42014-10-20 15:26:37 -070055 this.node = master;
Ayaka Koshibe8b3270f2014-09-22 13:44:42 -070056 }
57
58 /**
Ayaka Koshibeabedb092014-10-20 17:01:31 -070059 * Returns the NodeID of the node associated with the event.
60 * For MASTER_CHANGED this is the newly elected master, and for
61 * BACKUPS_CHANGED, this is the node that was newly added, removed, or
62 * whose position was changed in the list.
Ayaka Koshibe8b3270f2014-09-22 13:44:42 -070063 *
Ayaka Koshibe67af1f42014-10-20 15:26:37 -070064 * @return node ID as a subject
Ayaka Koshibe8b3270f2014-09-22 13:44:42 -070065 */
Ayaka Koshibe67af1f42014-10-20 15:26:37 -070066 public NodeId node() {
67 return node;
Ayaka Koshibe8b3270f2014-09-22 13:44:42 -070068 }
69}