public void removeResponsibility(Number160 locationKey, boolean keepData) { RangeLock<Number640>.Range lockResp = lockResponsibility(locationKey); try { if (!keepData) { RangeLock<Number640>.Range lock = lock(locationKey); try { final NavigableMap<Number640, Data> removed = backend.remove( new Number640(locationKey, Number160.ZERO, Number160.ZERO, Number160.ZERO), new Number640( locationKey, Number160.MAX_VALUE, Number160.MAX_VALUE, Number160.MAX_VALUE)); for (Map.Entry<Number640, Data> entry : removed.entrySet()) { if (entry.getValue() != null) { entry.getValue().release(); } backend.removeTimeout(entry.getKey()); } } finally { lock.unlock(); } } backend.removeResponsibility(locationKey); } finally { lockResp.unlock(); } }
public void checkTimeout() { long time = System.currentTimeMillis(); Collection<Number640> toRemove = backend.subMapTimeout(time); for (Number640 key : toRemove) { RangeLock<Number640>.Range lock = lock(key); try { Data oldData = backend.remove(key, false); if (oldData != null) { oldData.release(); } backend.removeTimeout(key); // remove responsibility if we don't have any data stored under // locationkey Number160 locationKey = key.locationKey(); RangeLock<Number640>.Range lockResp = lockResponsibility(locationKey); try { if (isEmpty(locationKey)) { backend.removeResponsibility(locationKey); } } finally { lockResp.unlock(); } } finally { lock.unlock(); } } }