blob: dcb2d95fa35c74f8a8ccd680d327d539ad2de761 [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 Koshibefc981cf2014-10-21 12:44:17 -07004import org.onlab.onos.cluster.RoleInfo;
Ayaka Koshibe8b3270f2014-09-22 13:44:42 -07005import org.onlab.onos.event.AbstractEvent;
6import org.onlab.onos.net.DeviceId;
7
8/**
Ayaka Koshibe8d504a92014-09-22 17:07:36 -07009 * Describes a device mastership event.
Ayaka Koshibe8b3270f2014-09-22 13:44:42 -070010 */
11public class MastershipEvent extends AbstractEvent<MastershipEvent.Type, DeviceId> {
12
Ayaka Koshibefc981cf2014-10-21 12:44:17 -070013 //Contains master and standby information.
14 RoleInfo roleInfo;
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 /**
Ayaka Koshibefc981cf2014-10-21 12:44:17 -070032 * Creates an event of a given type and for the specified device,
33 * role information, and the current time.
Ayaka Koshibe8b3270f2014-09-22 13:44:42 -070034 *
35 * @param type device event type
36 * @param device event device subject
Ayaka Koshibefc981cf2014-10-21 12:44:17 -070037 * @param info mastership role information subject
Ayaka Koshibe8b3270f2014-09-22 13:44:42 -070038 */
Ayaka Koshibefc981cf2014-10-21 12:44:17 -070039 public MastershipEvent(Type type, DeviceId device, RoleInfo info) {
Ayaka Koshibe8b3270f2014-09-22 13:44:42 -070040 super(type, device);
Ayaka Koshibefc981cf2014-10-21 12:44:17 -070041 this.roleInfo = info;
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 Koshibefc981cf2014-10-21 12:44:17 -070053 public MastershipEvent(Type type, DeviceId device, RoleInfo info, long time) {
Ayaka Koshibe8b3270f2014-09-22 13:44:42 -070054 super(type, device, time);
Ayaka Koshibefc981cf2014-10-21 12:44:17 -070055 this.roleInfo = info;
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 Koshibefc981cf2014-10-21 12:44:17 -070066 //XXX to-be removed - or keep for convenience?
Ayaka Koshibe67af1f42014-10-20 15:26:37 -070067 public NodeId node() {
Ayaka Koshibefc981cf2014-10-21 12:44:17 -070068 return roleInfo.master();
69 }
70
71 /**
72 * Returns the current role state for the subject.
73 *
74 * @return RoleInfo associated with Device ID subject
75 */
76 public RoleInfo roleInfo() {
77 return roleInfo;
Ayaka Koshibe8b3270f2014-09-22 13:44:42 -070078 }
79}