blob: 15811fbc2b36bddaa4a9c4122f36b50d2ff3464d [file] [log] [blame]
Ayaka Koshibe8b3270f2014-09-22 13:44:42 -07001package org.onlab.onos.cluster;
2
3import org.onlab.onos.event.AbstractEvent;
4import org.onlab.onos.net.DeviceId;
5
6/**
Ayaka Koshibe8d504a92014-09-22 17:07:36 -07007 * Describes a device mastership event.
Ayaka Koshibe8b3270f2014-09-22 13:44:42 -07008 */
9public class MastershipEvent extends AbstractEvent<MastershipEvent.Type, DeviceId> {
10
Ayaka Koshibea7f044e2014-09-23 16:56:20 -070011 //do we worry about explicitly setting slaves/equals? probably not,
12 //to keep it simple
tome4729872014-09-23 00:37:37 -070013 NodeId master;
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 */
22 MASTER_CHANGED
23 }
24
25 /**
26 * Creates an event of a given type and for the specified device, master,
27 * and the current time.
28 *
29 * @param type device event type
30 * @param device event device subject
31 * @param master master ID subject
32 */
Ayaka Koshibea7f044e2014-09-23 16:56:20 -070033 public MastershipEvent(Type type, DeviceId device, NodeId master) {
Ayaka Koshibe8b3270f2014-09-22 13:44:42 -070034 super(type, device);
35 this.master = master;
36 }
37
38 /**
39 * Creates an event of a given type and for the specified device, master,
40 * and time.
41 *
42 * @param type mastership event type
43 * @param device event device subject
44 * @param master master ID subject
45 * @param time occurrence time
46 */
Ayaka Koshibea7f044e2014-09-23 16:56:20 -070047 public MastershipEvent(Type type, DeviceId device, NodeId master, long time) {
Ayaka Koshibe8b3270f2014-09-22 13:44:42 -070048 super(type, device, time);
49 this.master = master;
50 }
51
52 /**
53 * Returns the current master's ID as a subject.
54 *
55 * @return master ID subject
56 */
tome4729872014-09-23 00:37:37 -070057 public NodeId master() {
Ayaka Koshibe8b3270f2014-09-22 13:44:42 -070058 return master;
59 }
60}