/** * Checks if latest call to acquire/release was called on this node. * Should only be called from update method. * * @param newOwnerID ID of the node that is about to acquire this lock (or null). * @return true if acquire/release that triggered last update came from this node. */ protected boolean isLockedLocally(UUID newOwnerID) { return thisNode.equals(getOwnerNode()) || thisNode.equals(newOwnerID); }
/** Interrupt every thread on this node waiting on this lock. */ private synchronized void interruptAll() { // First release all threads waiting on associated condition queues. if (!conditionMap.isEmpty()) { // Temporarily obtain ownership of the lock, // in order to signal all conditions. UUID tempUUID = getOwnerNode(); long tempThreadID = currentOwnerThreadId; setCurrentOwnerNode(thisNode); currentOwnerThreadId = Thread.currentThread().getId(); for (Condition c : conditionMap.values()) c.signalAll(); // Restore owner node and owner thread. setCurrentOwnerNode(tempUUID); currentOwnerThreadId = tempThreadID; } // Interrupt any future call to acquire/release on this sync object. interruptAll = true; // Interrupt any ongoing transactions. for (Thread t: getQueuedThreads()) t.interrupt(); }
/** {@inheritDoc} */ @Override public void onNodeRemoved(UUID nodeId) { updateLock.lock(); try { if (nodeId.equals(sync.getOwnerNode())) { if (!sync.failoverSafe) { sync.setBroken(true); sync.interruptAll(); } } // Try to notify any waiting threads. sync.release(0); } finally { updateLock.unlock(); } }
synchronized boolean checkIncomingSignals(GridCacheLockState state) { if (state.getSignals() == null) return false; LinkedList<String> signals = state.getSignals().get(thisNode); if (signals == null || signals.isEmpty()) return false; UUID tempUUID = getOwnerNode(); Thread tempThread = getExclusiveOwnerThread(); long tempThreadID = currentOwnerThreadId; // Temporarily allow current thread to signal condition object. // This is safe to do because: // 1. if release was called on this node, // it was called from currently active thread; // 2. if release came from a thread on any other node, // all threads on this node are already blocked. setCurrentOwnerNode(thisNode); setExclusiveOwnerThread(Thread.currentThread()); currentOwnerThreadId = Thread.currentThread().getId(); for (String signal: signals) conditionMap.get(signal).signal(); // Restore owner node and owner thread. setCurrentOwnerNode(tempUUID); setExclusiveOwnerThread(tempThread); currentOwnerThreadId = tempThreadID; return true; }
/** Interrupt every thread on this node waiting on this lock. */ private synchronized void interruptAll() { // First release all threads waiting on associated condition queues. if (!conditionMap.isEmpty()) { // Temporarily obtain ownership of the lock, // in order to signal all conditions. UUID tempUUID = getOwnerNode(); long tempThreadID = currentOwnerThreadId; setCurrentOwnerNode(thisNode); currentOwnerThreadId = Thread.currentThread().getId(); for (Condition c : conditionMap.values()) c.signalAll(); // Restore owner node and owner thread. setCurrentOwnerNode(tempUUID); currentOwnerThreadId = tempThreadID; } // Interrupt any future call to acquire/release on this sync object. interruptAll = true; // Interrupt any ongoing transactions. for (Thread t: getQueuedThreads()) t.interrupt(); }
/** {@inheritDoc} */ @Override public void onNodeRemoved(UUID nodeId) { updateLock.lock(); try { if (nodeId.equals(sync.getOwnerNode())) { if (!sync.failoverSafe) { sync.setBroken(true); sync.interruptAll(); } } // Try to notify any waiting threads. sync.release(0); } finally { updateLock.unlock(); } }
/** * Checks if latest call to acquire/release was called on this node. * Should only be called from update method. * * @param newOwnerID ID of the node that is about to acquire this lock (or null). * @return true if acquire/release that triggered last update came from this node. */ protected boolean isLockedLocally(UUID newOwnerID) { return thisNode.equals(getOwnerNode()) || thisNode.equals(newOwnerID); }
synchronized boolean checkIncomingSignals(GridCacheLockState state) { if (state.getSignals() == null) return false; LinkedList<String> signals = state.getSignals().get(thisNode); if (signals == null || signals.isEmpty()) return false; UUID tempUUID = getOwnerNode(); Thread tempThread = getExclusiveOwnerThread(); long tempThreadID = currentOwnerThreadId; // Temporarily allow current thread to signal condition object. // This is safe to do because: // 1. if release was called on this node, // it was called from currently active thread; // 2. if release came from a thread on any other node, // all threads on this node are already blocked. setCurrentOwnerNode(thisNode); setExclusiveOwnerThread(Thread.currentThread()); currentOwnerThreadId = Thread.currentThread().getId(); for (String signal: signals) conditionMap.get(signal).signal(); // Restore owner node and owner thread. setCurrentOwnerNode(tempUUID); setExclusiveOwnerThread(tempThread); currentOwnerThreadId = tempThreadID; return true; }