blob: e99f9aea1cb5fcaa8a0f43c9edfb56b8c668991d [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
Yuta HIGUCHIfd5cdf12014-10-26 13:28:48 -07007import com.google.common.base.MoreObjects;
8
Ayaka Koshibe8b3270f2014-09-22 13:44:42 -07009/**
Ayaka Koshibe8d504a92014-09-22 17:07:36 -070010 * Describes a device mastership event.
Ayaka Koshibe8b3270f2014-09-22 13:44:42 -070011 */
12public class MastershipEvent extends AbstractEvent<MastershipEvent.Type, DeviceId> {
13
Ayaka Koshibefc981cf2014-10-21 12:44:17 -070014 //Contains master and standby information.
15 RoleInfo roleInfo;
Ayaka Koshibe8b3270f2014-09-22 13:44:42 -070016
17 /**
18 * Type of mastership events.
19 */
20 public enum Type {
21 /**
22 * Signifies that the master for a device has changed.
23 */
Ayaka Koshibe67af1f42014-10-20 15:26:37 -070024 MASTER_CHANGED,
25
26 /**
27 * Signifies that the list of backup nodes has changed.
28 */
29 BACKUPS_CHANGED
Ayaka Koshibe8b3270f2014-09-22 13:44:42 -070030 }
31
32 /**
Ayaka Koshibefc981cf2014-10-21 12:44:17 -070033 * Creates an event of a given type and for the specified device,
34 * role information, and the current time.
Ayaka Koshibe8b3270f2014-09-22 13:44:42 -070035 *
36 * @param type device event type
37 * @param device event device subject
Ayaka Koshibefc981cf2014-10-21 12:44:17 -070038 * @param info mastership role information subject
Ayaka Koshibe8b3270f2014-09-22 13:44:42 -070039 */
Ayaka Koshibefc981cf2014-10-21 12:44:17 -070040 public MastershipEvent(Type type, DeviceId device, RoleInfo info) {
Ayaka Koshibe8b3270f2014-09-22 13:44:42 -070041 super(type, device);
Ayaka Koshibefc981cf2014-10-21 12:44:17 -070042 this.roleInfo = info;
Ayaka Koshibe8b3270f2014-09-22 13:44:42 -070043 }
44
45 /**
46 * Creates an event of a given type and for the specified device, master,
47 * and time.
48 *
49 * @param type mastership event type
50 * @param device event device subject
51 * @param master master ID subject
52 * @param time occurrence time
53 */
Ayaka Koshibefc981cf2014-10-21 12:44:17 -070054 public MastershipEvent(Type type, DeviceId device, RoleInfo info, long time) {
Ayaka Koshibe8b3270f2014-09-22 13:44:42 -070055 super(type, device, time);
Ayaka Koshibefc981cf2014-10-21 12:44:17 -070056 this.roleInfo = info;
Ayaka Koshibe8b3270f2014-09-22 13:44:42 -070057 }
58
59 /**
Ayaka Koshibefc981cf2014-10-21 12:44:17 -070060 * Returns the current role state for the subject.
61 *
62 * @return RoleInfo associated with Device ID subject
63 */
64 public RoleInfo roleInfo() {
65 return roleInfo;
Ayaka Koshibe8b3270f2014-09-22 13:44:42 -070066 }
Yuta HIGUCHIfd5cdf12014-10-26 13:28:48 -070067
68 @Override
69 public String toString() {
70 return MoreObjects.toStringHelper(getClass())
71 .add("time", time())
72 .add("type", type())
73 .add("subject", subject())
74 .add("roleInfo", roleInfo)
75 .toString();
76 }
Ayaka Koshibe8b3270f2014-09-22 13:44:42 -070077}