blob: 74f81615d196da89383a11e91ba570d718f2c082 [file] [log] [blame]
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07001/*
2 * Copyright 2014 Open Networking Laboratory
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
Yuta HIGUCHI80912e62014-10-12 00:15:47 -070016package org.onlab.onos.mastership;
Ayaka Koshibe8b3270f2014-09-22 13:44:42 -070017
Ayaka Koshibefc981cf2014-10-21 12:44:17 -070018import org.onlab.onos.cluster.RoleInfo;
Ayaka Koshibe8b3270f2014-09-22 13:44:42 -070019import org.onlab.onos.event.AbstractEvent;
20import org.onlab.onos.net.DeviceId;
21
Yuta HIGUCHIfd5cdf12014-10-26 13:28:48 -070022import com.google.common.base.MoreObjects;
23
Ayaka Koshibe8b3270f2014-09-22 13:44:42 -070024/**
Ayaka Koshibe8d504a92014-09-22 17:07:36 -070025 * Describes a device mastership event.
Ayaka Koshibe8b3270f2014-09-22 13:44:42 -070026 */
27public class MastershipEvent extends AbstractEvent<MastershipEvent.Type, DeviceId> {
28
Ayaka Koshibefc981cf2014-10-21 12:44:17 -070029 //Contains master and standby information.
30 RoleInfo roleInfo;
Ayaka Koshibe8b3270f2014-09-22 13:44:42 -070031
32 /**
33 * Type of mastership events.
34 */
35 public enum Type {
36 /**
37 * Signifies that the master for a device has changed.
38 */
Ayaka Koshibe67af1f42014-10-20 15:26:37 -070039 MASTER_CHANGED,
40
41 /**
42 * Signifies that the list of backup nodes has changed.
43 */
44 BACKUPS_CHANGED
Ayaka Koshibe8b3270f2014-09-22 13:44:42 -070045 }
46
47 /**
Ayaka Koshibefc981cf2014-10-21 12:44:17 -070048 * Creates an event of a given type and for the specified device,
49 * role information, and the current time.
Ayaka Koshibe8b3270f2014-09-22 13:44:42 -070050 *
51 * @param type device event type
52 * @param device event device subject
Ayaka Koshibefc981cf2014-10-21 12:44:17 -070053 * @param info mastership role information subject
Ayaka Koshibe8b3270f2014-09-22 13:44:42 -070054 */
Ayaka Koshibefc981cf2014-10-21 12:44:17 -070055 public MastershipEvent(Type type, DeviceId device, RoleInfo info) {
Ayaka Koshibe8b3270f2014-09-22 13:44:42 -070056 super(type, device);
Ayaka Koshibefc981cf2014-10-21 12:44:17 -070057 this.roleInfo = info;
Ayaka Koshibe8b3270f2014-09-22 13:44:42 -070058 }
59
60 /**
61 * Creates an event of a given type and for the specified device, master,
62 * and time.
63 *
64 * @param type mastership event type
65 * @param device event device subject
66 * @param master master ID subject
67 * @param time occurrence time
68 */
Ayaka Koshibefc981cf2014-10-21 12:44:17 -070069 public MastershipEvent(Type type, DeviceId device, RoleInfo info, long time) {
Ayaka Koshibe8b3270f2014-09-22 13:44:42 -070070 super(type, device, time);
Ayaka Koshibefc981cf2014-10-21 12:44:17 -070071 this.roleInfo = info;
Ayaka Koshibe8b3270f2014-09-22 13:44:42 -070072 }
73
74 /**
Ayaka Koshibefc981cf2014-10-21 12:44:17 -070075 * Returns the current role state for the subject.
76 *
77 * @return RoleInfo associated with Device ID subject
78 */
79 public RoleInfo roleInfo() {
80 return roleInfo;
Ayaka Koshibe8b3270f2014-09-22 13:44:42 -070081 }
Yuta HIGUCHIfd5cdf12014-10-26 13:28:48 -070082
83 @Override
84 public String toString() {
85 return MoreObjects.toStringHelper(getClass())
86 .add("time", time())
87 .add("type", type())
88 .add("subject", subject())
89 .add("roleInfo", roleInfo)
90 .toString();
91 }
Ayaka Koshibe8b3270f2014-09-22 13:44:42 -070092}