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 | |
Ayaka Koshibe | fc981cf | 2014-10-21 12:44:17 -0700 | [diff] [blame] | 3 | import org.onlab.onos.cluster.RoleInfo; |
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 | fc981cf | 2014-10-21 12:44:17 -0700 | [diff] [blame] | 12 | //Contains master and standby information. |
| 13 | RoleInfo roleInfo; |
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 | */ |
Ayaka Koshibe | 67af1f4 | 2014-10-20 15:26:37 -0700 | [diff] [blame] | 22 | MASTER_CHANGED, |
| 23 | |
| 24 | /** |
| 25 | * Signifies that the list of backup nodes has changed. |
| 26 | */ |
| 27 | BACKUPS_CHANGED |
Ayaka Koshibe | 8b3270f | 2014-09-22 13:44:42 -0700 | [diff] [blame] | 28 | } |
| 29 | |
| 30 | /** |
Ayaka Koshibe | fc981cf | 2014-10-21 12:44:17 -0700 | [diff] [blame] | 31 | * Creates an event of a given type and for the specified device, |
| 32 | * role information, and the current time. |
Ayaka Koshibe | 8b3270f | 2014-09-22 13:44:42 -0700 | [diff] [blame] | 33 | * |
| 34 | * @param type device event type |
| 35 | * @param device event device subject |
Ayaka Koshibe | fc981cf | 2014-10-21 12:44:17 -0700 | [diff] [blame] | 36 | * @param info mastership role information subject |
Ayaka Koshibe | 8b3270f | 2014-09-22 13:44:42 -0700 | [diff] [blame] | 37 | */ |
Ayaka Koshibe | fc981cf | 2014-10-21 12:44:17 -0700 | [diff] [blame] | 38 | public MastershipEvent(Type type, DeviceId device, RoleInfo info) { |
Ayaka Koshibe | 8b3270f | 2014-09-22 13:44:42 -0700 | [diff] [blame] | 39 | super(type, device); |
Ayaka Koshibe | fc981cf | 2014-10-21 12:44:17 -0700 | [diff] [blame] | 40 | this.roleInfo = info; |
Ayaka Koshibe | 8b3270f | 2014-09-22 13:44:42 -0700 | [diff] [blame] | 41 | } |
| 42 | |
| 43 | /** |
| 44 | * Creates an event of a given type and for the specified device, master, |
| 45 | * and time. |
| 46 | * |
| 47 | * @param type mastership event type |
| 48 | * @param device event device subject |
| 49 | * @param master master ID subject |
| 50 | * @param time occurrence time |
| 51 | */ |
Ayaka Koshibe | fc981cf | 2014-10-21 12:44:17 -0700 | [diff] [blame] | 52 | public MastershipEvent(Type type, DeviceId device, RoleInfo info, long time) { |
Ayaka Koshibe | 8b3270f | 2014-09-22 13:44:42 -0700 | [diff] [blame] | 53 | super(type, device, time); |
Ayaka Koshibe | fc981cf | 2014-10-21 12:44:17 -0700 | [diff] [blame] | 54 | this.roleInfo = info; |
Ayaka Koshibe | 8b3270f | 2014-09-22 13:44:42 -0700 | [diff] [blame] | 55 | } |
| 56 | |
| 57 | /** |
Ayaka Koshibe | fc981cf | 2014-10-21 12:44:17 -0700 | [diff] [blame] | 58 | * Returns the current role state for the subject. |
| 59 | * |
| 60 | * @return RoleInfo associated with Device ID subject |
| 61 | */ |
| 62 | public RoleInfo roleInfo() { |
| 63 | return roleInfo; |
Ayaka Koshibe | 8b3270f | 2014-09-22 13:44:42 -0700 | [diff] [blame] | 64 | } |
| 65 | } |