blob: f9352fe9e4c67fddcc842c0f81aab29ef0e662db [file] [log] [blame]
Yuta HIGUCHI80912e62014-10-12 00:15:47 -07001package org.onlab.onos.store.mastership.impl;
tomb41d1ac2014-09-24 01:51:24 -07002
Yuta HIGUCHI80912e62014-10-12 00:15:47 -07003import static org.onlab.onos.mastership.MastershipEvent.Type.MASTER_CHANGED;
alshabib339a3d92014-09-26 17:54:32 -07004
5import java.util.Map;
alshabib339a3d92014-09-26 17:54:32 -07006import java.util.Set;
Yuta HIGUCHIc8e19d42014-09-24 17:20:52 -07007
tomb41d1ac2014-09-24 01:51:24 -07008import org.apache.felix.scr.annotations.Activate;
9import org.apache.felix.scr.annotations.Component;
10import org.apache.felix.scr.annotations.Deactivate;
11import org.apache.felix.scr.annotations.Reference;
12import org.apache.felix.scr.annotations.ReferenceCardinality;
13import org.apache.felix.scr.annotations.Service;
14import org.onlab.onos.cluster.ClusterService;
tomb41d1ac2014-09-24 01:51:24 -070015import org.onlab.onos.cluster.NodeId;
Ayaka Koshibeabedb092014-10-20 17:01:31 -070016import org.onlab.onos.cluster.RoleInfo;
Yuta HIGUCHI80912e62014-10-12 00:15:47 -070017import org.onlab.onos.mastership.MastershipEvent;
18import org.onlab.onos.mastership.MastershipStore;
19import org.onlab.onos.mastership.MastershipStoreDelegate;
20import org.onlab.onos.mastership.MastershipTerm;
tomb41d1ac2014-09-24 01:51:24 -070021import org.onlab.onos.net.DeviceId;
22import org.onlab.onos.net.MastershipRole;
Yuta HIGUCHIb5df76d2014-09-27 20:54:00 -070023import org.onlab.onos.store.common.AbstractHazelcastStore;
Ayaka Koshibef9b02fc2014-10-15 17:07:05 -070024import org.onlab.onos.store.common.SMap;
Yuta HIGUCHI8d143d22014-10-19 23:15:09 -070025import org.onlab.onos.store.serializers.KryoNamespaces;
Ayaka Koshibef9b02fc2014-10-15 17:07:05 -070026import org.onlab.onos.store.serializers.KryoSerializer;
Yuta HIGUCHI8d143d22014-10-19 23:15:09 -070027import org.onlab.util.KryoNamespace;
tomb41d1ac2014-09-24 01:51:24 -070028
alshabib339a3d92014-09-26 17:54:32 -070029import com.google.common.collect.ImmutableSet;
Ayaka Koshibeb5c63a02014-10-18 18:42:27 -070030import com.hazelcast.core.EntryEvent;
31import com.hazelcast.core.EntryListener;
Ayaka Koshibee8e45352014-10-16 00:37:19 -070032import com.hazelcast.core.IAtomicLong;
Ayaka Koshibeb5c63a02014-10-18 18:42:27 -070033import com.hazelcast.core.MapEvent;
tomb41d1ac2014-09-24 01:51:24 -070034
Ayaka Koshibef9b02fc2014-10-15 17:07:05 -070035import static org.onlab.onos.net.MastershipRole.*;
36
tomb41d1ac2014-09-24 01:51:24 -070037/**
Ayaka Koshibec4047702014-10-07 14:43:52 -070038 * Distributed implementation of the mastership store. The store is
39 * responsible for the master selection process.
tomb41d1ac2014-09-24 01:51:24 -070040 */
41@Component(immediate = true)
42@Service
tom0755a362014-09-24 11:54:43 -070043public class DistributedMastershipStore
Yuta HIGUCHI2e963892014-09-27 13:00:39 -070044extends AbstractHazelcastStore<MastershipEvent, MastershipStoreDelegate>
alshabib339a3d92014-09-26 17:54:32 -070045implements MastershipStore {
tomb41d1ac2014-09-24 01:51:24 -070046
Ayaka Koshibec4047702014-10-07 14:43:52 -070047 //initial term/TTL value
Ayaka Koshibe8583ff32014-10-02 16:25:30 -070048 private static final Integer INIT = 0;
Ayaka Koshibe8583ff32014-10-02 16:25:30 -070049
Ayaka Koshibef9b02fc2014-10-15 17:07:05 -070050 //device to node roles
51 protected SMap<DeviceId, RoleValue> roleMap;
Ayaka Koshibe8583ff32014-10-02 16:25:30 -070052 //devices to terms
Ayaka Koshibef9b02fc2014-10-15 17:07:05 -070053 protected SMap<DeviceId, Integer> terms;
Ayaka Koshibee8e45352014-10-16 00:37:19 -070054 //last-known cluster size, used for tie-breaking when partitioning occurs
55 protected IAtomicLong clusterSize;
56
Ayaka Koshibe8583ff32014-10-02 16:25:30 -070057
tomb41d1ac2014-09-24 01:51:24 -070058 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
59 protected ClusterService clusterService;
60
Ayaka Koshibe406d0102014-09-24 16:08:12 -070061 @Override
tomb41d1ac2014-09-24 01:51:24 -070062 @Activate
63 public void activate() {
64 super.activate();
65
Ayaka Koshibee8e45352014-10-16 00:37:19 -070066 this.serializer = new KryoSerializer() {
67 @Override
68 protected void setupKryoPool() {
Yuta HIGUCHI8d143d22014-10-19 23:15:09 -070069 serializerPool = KryoNamespace.newBuilder()
70 .register(KryoNamespaces.API)
Ayaka Koshibee8e45352014-10-16 00:37:19 -070071
72 .register(RoleValue.class, new RoleValueSerializer())
73 .build()
74 .populate(1);
75 }
76 };
77
Yuta HIGUCHI9def0472014-10-23 15:51:10 -070078 roleMap = new SMap<>(theInstance.<byte[], byte[]>getMap("nodeRoles"), this.serializer);
Ayaka Koshibe67af1f42014-10-20 15:26:37 -070079 roleMap.addEntryListener((new RemoteMasterShipEventHandler()), true);
Yuta HIGUCHI9def0472014-10-23 15:51:10 -070080 terms = new SMap<>(theInstance.<byte[], byte[]>getMap("terms"), this.serializer);
Ayaka Koshibee8e45352014-10-16 00:37:19 -070081 clusterSize = theInstance.getAtomicLong("clustersize");
Yuta HIGUCHIc8e19d42014-09-24 17:20:52 -070082
tomb41d1ac2014-09-24 01:51:24 -070083 log.info("Started");
84 }
85
86 @Deactivate
87 public void deactivate() {
88 log.info("Stopped");
89 }
90
91 @Override
Ayaka Koshibec4047702014-10-07 14:43:52 -070092 public MastershipRole getRole(NodeId nodeId, DeviceId deviceId) {
Ayaka Koshibea7384a82014-10-22 18:59:06 -070093 final RoleValue roleInfo = getRoleValue(deviceId);
94 if (roleInfo.contains(MASTER, nodeId)) {
95 return MASTER;
Ayaka Koshibec4047702014-10-07 14:43:52 -070096 }
Ayaka Koshibea7384a82014-10-22 18:59:06 -070097 if (roleInfo.contains(STANDBY, nodeId)) {
98 return STANDBY;
99 }
100 return NONE;
Ayaka Koshibec4047702014-10-07 14:43:52 -0700101 }
102
103 @Override
Ayaka Koshibe406d0102014-09-24 16:08:12 -0700104 public MastershipEvent setMaster(NodeId nodeId, DeviceId deviceId) {
tomb41d1ac2014-09-24 01:51:24 -0700105
Ayaka Koshibef9b02fc2014-10-15 17:07:05 -0700106 MastershipRole role = getRole(nodeId, deviceId);
107 roleMap.lock(deviceId);
Ayaka Koshibe8583ff32014-10-02 16:25:30 -0700108 try {
Ayaka Koshibef9b02fc2014-10-15 17:07:05 -0700109 RoleValue rv = getRoleValue(deviceId);
Ayaka Koshibe8583ff32014-10-02 16:25:30 -0700110 switch (role) {
111 case MASTER:
Ayaka Koshibec4047702014-10-07 14:43:52 -0700112 //reinforce mastership
Ayaka Koshibef9b02fc2014-10-15 17:07:05 -0700113 rv.reassign(nodeId, STANDBY, NONE);
Ayaka Koshibee8e45352014-10-16 00:37:19 -0700114 roleMap.put(deviceId, rv);
Ayaka Koshibe8583ff32014-10-02 16:25:30 -0700115 return null;
116 case STANDBY:
Ayaka Koshibea7384a82014-10-22 18:59:06 -0700117 case NONE:
Ayaka Koshibef9b02fc2014-10-15 17:07:05 -0700118 NodeId current = rv.get(MASTER);
Ayaka Koshibec4047702014-10-07 14:43:52 -0700119 if (current != null) {
Ayaka Koshibef9b02fc2014-10-15 17:07:05 -0700120 //backup and replace current master
Ayaka Koshibea7384a82014-10-22 18:59:06 -0700121 rv.reassign(current, NONE, STANDBY);
Ayaka Koshibef9b02fc2014-10-15 17:07:05 -0700122 rv.replace(current, nodeId, MASTER);
123 } else {
124 //no master before so just add.
125 rv.add(MASTER, nodeId);
Ayaka Koshibe8583ff32014-10-02 16:25:30 -0700126 }
Ayaka Koshibef9b02fc2014-10-15 17:07:05 -0700127 rv.reassign(nodeId, STANDBY, NONE);
Ayaka Koshibee8e45352014-10-16 00:37:19 -0700128 roleMap.put(deviceId, rv);
Ayaka Koshibef9b02fc2014-10-15 17:07:05 -0700129 updateTerm(deviceId);
Ayaka Koshibefc981cf2014-10-21 12:44:17 -0700130 return new MastershipEvent(MASTER_CHANGED, deviceId, rv.roleInfo());
Ayaka Koshibe8583ff32014-10-02 16:25:30 -0700131 default:
132 log.warn("unknown Mastership Role {}", role);
133 return null;
134 }
Ayaka Koshibe8583ff32014-10-02 16:25:30 -0700135 } finally {
Ayaka Koshibef9b02fc2014-10-15 17:07:05 -0700136 roleMap.unlock(deviceId);
tomb41d1ac2014-09-24 01:51:24 -0700137 }
138 }
139
140 @Override
141 public NodeId getMaster(DeviceId deviceId) {
Ayaka Koshibee8e45352014-10-16 00:37:19 -0700142 return getNode(MASTER, deviceId);
tomb41d1ac2014-09-24 01:51:24 -0700143 }
144
Ayaka Koshibe45503ce2014-10-14 11:26:45 -0700145
146 @Override
Ayaka Koshibeabedb092014-10-20 17:01:31 -0700147 public RoleInfo getNodes(DeviceId deviceId) {
Ayaka Koshibef9b02fc2014-10-15 17:07:05 -0700148 roleMap.lock(deviceId);
Ayaka Koshibe45503ce2014-10-14 11:26:45 -0700149 try {
Ayaka Koshibef9b02fc2014-10-15 17:07:05 -0700150 RoleValue rv = getRoleValue(deviceId);
Ayaka Koshibeabedb092014-10-20 17:01:31 -0700151 return rv.roleInfo();
Ayaka Koshibe45503ce2014-10-14 11:26:45 -0700152 } finally {
Ayaka Koshibef9b02fc2014-10-15 17:07:05 -0700153 roleMap.unlock(deviceId);
Ayaka Koshibe45503ce2014-10-14 11:26:45 -0700154 }
155 }
156
tomb41d1ac2014-09-24 01:51:24 -0700157 @Override
158 public Set<DeviceId> getDevices(NodeId nodeId) {
159 ImmutableSet.Builder<DeviceId> builder = ImmutableSet.builder();
Ayaka Koshibe8583ff32014-10-02 16:25:30 -0700160
Ayaka Koshibef9b02fc2014-10-15 17:07:05 -0700161 for (Map.Entry<DeviceId, RoleValue> el : roleMap.entrySet()) {
162 if (nodeId.equals(el.getValue().get(MASTER))) {
163 builder.add(el.getKey());
tomb41d1ac2014-09-24 01:51:24 -0700164 }
165 }
Ayaka Koshibe8583ff32014-10-02 16:25:30 -0700166
tomb41d1ac2014-09-24 01:51:24 -0700167 return builder.build();
168 }
169
170 @Override
171 public MastershipRole requestRole(DeviceId deviceId) {
Ayaka Koshibe8583ff32014-10-02 16:25:30 -0700172 NodeId local = clusterService.getLocalNode().id();
Ayaka Koshibe8583ff32014-10-02 16:25:30 -0700173
Ayaka Koshibef9b02fc2014-10-15 17:07:05 -0700174 roleMap.lock(deviceId);
Ayaka Koshibe8583ff32014-10-02 16:25:30 -0700175 try {
Ayaka Koshibef9b02fc2014-10-15 17:07:05 -0700176 RoleValue rv = getRoleValue(deviceId);
Ayaka Koshibe8583ff32014-10-02 16:25:30 -0700177 MastershipRole role = getRole(local, deviceId);
178 switch (role) {
179 case MASTER:
Ayaka Koshibef9b02fc2014-10-15 17:07:05 -0700180 rv.reassign(local, STANDBY, NONE);
Ayaka Koshibea7384a82014-10-22 18:59:06 -0700181 terms.putIfAbsent(deviceId, INIT);
Ayaka Koshibee8e45352014-10-16 00:37:19 -0700182 roleMap.put(deviceId, rv);
Ayaka Koshibe8583ff32014-10-02 16:25:30 -0700183 break;
184 case STANDBY:
Ayaka Koshibef9b02fc2014-10-15 17:07:05 -0700185 rv.reassign(local, NONE, STANDBY);
Ayaka Koshibee8e45352014-10-16 00:37:19 -0700186 roleMap.put(deviceId, rv);
Ayaka Koshibef9b02fc2014-10-15 17:07:05 -0700187 terms.putIfAbsent(deviceId, INIT);
Ayaka Koshibe8583ff32014-10-02 16:25:30 -0700188 break;
189 case NONE:
Ayaka Koshibea7384a82014-10-22 18:59:06 -0700190 //either we're the first standby, or first to device.
191 //for latter, claim mastership.
192 if (rv.get(MASTER) == null) {
193 rv.add(MASTER, local);
194 rv.reassign(local, STANDBY, NONE);
195 updateTerm(deviceId);
196 role = MastershipRole.MASTER;
197 } else {
198 rv.add(STANDBY, local);
199 rv.reassign(local, NONE, STANDBY);
200 role = MastershipRole.STANDBY;
201 }
Ayaka Koshibee8e45352014-10-16 00:37:19 -0700202 roleMap.put(deviceId, rv);
Ayaka Koshibe8583ff32014-10-02 16:25:30 -0700203 break;
204 default:
205 log.warn("unknown Mastership Role {}", role);
206 }
207 return role;
208 } finally {
Ayaka Koshibef9b02fc2014-10-15 17:07:05 -0700209 roleMap.unlock(deviceId);
Ayaka Koshibe8583ff32014-10-02 16:25:30 -0700210 }
tomb41d1ac2014-09-24 01:51:24 -0700211 }
212
213 @Override
Ayaka Koshibeb70d34b2014-09-25 15:43:01 -0700214 public MastershipTerm getTermFor(DeviceId deviceId) {
Ayaka Koshibef9b02fc2014-10-15 17:07:05 -0700215 RoleValue rv = getRoleValue(deviceId);
216 if ((rv.get(MASTER) == null) || (terms.get(deviceId) == null)) {
Ayaka Koshibe8583ff32014-10-02 16:25:30 -0700217 return null;
218 }
Ayaka Koshibef9b02fc2014-10-15 17:07:05 -0700219 return MastershipTerm.of(rv.get(MASTER), terms.get(deviceId));
Ayaka Koshibeb70d34b2014-09-25 15:43:01 -0700220 }
221
Ayaka Koshibed9f693e2014-09-29 18:04:54 -0700222 @Override
Ayaka Koshibec4047702014-10-07 14:43:52 -0700223 public MastershipEvent setStandby(NodeId nodeId, DeviceId deviceId) {
Ayaka Koshibec4047702014-10-07 14:43:52 -0700224 MastershipEvent event = null;
Ayaka Koshibe8583ff32014-10-02 16:25:30 -0700225
Ayaka Koshibef9b02fc2014-10-15 17:07:05 -0700226 roleMap.lock(deviceId);
Ayaka Koshibe8583ff32014-10-02 16:25:30 -0700227 try {
Ayaka Koshibef9b02fc2014-10-15 17:07:05 -0700228 RoleValue rv = getRoleValue(deviceId);
Ayaka Koshibe8583ff32014-10-02 16:25:30 -0700229 MastershipRole role = getRole(nodeId, deviceId);
230 switch (role) {
231 case MASTER:
Ayaka Koshibee8e45352014-10-16 00:37:19 -0700232 event = reelect(nodeId, deviceId, rv);
Ayaka Koshibef9b02fc2014-10-15 17:07:05 -0700233 //fall through to reinforce role
Ayaka Koshibe8583ff32014-10-02 16:25:30 -0700234 case STANDBY:
Ayaka Koshibec4047702014-10-07 14:43:52 -0700235 //fall through to reinforce role
Ayaka Koshibe8583ff32014-10-02 16:25:30 -0700236 case NONE:
Ayaka Koshibef9b02fc2014-10-15 17:07:05 -0700237 rv.reassign(nodeId, NONE, STANDBY);
Ayaka Koshibee8e45352014-10-16 00:37:19 -0700238 roleMap.put(deviceId, rv);
Ayaka Koshibe8583ff32014-10-02 16:25:30 -0700239 break;
240 default:
241 log.warn("unknown Mastership Role {}", role);
242 }
Ayaka Koshibec4047702014-10-07 14:43:52 -0700243 return event;
Ayaka Koshibe8583ff32014-10-02 16:25:30 -0700244 } finally {
Ayaka Koshibef9b02fc2014-10-15 17:07:05 -0700245 roleMap.unlock(deviceId);
Ayaka Koshibe8583ff32014-10-02 16:25:30 -0700246 }
247 }
248
Ayaka Koshibec4047702014-10-07 14:43:52 -0700249 @Override
250 public MastershipEvent relinquishRole(NodeId nodeId, DeviceId deviceId) {
Ayaka Koshibec4047702014-10-07 14:43:52 -0700251 MastershipEvent event = null;
Ayaka Koshibe25fd23a2014-10-03 15:50:43 -0700252
Ayaka Koshibef9b02fc2014-10-15 17:07:05 -0700253 roleMap.lock(deviceId);
Ayaka Koshibec4047702014-10-07 14:43:52 -0700254 try {
Ayaka Koshibef9b02fc2014-10-15 17:07:05 -0700255 RoleValue rv = getRoleValue(deviceId);
Ayaka Koshibec4047702014-10-07 14:43:52 -0700256 MastershipRole role = getRole(nodeId, deviceId);
257 switch (role) {
258 case MASTER:
Ayaka Koshibee8e45352014-10-16 00:37:19 -0700259 event = reelect(nodeId, deviceId, rv);
Ayaka Koshibef9b02fc2014-10-15 17:07:05 -0700260 //fall through to reinforce relinquishment
Ayaka Koshibec4047702014-10-07 14:43:52 -0700261 case STANDBY:
262 //fall through to reinforce relinquishment
263 case NONE:
Ayaka Koshibef9b02fc2014-10-15 17:07:05 -0700264 rv.reassign(nodeId, STANDBY, NONE);
Ayaka Koshibee8e45352014-10-16 00:37:19 -0700265 roleMap.put(deviceId, rv);
Ayaka Koshibec4047702014-10-07 14:43:52 -0700266 break;
267 default:
268 log.warn("unknown Mastership Role {}", role);
Ayaka Koshibe8583ff32014-10-02 16:25:30 -0700269 }
Ayaka Koshibec4047702014-10-07 14:43:52 -0700270 return event;
271 } finally {
Ayaka Koshibef9b02fc2014-10-15 17:07:05 -0700272 roleMap.unlock(deviceId);
Ayaka Koshibe8583ff32014-10-02 16:25:30 -0700273 }
Ayaka Koshibed9f693e2014-09-29 18:04:54 -0700274 }
275
Ayaka Koshibec4047702014-10-07 14:43:52 -0700276 //helper to fetch a new master candidate for a given device.
Ayaka Koshibeb5c63a02014-10-18 18:42:27 -0700277 private MastershipEvent reelect(
278 NodeId current, DeviceId deviceId, RoleValue rv) {
Ayaka Koshibec4047702014-10-07 14:43:52 -0700279
280 //if this is an queue it'd be neater.
Ayaka Koshibef9b02fc2014-10-15 17:07:05 -0700281 NodeId backup = null;
282 for (NodeId n : rv.nodesOfRole(STANDBY)) {
283 if (!current.equals(n)) {
Ayaka Koshibec4047702014-10-07 14:43:52 -0700284 backup = n;
285 break;
286 }
287 }
288
289 if (backup == null) {
Ayaka Koshibeb5c63a02014-10-18 18:42:27 -0700290 log.info("{} giving up and going to NONE for {}", current, deviceId);
Ayaka Koshibef9b02fc2014-10-15 17:07:05 -0700291 rv.remove(MASTER, current);
Ayaka Koshibee8e45352014-10-16 00:37:19 -0700292 roleMap.put(deviceId, rv);
Ayaka Koshibec4047702014-10-07 14:43:52 -0700293 return null;
294 } else {
Ayaka Koshibeb5c63a02014-10-18 18:42:27 -0700295 log.info("{} trying to pass mastership for {} to {}", current, deviceId, backup);
Ayaka Koshibef9b02fc2014-10-15 17:07:05 -0700296 rv.replace(current, backup, MASTER);
297 rv.reassign(backup, STANDBY, NONE);
Ayaka Koshibee8e45352014-10-16 00:37:19 -0700298 roleMap.put(deviceId, rv);
Ayaka Koshibef9b02fc2014-10-15 17:07:05 -0700299 Integer term = terms.get(deviceId);
300 terms.put(deviceId, ++term);
Ayaka Koshibefc981cf2014-10-21 12:44:17 -0700301 return new MastershipEvent(MASTER_CHANGED, deviceId, rv.roleInfo());
Ayaka Koshibec4047702014-10-07 14:43:52 -0700302 }
303 }
304
Ayaka Koshibef9b02fc2014-10-15 17:07:05 -0700305 //return the RoleValue structure for a device, or create one
306 private RoleValue getRoleValue(DeviceId deviceId) {
307 RoleValue value = roleMap.get(deviceId);
308 if (value == null) {
309 value = new RoleValue();
Ayaka Koshibea7384a82014-10-22 18:59:06 -0700310 RoleValue concurrentlyAdded = roleMap.putIfAbsent(deviceId, value);
311 if (concurrentlyAdded != null) {
312 return concurrentlyAdded;
313 }
Ayaka Koshibec4047702014-10-07 14:43:52 -0700314 }
Ayaka Koshibef9b02fc2014-10-15 17:07:05 -0700315 return value;
Ayaka Koshibec4047702014-10-07 14:43:52 -0700316 }
317
Ayaka Koshibef9b02fc2014-10-15 17:07:05 -0700318 //get first applicable node out of store-unique structure.
319 private NodeId getNode(MastershipRole role, DeviceId deviceId) {
320 RoleValue value = roleMap.get(deviceId);
321 if (value != null) {
322 return value.get(role);
Ayaka Koshibec4047702014-10-07 14:43:52 -0700323 }
Ayaka Koshibef9b02fc2014-10-15 17:07:05 -0700324 return null;
325 }
326
Ayaka Koshibec4047702014-10-07 14:43:52 -0700327 //adds or updates term information.
Ayaka Koshibef9b02fc2014-10-15 17:07:05 -0700328 private void updateTerm(DeviceId deviceId) {
Ayaka Koshibeb5c63a02014-10-18 18:42:27 -0700329 terms.lock(deviceId);
330 try {
331 Integer term = terms.get(deviceId);
332 if (term == null) {
333 terms.put(deviceId, INIT);
334 } else {
335 terms.put(deviceId, ++term);
336 }
337 } finally {
338 terms.unlock(deviceId);
Ayaka Koshibec4047702014-10-07 14:43:52 -0700339 }
Ayaka Koshibe8583ff32014-10-02 16:25:30 -0700340 }
341
Ayaka Koshibeb5c63a02014-10-18 18:42:27 -0700342 private class RemoteMasterShipEventHandler implements EntryListener<DeviceId, RoleValue> {
alshabib339a3d92014-09-26 17:54:32 -0700343
344 @Override
Ayaka Koshibeb5c63a02014-10-18 18:42:27 -0700345 public void entryAdded(EntryEvent<DeviceId, RoleValue> event) {
alshabib339a3d92014-09-26 17:54:32 -0700346 }
347
348 @Override
Ayaka Koshibeb5c63a02014-10-18 18:42:27 -0700349 public void entryRemoved(EntryEvent<DeviceId, RoleValue> event) {
alshabib339a3d92014-09-26 17:54:32 -0700350 }
351
352 @Override
Ayaka Koshibeb5c63a02014-10-18 18:42:27 -0700353 public void entryUpdated(EntryEvent<DeviceId, RoleValue> event) {
354 NodeId myId = clusterService.getLocalNode().id();
355 NodeId node = event.getValue().get(MASTER);
356 if (myId.equals(node)) {
357 // XXX or do we just let it get sent and caught by ourself?
358 return;
359 }
360 notifyDelegate(new MastershipEvent(
Ayaka Koshibefc981cf2014-10-21 12:44:17 -0700361 MASTER_CHANGED, event.getKey(), event.getValue().roleInfo()));
Ayaka Koshibeb5c63a02014-10-18 18:42:27 -0700362 }
363
364 @Override
365 public void entryEvicted(EntryEvent<DeviceId, RoleValue> event) {
366 }
367
368 @Override
369 public void mapEvicted(MapEvent event) {
370 }
371
372 @Override
373 public void mapCleared(MapEvent event) {
alshabib339a3d92014-09-26 17:54:32 -0700374 }
375 }
376
tomb41d1ac2014-09-24 01:51:24 -0700377}