blob: 7b8531c9f50fb0479d9c511a1bbcb294269f6855 [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 Koshibe67af1f42014-10-20 15:26:37 -070059 * Returns the NodeID of the node responsible for triggering the event.
Ayaka Koshibe8b3270f2014-09-22 13:44:42 -070060 *
Ayaka Koshibe67af1f42014-10-20 15:26:37 -070061 * @return node ID as a subject
Ayaka Koshibe8b3270f2014-09-22 13:44:42 -070062 */
Ayaka Koshibe67af1f42014-10-20 15:26:37 -070063 public NodeId node() {
64 return node;
Ayaka Koshibe8b3270f2014-09-22 13:44:42 -070065 }
66}