blob: bd7462d621a6acf7572730e133e877321ef7a5ff [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
tome4729872014-09-23 00:37:37 -070014 NodeId master;
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 */
23 MASTER_CHANGED
24 }
25
26 /**
27 * Creates an event of a given type and for the specified device, master,
28 * and the current time.
29 *
30 * @param type device event type
31 * @param device event device subject
32 * @param master master ID subject
33 */
Ayaka Koshibea7f044e2014-09-23 16:56:20 -070034 public MastershipEvent(Type type, DeviceId device, NodeId master) {
Ayaka Koshibe8b3270f2014-09-22 13:44:42 -070035 super(type, device);
36 this.master = master;
37 }
38
39 /**
40 * Creates an event of a given type and for the specified device, master,
41 * and time.
42 *
43 * @param type mastership event type
44 * @param device event device subject
45 * @param master master ID subject
46 * @param time occurrence time
47 */
Ayaka Koshibea7f044e2014-09-23 16:56:20 -070048 public MastershipEvent(Type type, DeviceId device, NodeId master, long time) {
Ayaka Koshibe8b3270f2014-09-22 13:44:42 -070049 super(type, device, time);
50 this.master = master;
51 }
52
53 /**
54 * Returns the current master's ID as a subject.
55 *
56 * @return master ID subject
57 */
tome4729872014-09-23 00:37:37 -070058 public NodeId master() {
Ayaka Koshibe8b3270f2014-09-22 13:44:42 -070059 return master;
60 }
61}