blob: fdbb645c1c2a65a5cf19f75b280dcfe896f5eb0a [file] [log] [blame]
Yuta HIGUCHI80912e62014-10-12 00:15:47 -07001package org.onlab.onos.mastership;
Ayaka Koshibe8b3270f2014-09-22 13:44:42 -07002
Ayaka Koshibefc981cf2014-10-21 12:44:17 -07003import org.onlab.onos.cluster.RoleInfo;
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 Koshibefc981cf2014-10-21 12:44:17 -070012 //Contains master and standby information.
13 RoleInfo roleInfo;
Ayaka Koshibe8b3270f2014-09-22 13:44:42 -070014
15 /**
16 * Type of mastership events.
17 */
18 public enum Type {
19 /**
20 * Signifies that the master for a device has changed.
21 */
Ayaka Koshibe67af1f42014-10-20 15:26:37 -070022 MASTER_CHANGED,
23
24 /**
25 * Signifies that the list of backup nodes has changed.
26 */
27 BACKUPS_CHANGED
Ayaka Koshibe8b3270f2014-09-22 13:44:42 -070028 }
29
30 /**
Ayaka Koshibefc981cf2014-10-21 12:44:17 -070031 * Creates an event of a given type and for the specified device,
32 * role information, and the current time.
Ayaka Koshibe8b3270f2014-09-22 13:44:42 -070033 *
34 * @param type device event type
35 * @param device event device subject
Ayaka Koshibefc981cf2014-10-21 12:44:17 -070036 * @param info mastership role information subject
Ayaka Koshibe8b3270f2014-09-22 13:44:42 -070037 */
Ayaka Koshibefc981cf2014-10-21 12:44:17 -070038 public MastershipEvent(Type type, DeviceId device, RoleInfo info) {
Ayaka Koshibe8b3270f2014-09-22 13:44:42 -070039 super(type, device);
Ayaka Koshibefc981cf2014-10-21 12:44:17 -070040 this.roleInfo = info;
Ayaka Koshibe8b3270f2014-09-22 13:44:42 -070041 }
42
43 /**
44 * Creates an event of a given type and for the specified device, master,
45 * and time.
46 *
47 * @param type mastership event type
48 * @param device event device subject
49 * @param master master ID subject
50 * @param time occurrence time
51 */
Ayaka Koshibefc981cf2014-10-21 12:44:17 -070052 public MastershipEvent(Type type, DeviceId device, RoleInfo info, long time) {
Ayaka Koshibe8b3270f2014-09-22 13:44:42 -070053 super(type, device, time);
Ayaka Koshibefc981cf2014-10-21 12:44:17 -070054 this.roleInfo = info;
Ayaka Koshibe8b3270f2014-09-22 13:44:42 -070055 }
56
57 /**
Ayaka Koshibefc981cf2014-10-21 12:44:17 -070058 * Returns the current role state for the subject.
59 *
60 * @return RoleInfo associated with Device ID subject
61 */
62 public RoleInfo roleInfo() {
63 return roleInfo;
Ayaka Koshibe8b3270f2014-09-22 13:44:42 -070064 }
65}