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