@Override public void lock(K key) { map.lock(key); }
@Override public void lock(K key, long leaseTime, TimeUnit timeUnit) { map.lock(key, leaseTime, timeUnit); }
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 contains(String key) { repo.lock(key); try { return this.repo.containsKey(key); } finally { repo.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 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 handleMapLock(String[] args) { getMap().lock(args[1]); println("true"); }
protected void handleMapLock(String[] args) { getMap().lock(args[1]); println("true"); }
protected void handleMapLock(String[] args) { getMap().lock(args[1]); println("true"); }
protected void handleMapLock(String[] args) { getMap().lock(args[1]); println("true"); }
/** * Unlock the lock with its name. * * @param lockName the name of the lock to unlock. */ /* package */ void unlock(final String lockName) { log.trace("unlock - attempt : {}", lockName); final Instant now = Instant.now(); final IMap<String, HazelcastLock> store = getStore(); try { store.lock(lockName); final HazelcastLock lock = getLock(lockName); unlockProperly(lock, now); } finally { store.unlock(lockName); } }
@Override public void releaseAcquiredTrigger(OperableTrigger trigger) { TriggerKey triggerKey = trigger.getKey(); triggersByKey.lock(triggerKey, 5, TimeUnit.SECONDS); try { storeTriggerWrapper(newTriggerWrapper(trigger, WAITING)); } finally { try { triggersByKey.unlock(triggerKey); } catch (IllegalMonitorStateException ex) { LOG.warn("Error unlocking since it is already released.", ex); } } }
@Override public void pauseTrigger(TriggerKey triggerKey) throws JobPersistenceException { triggersByKey.lock(triggerKey, 5, TimeUnit.SECONDS); try { final TriggerWrapper newTrigger = newTriggerWrapper(triggersByKey.get(triggerKey), PAUSED); triggersByKey.set(triggerKey, newTrigger); } finally { try { triggersByKey.unlock(triggerKey); } catch (IllegalMonitorStateException ex) { LOG.warn("Error unlocking since it is already released.", ex); } } }
@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); } }