Ayaka Koshibe | 8b3270f | 2014-09-22 13:44:42 -0700 | [diff] [blame] | 1 | package org.onlab.onos.cluster; |
| 2 | |
| 3 | import org.onlab.onos.event.AbstractEvent; |
| 4 | import org.onlab.onos.net.DeviceId; |
| 5 | |
| 6 | /** |
Ayaka Koshibe | 8d504a9 | 2014-09-22 17:07:36 -0700 | [diff] [blame] | 7 | * Describes a device mastership event. |
Ayaka Koshibe | 8b3270f | 2014-09-22 13:44:42 -0700 | [diff] [blame] | 8 | */ |
| 9 | public class MastershipEvent extends AbstractEvent<MastershipEvent.Type, DeviceId> { |
| 10 | |
Ayaka Koshibe | a7f044e | 2014-09-23 16:56:20 -0700 | [diff] [blame] | 11 | //do we worry about explicitly setting slaves/equals? probably not, |
| 12 | //to keep it simple |
tom | e472987 | 2014-09-23 00:37:37 -0700 | [diff] [blame] | 13 | NodeId master; |
Ayaka Koshibe | 8b3270f | 2014-09-22 13:44:42 -0700 | [diff] [blame] | 14 | |
| 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 Koshibe | a7f044e | 2014-09-23 16:56:20 -0700 | [diff] [blame] | 33 | public MastershipEvent(Type type, DeviceId device, NodeId master) { |
Ayaka Koshibe | 8b3270f | 2014-09-22 13:44:42 -0700 | [diff] [blame] | 34 | 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 Koshibe | a7f044e | 2014-09-23 16:56:20 -0700 | [diff] [blame] | 47 | public MastershipEvent(Type type, DeviceId device, NodeId master, long time) { |
Ayaka Koshibe | 8b3270f | 2014-09-22 13:44:42 -0700 | [diff] [blame] | 48 | 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 | */ |
tom | e472987 | 2014-09-23 00:37:37 -0700 | [diff] [blame] | 57 | public NodeId master() { |
Ayaka Koshibe | 8b3270f | 2014-09-22 13:44:42 -0700 | [diff] [blame] | 58 | return master; |
| 59 | } |
| 60 | } |