@Override public void unlock() { map.unlock(key); }
@Override public void unlock(K key) { map.unlock(key); }
@SuppressWarnings({ "unchecked", "rawtypes" }) protected <K> void unlock(Map<K, ?> cache, K key) { ((IMap) cache).unlock(key); }
@Override public void unlock(String mapName, String key) { hazelcast.getMap(mapName).unlock(key); }
@Override public void unlock(String mapName, String key) { hazelcast.getMap(mapName).unlock(key); }
public void run() { IMap map = hazelcast.getMap("myMap"); int key = random.nextInt(SIZE); map.lock(key); try { Thread.sleep(1); } catch (InterruptedException e) { throw new RuntimeException(e); } finally { map.unlock(key); } } }, 1);
/** * UPDATE an object in your cache (the whole object will be replaced) */ private void update(Object oid, Exchange exchange) { Object body = exchange.getIn().getBody(); this.cache.lock(oid); this.cache.replace(oid, body); this.cache.unlock(oid); }
/** * Replaces the entry for given id with a specific value in the body, only if currently mapped to a given value */ private void update(Object oid, Object ovalue, Exchange exchange) { Object body = exchange.getIn().getBody(); this.cache.lock(oid); this.cache.replace(oid, ovalue, body); this.cache.unlock(oid); }
@Override public <K, T> void modifyMap(String mapId, K key, Consumer<Map<K, T>> action) { IMap<K, T> map = getMap(mapId); map.lock(key, lockTimeout, TimeUnit.MILLISECONDS); try { action.accept(map); } finally { map.unlock(key); } }
@Override public <K, I, O> O readFromMap(String mapId, K key, Function<Map<K, I>, O> function) { IMap<K, I> map = getMap(mapId); map.lock(key, lockTimeout, TimeUnit.MILLISECONDS); try { return function.apply(map); } finally { map.unlock(key); } }
@Override public boolean add(String key) { repo.lock(key); try { return repo.putIfAbsent(key, false) == null; } finally { repo.unlock(key); } }
@Override public boolean contains(String key) { repo.lock(key); try { return this.repo.containsKey(key); } finally { repo.unlock(key); } }
protected void handleMapUnlock(String[] args) { getMap().unlock(args[1]); println("true"); }
@Override public boolean confirm(String key) { repo.lock(key); try { return repo.replace(key, false, true); } finally { repo.unlock(key); } }
@Override public boolean remove(String key) { repo.lock(key); try { return repo.remove(key) != null; } finally { repo.unlock(key); } }
protected void handleMapUnlock(String[] args) { getMap().unlock(args[1]); println("true"); }
protected void handleMapUnlock(String[] args) { getMap().unlock(args[1]); println("true"); }
protected void handleMapUnlock(String[] args) { getMap().unlock(args[1]); println("true"); }
@Override public Session createOrRetrieveSession( HttpServerExchange exchange ) { final String sessionId = retrieveSessionIdFrom( exchange ); Session session = getSessionFromCache( sessionId ); if ( session == null ) { sessionCache.lock(sessionId); try { session = tryToCreateAndStoreNewSession(sessionId, exchange); } finally { sessionCache.unlock(sessionId); } } return session; }
@TimeStep public void timeStep(ThreadState state) { int key = state.randomInt(keyCount); long increment = state.randomInt(100); map.lock(key); try { Long current = map.get(key); map.put(key, current + increment); state.increments[key] += increment; } finally { map.unlock(key); } }