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 |
Ayaka Koshibe | 67af1f4 | 2014-10-20 15:26:37 -0700 | [diff] [blame] | 14 | NodeId node; |
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 | */ |
Ayaka Koshibe | 67af1f4 | 2014-10-20 15:26:37 -0700 | [diff] [blame] | 23 | MASTER_CHANGED, |
| 24 | |
| 25 | /** |
| 26 | * Signifies that the list of backup nodes has changed. |
| 27 | */ |
| 28 | BACKUPS_CHANGED |
Ayaka Koshibe | 8b3270f | 2014-09-22 13:44:42 -0700 | [diff] [blame] | 29 | } |
| 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 Koshibe | 67af1f4 | 2014-10-20 15:26:37 -0700 | [diff] [blame] | 37 | * @param node master ID subject |
Ayaka Koshibe | 8b3270f | 2014-09-22 13:44:42 -0700 | [diff] [blame] | 38 | */ |
Ayaka Koshibe | 67af1f4 | 2014-10-20 15:26:37 -0700 | [diff] [blame] | 39 | public MastershipEvent(Type type, DeviceId device, NodeId node) { |
Ayaka Koshibe | 8b3270f | 2014-09-22 13:44:42 -0700 | [diff] [blame] | 40 | super(type, device); |
Ayaka Koshibe | 67af1f4 | 2014-10-20 15:26:37 -0700 | [diff] [blame] | 41 | this.node = node; |
Ayaka Koshibe | 8b3270f | 2014-09-22 13:44:42 -0700 | [diff] [blame] | 42 | } |
| 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 Koshibe | a7f044e | 2014-09-23 16:56:20 -0700 | [diff] [blame] | 53 | public MastershipEvent(Type type, DeviceId device, NodeId master, long time) { |
Ayaka Koshibe | 8b3270f | 2014-09-22 13:44:42 -0700 | [diff] [blame] | 54 | super(type, device, time); |
Ayaka Koshibe | 67af1f4 | 2014-10-20 15:26:37 -0700 | [diff] [blame] | 55 | this.node = master; |
Ayaka Koshibe | 8b3270f | 2014-09-22 13:44:42 -0700 | [diff] [blame] | 56 | } |
| 57 | |
| 58 | /** |
Ayaka Koshibe | abedb09 | 2014-10-20 17:01:31 -0700 | [diff] [blame] | 59 | * Returns the NodeID of the node associated with the event. |
| 60 | * For MASTER_CHANGED this is the newly elected master, and for |
| 61 | * BACKUPS_CHANGED, this is the node that was newly added, removed, or |
| 62 | * whose position was changed in the list. |
Ayaka Koshibe | 8b3270f | 2014-09-22 13:44:42 -0700 | [diff] [blame] | 63 | * |
Ayaka Koshibe | 67af1f4 | 2014-10-20 15:26:37 -0700 | [diff] [blame] | 64 | * @return node ID as a subject |
Ayaka Koshibe | 8b3270f | 2014-09-22 13:44:42 -0700 | [diff] [blame] | 65 | */ |
Ayaka Koshibe | 67af1f4 | 2014-10-20 15:26:37 -0700 | [diff] [blame] | 66 | public NodeId node() { |
| 67 | return node; |
Ayaka Koshibe | 8b3270f | 2014-09-22 13:44:42 -0700 | [diff] [blame] | 68 | } |
| 69 | } |