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 | |
Yuta HIGUCHI | fd5cdf1 | 2014-10-26 13:28:48 -0700 | [diff] [blame] | 7 | import com.google.common.base.MoreObjects; |
| 8 | |
Ayaka Koshibe | 8b3270f | 2014-09-22 13:44:42 -0700 | [diff] [blame] | 9 | /** |
Ayaka Koshibe | 8d504a9 | 2014-09-22 17:07:36 -0700 | [diff] [blame] | 10 | * Describes a device mastership event. |
Ayaka Koshibe | 8b3270f | 2014-09-22 13:44:42 -0700 | [diff] [blame] | 11 | */ |
| 12 | public class MastershipEvent extends AbstractEvent<MastershipEvent.Type, DeviceId> { |
| 13 | |
Ayaka Koshibe | fc981cf | 2014-10-21 12:44:17 -0700 | [diff] [blame] | 14 | //Contains master and standby information. |
| 15 | RoleInfo roleInfo; |
Ayaka Koshibe | 8b3270f | 2014-09-22 13:44:42 -0700 | [diff] [blame] | 16 | |
| 17 | /** |
| 18 | * Type of mastership events. |
| 19 | */ |
| 20 | public enum Type { |
| 21 | /** |
| 22 | * Signifies that the master for a device has changed. |
| 23 | */ |
Ayaka Koshibe | 67af1f4 | 2014-10-20 15:26:37 -0700 | [diff] [blame] | 24 | MASTER_CHANGED, |
| 25 | |
| 26 | /** |
| 27 | * Signifies that the list of backup nodes has changed. |
| 28 | */ |
| 29 | BACKUPS_CHANGED |
Ayaka Koshibe | 8b3270f | 2014-09-22 13:44:42 -0700 | [diff] [blame] | 30 | } |
| 31 | |
| 32 | /** |
Ayaka Koshibe | fc981cf | 2014-10-21 12:44:17 -0700 | [diff] [blame] | 33 | * Creates an event of a given type and for the specified device, |
| 34 | * role information, and the current time. |
Ayaka Koshibe | 8b3270f | 2014-09-22 13:44:42 -0700 | [diff] [blame] | 35 | * |
| 36 | * @param type device event type |
| 37 | * @param device event device subject |
Ayaka Koshibe | fc981cf | 2014-10-21 12:44:17 -0700 | [diff] [blame] | 38 | * @param info mastership role information subject |
Ayaka Koshibe | 8b3270f | 2014-09-22 13:44:42 -0700 | [diff] [blame] | 39 | */ |
Ayaka Koshibe | fc981cf | 2014-10-21 12:44:17 -0700 | [diff] [blame] | 40 | public MastershipEvent(Type type, DeviceId device, RoleInfo info) { |
Ayaka Koshibe | 8b3270f | 2014-09-22 13:44:42 -0700 | [diff] [blame] | 41 | super(type, device); |
Ayaka Koshibe | fc981cf | 2014-10-21 12:44:17 -0700 | [diff] [blame] | 42 | this.roleInfo = info; |
Ayaka Koshibe | 8b3270f | 2014-09-22 13:44:42 -0700 | [diff] [blame] | 43 | } |
| 44 | |
| 45 | /** |
| 46 | * Creates an event of a given type and for the specified device, master, |
| 47 | * and time. |
| 48 | * |
| 49 | * @param type mastership event type |
| 50 | * @param device event device subject |
| 51 | * @param master master ID subject |
| 52 | * @param time occurrence time |
| 53 | */ |
Ayaka Koshibe | fc981cf | 2014-10-21 12:44:17 -0700 | [diff] [blame] | 54 | public MastershipEvent(Type type, DeviceId device, RoleInfo info, long time) { |
Ayaka Koshibe | 8b3270f | 2014-09-22 13:44:42 -0700 | [diff] [blame] | 55 | super(type, device, time); |
Ayaka Koshibe | fc981cf | 2014-10-21 12:44:17 -0700 | [diff] [blame] | 56 | this.roleInfo = info; |
Ayaka Koshibe | 8b3270f | 2014-09-22 13:44:42 -0700 | [diff] [blame] | 57 | } |
| 58 | |
| 59 | /** |
Ayaka Koshibe | fc981cf | 2014-10-21 12:44:17 -0700 | [diff] [blame] | 60 | * Returns the current role state for the subject. |
| 61 | * |
| 62 | * @return RoleInfo associated with Device ID subject |
| 63 | */ |
| 64 | public RoleInfo roleInfo() { |
| 65 | return roleInfo; |
Ayaka Koshibe | 8b3270f | 2014-09-22 13:44:42 -0700 | [diff] [blame] | 66 | } |
Yuta HIGUCHI | fd5cdf1 | 2014-10-26 13:28:48 -0700 | [diff] [blame] | 67 | |
| 68 | @Override |
| 69 | public String toString() { |
| 70 | return MoreObjects.toStringHelper(getClass()) |
| 71 | .add("time", time()) |
| 72 | .add("type", type()) |
| 73 | .add("subject", subject()) |
| 74 | .add("roleInfo", roleInfo) |
| 75 | .toString(); |
| 76 | } |
Ayaka Koshibe | 8b3270f | 2014-09-22 13:44:42 -0700 | [diff] [blame] | 77 | } |