@Override public boolean tryLock(long waitMillSec, long leaseMillSec) throws InterruptedException { if (waitMillSec == 0 && leaseMillSec == 0) { return lock.tryLock(); } else if (leaseMillSec == 0) { return lock.tryLock(waitMillSec, TimeUnit.MILLISECONDS); } else if (waitMillSec == 0) { return lock.tryLock(0, TimeUnit.MILLISECONDS, leaseMillSec, TimeUnit.MILLISECONDS); } else { return lock.tryLock(waitMillSec, TimeUnit.MILLISECONDS, leaseMillSec, TimeUnit.MILLISECONDS); } }
@Override public boolean tryLock(long waitMillSec, long leaseMillSec) throws InterruptedException { if (waitMillSec == 0 && leaseMillSec == 0) { return lock.tryLock(); } else if (leaseMillSec == 0) { return lock.tryLock(waitMillSec, TimeUnit.MILLISECONDS); } else if (waitMillSec == 0) { return lock.tryLock(0, TimeUnit.MILLISECONDS, leaseMillSec, TimeUnit.MILLISECONDS); } else { return lock.tryLock(waitMillSec, TimeUnit.MILLISECONDS, leaseMillSec, TimeUnit.MILLISECONDS); } }
@Override public boolean tryLock() { return lock.tryLock(); }
@Override public boolean tryLock() { return lock.tryLock(); }
@Override public void run() { while (!HazelcastNodeInfo.isActive(localMember)) try { //try to become a master HazelcastNodeInfo.setActive(localMember, masterLock.tryLock(3, TimeUnit.MILLISECONDS)); } catch (final InterruptedException e) { HazelcastNodeInfo.setActive(localMember, false); return; } }
public synchronized void tryBecomeCoordinator() { HazelcastInstance hazelcastInstance = EventProcessorValueHolder.getHazelcastInstance(); if (hazelcastInstance != null) { if(!isStormCoordinator()) { ILock lock = hazelcastInstance.getLock("StormCoordinator"); boolean isCoordinator = lock.tryLock(); setStormCoordinator(isCoordinator); if (isCoordinator) { log.info("Node became the Storm coordinator with member id " + myHazelcastId); if (roleToMembershipMap != null){ roleToMembershipMap.put(STORM_HZ_MAP_ACTIVE_MANAGER_KEY, myHazelcastId); } } } } }
private List<KeyIncrementPair> getLocks(List<KeyIncrementPair> potentialLocks) { List<KeyIncrementPair> locked = new ArrayList<KeyIncrementPair>(); for (KeyIncrementPair keyIncrementPair : potentialLocks) { try { ILock lock = getLock(keyIncrementPair); try { if (lock.tryLock(tryLockTimeOutMs, TimeUnit.MILLISECONDS)) { locked.add(keyIncrementPair); localCounter.locked++; } } catch (Exception e) { logger.severe(name + ": trying lock=" + keyIncrementPair.key, e); if (throwException) { throw rethrow(e); } } } catch (Exception e) { logger.severe(name + ": getting lock for locking=" + keyIncrementPair.key, e); if (throwException) { throw rethrow(e); } } } return locked; }
LeaderInitiator.this.lock.tryLock(LeaderInitiator.this.heartBeatMillis, TimeUnit.MILLISECONDS); if (!this.locked) {
if (!lock.tryLock()) return; try {
@TimeStep public void timeStep(BaseThreadState state) { int lockIndex = state.randomInt(lockCount); ILock lock = targetInstance.getLock(name + lockIndex); int leaseTime = 1 + state.randomInt(maxLeaseTimeMillis); int tryTime = 1 + state.randomInt(maxTryTimeMillis); if (state.randomBoolean()) { lock.lock(leaseTime, MILLISECONDS); } else { try { lock.tryLock(tryTime, MILLISECONDS, leaseTime, MILLISECONDS); } catch (InterruptedException e) { logger.info("tryLock() got exception: " + e.getMessage()); } } }
@TimeStep public void timeStep(BaseThreadState state) { int key1 = state.randomInt(maxAccounts); int key2; do { key2 = state.randomInt(maxAccounts); } while (key1 == key2); ILock lock1 = targetInstance.getLock(name + key1); if (lock1.tryLock()) { try { ILock lock2 = targetInstance.getLock(name + key2); if (lock2.tryLock()) { try { IAtomicLong account1 = targetInstance.getAtomicLong(name + key1); IAtomicLong account2 = targetInstance.getAtomicLong(name + key2); int delta = state.randomInt(100); if (account1.get() >= delta) { account1.set(account1.get() - delta); account2.set(account2.get() + delta); } } finally { lock2.unlock(); } } } finally { lock1.unlock(); } } }