blob: 316a3b41cf67f11c447a4023b2fec925664c9839 [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 Koshibef9b02fc2014-10-15 17:07:05 -070061 @SuppressWarnings({ "unchecked", "rawtypes" })
Ayaka Koshibe406d0102014-09-24 16:08:12 -070062 @Override
tomb41d1ac2014-09-24 01:51:24 -070063 @Activate
64 public void activate() {
65 super.activate();
66
Ayaka Koshibee8e45352014-10-16 00:37:19 -070067 this.serializer = new KryoSerializer() {
68 @Override
69 protected void setupKryoPool() {
Yuta HIGUCHI8d143d22014-10-19 23:15:09 -070070 serializerPool = KryoNamespace.newBuilder()
71 .register(KryoNamespaces.API)
Ayaka Koshibee8e45352014-10-16 00:37:19 -070072
73 .register(RoleValue.class, new RoleValueSerializer())
74 .build()
75 .populate(1);
76 }
77 };
78
79 roleMap = new SMap(theInstance.getMap("nodeRoles"), this.serializer);
Ayaka Koshibe67af1f42014-10-20 15:26:37 -070080 roleMap.addEntryListener((new RemoteMasterShipEventHandler()), true);
Ayaka Koshibee8e45352014-10-16 00:37:19 -070081 terms = new SMap(theInstance.getMap("terms"), this.serializer);
82 clusterSize = theInstance.getAtomicLong("clustersize");
Yuta HIGUCHIc8e19d42014-09-24 17:20:52 -070083
tomb41d1ac2014-09-24 01:51:24 -070084 log.info("Started");
85 }
86
87 @Deactivate
88 public void deactivate() {
89 log.info("Stopped");
90 }
91
92 @Override
Ayaka Koshibec4047702014-10-07 14:43:52 -070093 public MastershipRole getRole(NodeId nodeId, DeviceId deviceId) {
Ayaka Koshibea7384a82014-10-22 18:59:06 -070094 final RoleValue roleInfo = getRoleValue(deviceId);
95 if (roleInfo.contains(MASTER, nodeId)) {
96 return MASTER;
Ayaka Koshibec4047702014-10-07 14:43:52 -070097 }
Ayaka Koshibea7384a82014-10-22 18:59:06 -070098 if (roleInfo.contains(STANDBY, nodeId)) {
99 return STANDBY;
100 }
101 return NONE;
Ayaka Koshibec4047702014-10-07 14:43:52 -0700102 }
103
104 @Override
Ayaka Koshibe406d0102014-09-24 16:08:12 -0700105 public MastershipEvent setMaster(NodeId nodeId, DeviceId deviceId) {
tomb41d1ac2014-09-24 01:51:24 -0700106
Ayaka Koshibef9b02fc2014-10-15 17:07:05 -0700107 MastershipRole role = getRole(nodeId, deviceId);
108 roleMap.lock(deviceId);
Ayaka Koshibe8583ff32014-10-02 16:25:30 -0700109 try {
Ayaka Koshibef9b02fc2014-10-15 17:07:05 -0700110 RoleValue rv = getRoleValue(deviceId);
Ayaka Koshibe8583ff32014-10-02 16:25:30 -0700111 switch (role) {
112 case MASTER:
Ayaka Koshibec4047702014-10-07 14:43:52 -0700113 //reinforce mastership
Ayaka Koshibef9b02fc2014-10-15 17:07:05 -0700114 rv.reassign(nodeId, STANDBY, NONE);
Ayaka Koshibee8e45352014-10-16 00:37:19 -0700115 roleMap.put(deviceId, rv);
Ayaka Koshibe8583ff32014-10-02 16:25:30 -0700116 return null;
117 case STANDBY:
Ayaka Koshibea7384a82014-10-22 18:59:06 -0700118 case NONE:
Ayaka Koshibef9b02fc2014-10-15 17:07:05 -0700119 NodeId current = rv.get(MASTER);
Ayaka Koshibec4047702014-10-07 14:43:52 -0700120 if (current != null) {
Ayaka Koshibef9b02fc2014-10-15 17:07:05 -0700121 //backup and replace current master
Ayaka Koshibea7384a82014-10-22 18:59:06 -0700122 rv.reassign(current, NONE, STANDBY);
Ayaka Koshibef9b02fc2014-10-15 17:07:05 -0700123 rv.replace(current, nodeId, MASTER);
124 } else {
125 //no master before so just add.
126 rv.add(MASTER, nodeId);
Ayaka Koshibe8583ff32014-10-02 16:25:30 -0700127 }
Ayaka Koshibef9b02fc2014-10-15 17:07:05 -0700128 rv.reassign(nodeId, STANDBY, NONE);
Ayaka Koshibee8e45352014-10-16 00:37:19 -0700129 roleMap.put(deviceId, rv);
Ayaka Koshibef9b02fc2014-10-15 17:07:05 -0700130 updateTerm(deviceId);
Ayaka Koshibefc981cf2014-10-21 12:44:17 -0700131 return new MastershipEvent(MASTER_CHANGED, deviceId, rv.roleInfo());
Ayaka Koshibe8583ff32014-10-02 16:25:30 -0700132 default:
133 log.warn("unknown Mastership Role {}", role);
134 return null;
135 }
Ayaka Koshibe8583ff32014-10-02 16:25:30 -0700136 } finally {
Ayaka Koshibef9b02fc2014-10-15 17:07:05 -0700137 roleMap.unlock(deviceId);
tomb41d1ac2014-09-24 01:51:24 -0700138 }
139 }
140
141 @Override
142 public NodeId getMaster(DeviceId deviceId) {
Ayaka Koshibee8e45352014-10-16 00:37:19 -0700143 return getNode(MASTER, deviceId);
tomb41d1ac2014-09-24 01:51:24 -0700144 }
145
Ayaka Koshibe45503ce2014-10-14 11:26:45 -0700146
147 @Override
Ayaka Koshibeabedb092014-10-20 17:01:31 -0700148 public RoleInfo getNodes(DeviceId deviceId) {
Ayaka Koshibef9b02fc2014-10-15 17:07:05 -0700149 roleMap.lock(deviceId);
Ayaka Koshibe45503ce2014-10-14 11:26:45 -0700150 try {
Ayaka Koshibef9b02fc2014-10-15 17:07:05 -0700151 RoleValue rv = getRoleValue(deviceId);
Ayaka Koshibeabedb092014-10-20 17:01:31 -0700152 return rv.roleInfo();
Ayaka Koshibe45503ce2014-10-14 11:26:45 -0700153 } finally {
Ayaka Koshibef9b02fc2014-10-15 17:07:05 -0700154 roleMap.unlock(deviceId);
Ayaka Koshibe45503ce2014-10-14 11:26:45 -0700155 }
156 }
157
tomb41d1ac2014-09-24 01:51:24 -0700158 @Override
159 public Set<DeviceId> getDevices(NodeId nodeId) {
160 ImmutableSet.Builder<DeviceId> builder = ImmutableSet.builder();
Ayaka Koshibe8583ff32014-10-02 16:25:30 -0700161
Ayaka Koshibef9b02fc2014-10-15 17:07:05 -0700162 for (Map.Entry<DeviceId, RoleValue> el : roleMap.entrySet()) {
163 if (nodeId.equals(el.getValue().get(MASTER))) {
164 builder.add(el.getKey());
tomb41d1ac2014-09-24 01:51:24 -0700165 }
166 }
Ayaka Koshibe8583ff32014-10-02 16:25:30 -0700167
tomb41d1ac2014-09-24 01:51:24 -0700168 return builder.build();
169 }
170
171 @Override
172 public MastershipRole requestRole(DeviceId deviceId) {
Ayaka Koshibe8583ff32014-10-02 16:25:30 -0700173 NodeId local = clusterService.getLocalNode().id();
Ayaka Koshibe8583ff32014-10-02 16:25:30 -0700174
Ayaka Koshibef9b02fc2014-10-15 17:07:05 -0700175 roleMap.lock(deviceId);
Ayaka Koshibe8583ff32014-10-02 16:25:30 -0700176 try {
Ayaka Koshibef9b02fc2014-10-15 17:07:05 -0700177 RoleValue rv = getRoleValue(deviceId);
Ayaka Koshibe8583ff32014-10-02 16:25:30 -0700178 MastershipRole role = getRole(local, deviceId);
179 switch (role) {
180 case MASTER:
Ayaka Koshibef9b02fc2014-10-15 17:07:05 -0700181 rv.reassign(local, STANDBY, NONE);
Ayaka Koshibea7384a82014-10-22 18:59:06 -0700182 terms.putIfAbsent(deviceId, INIT);
Ayaka Koshibee8e45352014-10-16 00:37:19 -0700183 roleMap.put(deviceId, rv);
Ayaka Koshibe8583ff32014-10-02 16:25:30 -0700184 break;
185 case STANDBY:
Ayaka Koshibef9b02fc2014-10-15 17:07:05 -0700186 rv.reassign(local, NONE, STANDBY);
Ayaka Koshibee8e45352014-10-16 00:37:19 -0700187 roleMap.put(deviceId, rv);
Ayaka Koshibef9b02fc2014-10-15 17:07:05 -0700188 terms.putIfAbsent(deviceId, INIT);
Ayaka Koshibe8583ff32014-10-02 16:25:30 -0700189 break;
190 case NONE:
Ayaka Koshibea7384a82014-10-22 18:59:06 -0700191 //either we're the first standby, or first to device.
192 //for latter, claim mastership.
193 if (rv.get(MASTER) == null) {
194 rv.add(MASTER, local);
195 rv.reassign(local, STANDBY, NONE);
196 updateTerm(deviceId);
197 role = MastershipRole.MASTER;
198 } else {
199 rv.add(STANDBY, local);
200 rv.reassign(local, NONE, STANDBY);
201 role = MastershipRole.STANDBY;
202 }
Ayaka Koshibee8e45352014-10-16 00:37:19 -0700203 roleMap.put(deviceId, rv);
Ayaka Koshibe8583ff32014-10-02 16:25:30 -0700204 break;
205 default:
206 log.warn("unknown Mastership Role {}", role);
207 }
208 return role;
209 } finally {
Ayaka Koshibef9b02fc2014-10-15 17:07:05 -0700210 roleMap.unlock(deviceId);
Ayaka Koshibe8583ff32014-10-02 16:25:30 -0700211 }
tomb41d1ac2014-09-24 01:51:24 -0700212 }
213
214 @Override
Ayaka Koshibeb70d34b2014-09-25 15:43:01 -0700215 public MastershipTerm getTermFor(DeviceId deviceId) {
Ayaka Koshibef9b02fc2014-10-15 17:07:05 -0700216 RoleValue rv = getRoleValue(deviceId);
217 if ((rv.get(MASTER) == null) || (terms.get(deviceId) == null)) {
Ayaka Koshibe8583ff32014-10-02 16:25:30 -0700218 return null;
219 }
Ayaka Koshibef9b02fc2014-10-15 17:07:05 -0700220 return MastershipTerm.of(rv.get(MASTER), terms.get(deviceId));
Ayaka Koshibeb70d34b2014-09-25 15:43:01 -0700221 }
222
Ayaka Koshibed9f693e2014-09-29 18:04:54 -0700223 @Override
Ayaka Koshibec4047702014-10-07 14:43:52 -0700224 public MastershipEvent setStandby(NodeId nodeId, DeviceId deviceId) {
Ayaka Koshibec4047702014-10-07 14:43:52 -0700225 MastershipEvent event = null;
Ayaka Koshibe8583ff32014-10-02 16:25:30 -0700226
Ayaka Koshibef9b02fc2014-10-15 17:07:05 -0700227 roleMap.lock(deviceId);
Ayaka Koshibe8583ff32014-10-02 16:25:30 -0700228 try {
Ayaka Koshibef9b02fc2014-10-15 17:07:05 -0700229 RoleValue rv = getRoleValue(deviceId);
Ayaka Koshibe8583ff32014-10-02 16:25:30 -0700230 MastershipRole role = getRole(nodeId, deviceId);
231 switch (role) {
232 case MASTER:
Ayaka Koshibee8e45352014-10-16 00:37:19 -0700233 event = reelect(nodeId, deviceId, rv);
Ayaka Koshibef9b02fc2014-10-15 17:07:05 -0700234 //fall through to reinforce role
Ayaka Koshibe8583ff32014-10-02 16:25:30 -0700235 case STANDBY:
Ayaka Koshibec4047702014-10-07 14:43:52 -0700236 //fall through to reinforce role
Ayaka Koshibe8583ff32014-10-02 16:25:30 -0700237 case NONE:
Ayaka Koshibef9b02fc2014-10-15 17:07:05 -0700238 rv.reassign(nodeId, NONE, STANDBY);
Ayaka Koshibee8e45352014-10-16 00:37:19 -0700239 roleMap.put(deviceId, rv);
Ayaka Koshibe8583ff32014-10-02 16:25:30 -0700240 break;
241 default:
242 log.warn("unknown Mastership Role {}", role);
243 }
Ayaka Koshibec4047702014-10-07 14:43:52 -0700244 return event;
Ayaka Koshibe8583ff32014-10-02 16:25:30 -0700245 } finally {
Ayaka Koshibef9b02fc2014-10-15 17:07:05 -0700246 roleMap.unlock(deviceId);
Ayaka Koshibe8583ff32014-10-02 16:25:30 -0700247 }
248 }
249
Ayaka Koshibec4047702014-10-07 14:43:52 -0700250 @Override
251 public MastershipEvent relinquishRole(NodeId nodeId, DeviceId deviceId) {
Ayaka Koshibec4047702014-10-07 14:43:52 -0700252 MastershipEvent event = null;
Ayaka Koshibe25fd23a2014-10-03 15:50:43 -0700253
Ayaka Koshibef9b02fc2014-10-15 17:07:05 -0700254 roleMap.lock(deviceId);
Ayaka Koshibec4047702014-10-07 14:43:52 -0700255 try {
Ayaka Koshibef9b02fc2014-10-15 17:07:05 -0700256 RoleValue rv = getRoleValue(deviceId);
Ayaka Koshibec4047702014-10-07 14:43:52 -0700257 MastershipRole role = getRole(nodeId, deviceId);
258 switch (role) {
259 case MASTER:
Ayaka Koshibee8e45352014-10-16 00:37:19 -0700260 event = reelect(nodeId, deviceId, rv);
Ayaka Koshibef9b02fc2014-10-15 17:07:05 -0700261 //fall through to reinforce relinquishment
Ayaka Koshibec4047702014-10-07 14:43:52 -0700262 case STANDBY:
263 //fall through to reinforce relinquishment
264 case NONE:
Ayaka Koshibef9b02fc2014-10-15 17:07:05 -0700265 rv.reassign(nodeId, STANDBY, NONE);
Ayaka Koshibee8e45352014-10-16 00:37:19 -0700266 roleMap.put(deviceId, rv);
Ayaka Koshibec4047702014-10-07 14:43:52 -0700267 break;
268 default:
269 log.warn("unknown Mastership Role {}", role);
Ayaka Koshibe8583ff32014-10-02 16:25:30 -0700270 }
Ayaka Koshibec4047702014-10-07 14:43:52 -0700271 return event;
272 } finally {
Ayaka Koshibef9b02fc2014-10-15 17:07:05 -0700273 roleMap.unlock(deviceId);
Ayaka Koshibe8583ff32014-10-02 16:25:30 -0700274 }
Ayaka Koshibed9f693e2014-09-29 18:04:54 -0700275 }
276
Ayaka Koshibec4047702014-10-07 14:43:52 -0700277 //helper to fetch a new master candidate for a given device.
Ayaka Koshibeb5c63a02014-10-18 18:42:27 -0700278 private MastershipEvent reelect(
279 NodeId current, DeviceId deviceId, RoleValue rv) {
Ayaka Koshibec4047702014-10-07 14:43:52 -0700280
281 //if this is an queue it'd be neater.
Ayaka Koshibef9b02fc2014-10-15 17:07:05 -0700282 NodeId backup = null;
283 for (NodeId n : rv.nodesOfRole(STANDBY)) {
284 if (!current.equals(n)) {
Ayaka Koshibec4047702014-10-07 14:43:52 -0700285 backup = n;
286 break;
287 }
288 }
289
290 if (backup == null) {
Ayaka Koshibeb5c63a02014-10-18 18:42:27 -0700291 log.info("{} giving up and going to NONE for {}", current, deviceId);
Ayaka Koshibef9b02fc2014-10-15 17:07:05 -0700292 rv.remove(MASTER, current);
Ayaka Koshibee8e45352014-10-16 00:37:19 -0700293 roleMap.put(deviceId, rv);
Ayaka Koshibec4047702014-10-07 14:43:52 -0700294 return null;
295 } else {
Ayaka Koshibeb5c63a02014-10-18 18:42:27 -0700296 log.info("{} trying to pass mastership for {} to {}", current, deviceId, backup);
Ayaka Koshibef9b02fc2014-10-15 17:07:05 -0700297 rv.replace(current, backup, MASTER);
298 rv.reassign(backup, STANDBY, NONE);
Ayaka Koshibee8e45352014-10-16 00:37:19 -0700299 roleMap.put(deviceId, rv);
Ayaka Koshibef9b02fc2014-10-15 17:07:05 -0700300 Integer term = terms.get(deviceId);
301 terms.put(deviceId, ++term);
Ayaka Koshibefc981cf2014-10-21 12:44:17 -0700302 return new MastershipEvent(MASTER_CHANGED, deviceId, rv.roleInfo());
Ayaka Koshibec4047702014-10-07 14:43:52 -0700303 }
304 }
305
Ayaka Koshibef9b02fc2014-10-15 17:07:05 -0700306 //return the RoleValue structure for a device, or create one
307 private RoleValue getRoleValue(DeviceId deviceId) {
308 RoleValue value = roleMap.get(deviceId);
309 if (value == null) {
310 value = new RoleValue();
Ayaka Koshibea7384a82014-10-22 18:59:06 -0700311 RoleValue concurrentlyAdded = roleMap.putIfAbsent(deviceId, value);
312 if (concurrentlyAdded != null) {
313 return concurrentlyAdded;
314 }
Ayaka Koshibec4047702014-10-07 14:43:52 -0700315 }
Ayaka Koshibef9b02fc2014-10-15 17:07:05 -0700316 return value;
Ayaka Koshibec4047702014-10-07 14:43:52 -0700317 }
318
Ayaka Koshibef9b02fc2014-10-15 17:07:05 -0700319 //get first applicable node out of store-unique structure.
320 private NodeId getNode(MastershipRole role, DeviceId deviceId) {
321 RoleValue value = roleMap.get(deviceId);
322 if (value != null) {
323 return value.get(role);
Ayaka Koshibec4047702014-10-07 14:43:52 -0700324 }
Ayaka Koshibef9b02fc2014-10-15 17:07:05 -0700325 return null;
326 }
327
Ayaka Koshibec4047702014-10-07 14:43:52 -0700328 //adds or updates term information.
Ayaka Koshibef9b02fc2014-10-15 17:07:05 -0700329 private void updateTerm(DeviceId deviceId) {
Ayaka Koshibeb5c63a02014-10-18 18:42:27 -0700330 terms.lock(deviceId);
331 try {
332 Integer term = terms.get(deviceId);
333 if (term == null) {
334 terms.put(deviceId, INIT);
335 } else {
336 terms.put(deviceId, ++term);
337 }
338 } finally {
339 terms.unlock(deviceId);
Ayaka Koshibec4047702014-10-07 14:43:52 -0700340 }
Ayaka Koshibe8583ff32014-10-02 16:25:30 -0700341 }
342
Ayaka Koshibeb5c63a02014-10-18 18:42:27 -0700343 private class RemoteMasterShipEventHandler implements EntryListener<DeviceId, RoleValue> {
alshabib339a3d92014-09-26 17:54:32 -0700344
345 @Override
Ayaka Koshibeb5c63a02014-10-18 18:42:27 -0700346 public void entryAdded(EntryEvent<DeviceId, RoleValue> event) {
alshabib339a3d92014-09-26 17:54:32 -0700347 }
348
349 @Override
Ayaka Koshibeb5c63a02014-10-18 18:42:27 -0700350 public void entryRemoved(EntryEvent<DeviceId, RoleValue> event) {
alshabib339a3d92014-09-26 17:54:32 -0700351 }
352
353 @Override
Ayaka Koshibeb5c63a02014-10-18 18:42:27 -0700354 public void entryUpdated(EntryEvent<DeviceId, RoleValue> event) {
355 NodeId myId = clusterService.getLocalNode().id();
356 NodeId node = event.getValue().get(MASTER);
357 if (myId.equals(node)) {
358 // XXX or do we just let it get sent and caught by ourself?
359 return;
360 }
361 notifyDelegate(new MastershipEvent(
Ayaka Koshibefc981cf2014-10-21 12:44:17 -0700362 MASTER_CHANGED, event.getKey(), event.getValue().roleInfo()));
Ayaka Koshibeb5c63a02014-10-18 18:42:27 -0700363 }
364
365 @Override
366 public void entryEvicted(EntryEvent<DeviceId, RoleValue> event) {
367 }
368
369 @Override
370 public void mapEvicted(MapEvent event) {
371 }
372
373 @Override
374 public void mapCleared(MapEvent event) {
alshabib339a3d92014-09-26 17:54:32 -0700375 }
376 }
377
tomb41d1ac2014-09-24 01:51:24 -0700378}