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 | fc981cf | 2014-10-21 12:44:17 -0700 | [diff] [blame] | 4 | import org.onlab.onos.cluster.RoleInfo; |
Ayaka Koshibe | 8b3270f | 2014-09-22 13:44:42 -0700 | [diff] [blame] | 5 | import org.onlab.onos.event.AbstractEvent; |
| 6 | import org.onlab.onos.net.DeviceId; |
| 7 | |
| 8 | /** |
Ayaka Koshibe | 8d504a9 | 2014-09-22 17:07:36 -0700 | [diff] [blame] | 9 | * Describes a device mastership event. |
Ayaka Koshibe | 8b3270f | 2014-09-22 13:44:42 -0700 | [diff] [blame] | 10 | */ |
| 11 | public class MastershipEvent extends AbstractEvent<MastershipEvent.Type, DeviceId> { |
| 12 | |
Ayaka Koshibe | fc981cf | 2014-10-21 12:44:17 -0700 | [diff] [blame] | 13 | //Contains master and standby information. |
| 14 | RoleInfo roleInfo; |
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 | /** |
Ayaka Koshibe | fc981cf | 2014-10-21 12:44:17 -0700 | [diff] [blame] | 32 | * Creates an event of a given type and for the specified device, |
| 33 | * role information, and the current time. |
Ayaka Koshibe | 8b3270f | 2014-09-22 13:44:42 -0700 | [diff] [blame] | 34 | * |
| 35 | * @param type device event type |
| 36 | * @param device event device subject |
Ayaka Koshibe | fc981cf | 2014-10-21 12:44:17 -0700 | [diff] [blame] | 37 | * @param info mastership role information subject |
Ayaka Koshibe | 8b3270f | 2014-09-22 13:44:42 -0700 | [diff] [blame] | 38 | */ |
Ayaka Koshibe | fc981cf | 2014-10-21 12:44:17 -0700 | [diff] [blame] | 39 | public MastershipEvent(Type type, DeviceId device, RoleInfo info) { |
Ayaka Koshibe | 8b3270f | 2014-09-22 13:44:42 -0700 | [diff] [blame] | 40 | super(type, device); |
Ayaka Koshibe | fc981cf | 2014-10-21 12:44:17 -0700 | [diff] [blame] | 41 | this.roleInfo = info; |
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 | fc981cf | 2014-10-21 12:44:17 -0700 | [diff] [blame] | 53 | public MastershipEvent(Type type, DeviceId device, RoleInfo info, long time) { |
Ayaka Koshibe | 8b3270f | 2014-09-22 13:44:42 -0700 | [diff] [blame] | 54 | super(type, device, time); |
Ayaka Koshibe | fc981cf | 2014-10-21 12:44:17 -0700 | [diff] [blame] | 55 | this.roleInfo = info; |
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 | fc981cf | 2014-10-21 12:44:17 -0700 | [diff] [blame] | 66 | //XXX to-be removed - or keep for convenience? |
Ayaka Koshibe | 67af1f4 | 2014-10-20 15:26:37 -0700 | [diff] [blame] | 67 | public NodeId node() { |
Ayaka Koshibe | fc981cf | 2014-10-21 12:44:17 -0700 | [diff] [blame] | 68 | return roleInfo.master(); |
| 69 | } |
| 70 | |
| 71 | /** |
| 72 | * Returns the current role state for the subject. |
| 73 | * |
| 74 | * @return RoleInfo associated with Device ID subject |
| 75 | */ |
| 76 | public RoleInfo roleInfo() { |
| 77 | return roleInfo; |
Ayaka Koshibe | 8b3270f | 2014-09-22 13:44:42 -0700 | [diff] [blame] | 78 | } |
| 79 | } |