simple implementation of DistributedMastershipStore#unsetMaster
Change-Id: I955f394b975fb53d2ca93b7a8a34a7ad3d684767
Showing
1 changed file
with
13 additions
and
3 deletions
... | @@ -119,14 +119,24 @@ implements MastershipStore { | ... | @@ -119,14 +119,24 @@ implements MastershipStore { |
119 | 119 | ||
120 | @Override | 120 | @Override |
121 | public MastershipTerm getTermFor(DeviceId deviceId) { | 121 | public MastershipTerm getTermFor(DeviceId deviceId) { |
122 | - // FIXME: implement this | 122 | + // FIXME: implement this properly |
123 | return MastershipTerm.of(getMaster(deviceId), 1); | 123 | return MastershipTerm.of(getMaster(deviceId), 1); |
124 | } | 124 | } |
125 | 125 | ||
126 | @Override | 126 | @Override |
127 | public MastershipEvent unsetMaster(NodeId nodeId, DeviceId deviceId) { | 127 | public MastershipEvent unsetMaster(NodeId nodeId, DeviceId deviceId) { |
128 | - // TODO Auto-generated method stub | 128 | + boolean removed = rawMasters.remove(serialize(deviceId), serialize(nodeId)); |
129 | - return null; | 129 | + masters.invalidate(deviceId); |
130 | + if (!removed) { | ||
131 | + return null; | ||
132 | + } | ||
133 | + Optional<NodeId> newMaster = masters.getUnchecked(deviceId); | ||
134 | + if (newMaster.isPresent()) { | ||
135 | + return new MastershipEvent(MASTER_CHANGED, deviceId, newMaster.get()); | ||
136 | + } else { | ||
137 | + // FIXME: probably need to express NO_MASTER somehow. | ||
138 | + return null; | ||
139 | + } | ||
130 | } | 140 | } |
131 | 141 | ||
132 | private class RemoteMasterShipEventHandler extends RemoteCacheEventHandler<DeviceId, NodeId> { | 142 | private class RemoteMasterShipEventHandler extends RemoteCacheEventHandler<DeviceId, NodeId> { | ... | ... |
-
Please register or login to post a comment