public final class GridCacheLockImpl extends AtomicDataStructureProxy<GridCacheLockState> implements GridCacheLockEx, IgniteChangeGlobalStateSupport, Externalizable
| Constructor and Description |
|---|
GridCacheLockImpl()
Empty constructor required by
Externalizable. |
GridCacheLockImpl(String name,
GridCacheInternalKey key,
IgniteInternalCache<GridCacheInternalKey,GridCacheLockState> lockView)
Constructor.
|
| Modifier and Type | Method and Description |
|---|---|
void |
close()
Removes reentrant lock.
|
int |
getHoldCount()
Queries the number of holds on this lock by the current thread.
|
IgniteCondition |
getOrCreateCondition(String name)
Returns a
Condition instance for use with this
IgniteLock instance. |
int |
getWaitQueueLength(IgniteCondition condition)
Returns an estimate of the number of threads on this node that are waiting on the
given condition associated with this lock.
|
boolean |
hasQueuedThread(Thread thread)
Queries whether the given thread is waiting to acquire this
lock.
|
boolean |
hasQueuedThreads()
Queries whether any threads on this node are waiting to acquire this lock.
|
boolean |
hasWaiters(IgniteCondition condition)
Queries whether any threads on this node are waiting on the given condition
associated with this lock.
|
boolean |
isBroken()
Returns true if any node that owned the locked failed before releasing the lock.
|
boolean |
isFailoverSafe()
Returns
true if this lock is safe to use after node failure. |
boolean |
isFair()
Returns
true if this lock is fair. |
boolean |
isHeldByCurrentThread()
Queries if this lock is held by the current thread.
|
boolean |
isLocked()
Queries if this lock is held by any thread on any node.
|
void |
lock()
Acquires the distributed reentrant lock.
|
void |
lockInterruptibly()
Acquires the lock unless the current thread is
interrupted.
|
void |
needCheckNotRemoved() |
Condition |
newCondition()
This method is not supported in IgniteLock,
Any invocation of this method will result in UnsupportedOperationException.
|
void |
onNodeRemoved(UUID nodeId)
Callback to notify semaphore on topology changes.
|
void |
onStop()
Callback to notify local reentrant lock instance on node stop.
|
void |
onUpdate(GridCacheLockState val)
Callback to notify reentrant lock on changes.
|
void |
readExternal(ObjectInput in) |
String |
toString() |
boolean |
tryLock()
Acquires the lock only if it is free at the time of invocation.
|
boolean |
tryLock(long timeout,
TimeUnit unit)
Acquires the lock if it is not held by another thread within the given
waiting time and the current thread has not been
interrupted.
|
void |
unlock()
Releases the lock.
|
void |
writeExternal(ObjectOutput out) |
checkRemoved, invalidateLocalState, key, name, onActivate, onDeActivate, onRemoved, removed, restart, suspendclone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitkeyname, removedonRemoved, restart, suspendonActivate, onDeActivatepublic GridCacheLockImpl()
Externalizable.public GridCacheLockImpl(String name, GridCacheInternalKey key, IgniteInternalCache<GridCacheInternalKey,GridCacheLockState> lockView)
name - Reentrant lock name.key - Reentrant lock key.lockView - Reentrant lock projection.public void onUpdate(GridCacheLockState val)
onUpdate in interface GridCacheLockExval - New reentrant lock state.public void onNodeRemoved(UUID nodeId)
onNodeRemoved in interface GridCacheLockExnodeId - Id of the node that left the grid.public void onStop()
onStop in interface GridCacheLockExpublic void lock()
Acquires the lock if it is not held by another thread and returns immediately, setting the lock hold count to one.
If the current thread already holds this lock then the hold count is incremented by one and the method returns immediately.
If the lock is held by another thread then the current thread becomes disabled for thread scheduling purposes and lies dormant until one of four things happens:
lock in interface Locklock in interface IgniteLockpublic void lockInterruptibly()
throws IgniteInterruptedException
Acquires the lock if it is not held by another thread and returns immediately, setting the lock hold count to one.
If the current thread already holds this lock then the hold count is incremented by one and the method returns immediately.
If the lock is held by another thread then the current thread becomes disabled for thread scheduling purposes and lies dormant until one of four things happens:
If the lock is acquired by the current thread then the lock hold count is set to one.
If the current thread:
IgniteInterruptedException is thrown and the current thread's
interrupted status is cleared.
IgniteException is thrown in case:
In this implementation, as this method is an explicit interruption point, preference is given to responding to the interrupt over normal or reentrant acquisition of the lock.
lockInterruptibly in interface LocklockInterruptibly in interface IgniteLockIgniteInterruptedException - if the current thread is interruptedpublic boolean tryLock()
Acquires the lock if it is available and returns immediately
with the value true.
If the lock is not available then this method will return
immediately with the value false.
A typical usage idiom for this method would be:
Lock lock = ...;
if (lock.tryLock()) {
try {
// manipulate protected state
} finally {
lock.unlock();
}
} else {
// perform alternative actions
}
This usage ensures that the lock is unlocked if it was acquired, and
doesn't try to unlock if the lock was not acquired.
If node is stopped, or any node failed while owning the lock in non-failoverSafe mode,
then IgniteException is thrown.tryLock in interface LocktryLock in interface IgniteLocktrue if the lock was acquired and
false otherwisepublic boolean tryLock(long timeout,
TimeUnit unit)
throws IgniteInterruptedException
Acquires the lock if it is not held by another thread and returns
immediately with the value true, setting the lock hold count
to one.
If the current thread
already holds this lock then the hold count is incremented by one and
the method returns true.
If the lock is held by another thread then the current thread becomes disabled for thread scheduling purposes and lies dormant until one of five things happens:
If the lock is acquired then the value true is returned and
the lock hold count is set to one.
If the current thread:
IgniteInterruptedException is thrown and the current thread's
interrupted status is cleared.
IgniteException is thrown in case:
If the specified waiting time elapses then the value false
is returned. If the time is less than or equal to zero, the method
will not wait at all.
In this implementation, as this method is an explicit interruption point, preference is given to responding to the interrupt over normal or reentrant acquisition of the lock, and over reporting the elapse of the waiting time.
tryLock in interface LocktryLock in interface IgniteLocktimeout - the time to wait for the lockunit - the time unit of the timeout argumenttrue if the lock was free and was acquired by the
current thread, or the lock was already held by the current
thread; and false if the waiting time elapsed before
the lock could be acquiredIgniteInterruptedException - if the current thread is interruptedpublic void unlock()
IllegalMonitorStateException is thrown.
If lock is already broken prior to invocation of this method, and
lock is created in non-failover safe mode, then IgniteException is thrown.unlock in interface Lockunlock in interface IgniteLock@NotNull public Condition newCondition()
IgniteLocknewCondition in interface LocknewCondition in interface IgniteLockpublic IgniteCondition getOrCreateCondition(String name)
Condition instance for use with this
IgniteLock instance.
Condition
waiting or signalling methods are called, then an IllegalMonitorStateException is thrown.
IgniteInterruptedException will be thrown, and the thread's
interrupted status will be cleared.
getOrCreateCondition in interface IgniteLockname - Name of the distributed condition objectpublic int getHoldCount()
getHoldCount in interface IgniteLockpublic boolean isHeldByCurrentThread()
isHeldByCurrentThread in interface IgniteLocktrue if current thread holds this lock and
false otherwisepublic boolean isLocked()
isLocked in interface IgniteLocktrue if any thread on this or any other node holds this lock and
false otherwisepublic boolean hasQueuedThreads()
true
return does not guarantee that any other thread will ever
acquire this lock. This method is designed primarily for use in
monitoring of the system state.hasQueuedThreads in interface IgniteLocktrue if there may be other threads on this node waiting to
acquire the lockpublic boolean hasQueuedThread(Thread thread)
true return does not guarantee that this thread
will ever acquire this lock. This method is designed primarily for use
in monitoring of the system state.hasQueuedThread in interface IgniteLockthread - the threadtrue if the given thread is queued waiting for this lockpublic boolean hasWaiters(IgniteCondition condition)
true return does
not guarantee that a future signal will awaken any
threads. This method is designed primarily for use in
monitoring of the system state.hasWaiters in interface IgniteLockcondition - the conditiontrue if there are any waiting threads on this nodepublic int getWaitQueueLength(IgniteCondition condition)
getWaitQueueLength in interface IgniteLockcondition - the conditionpublic boolean isFailoverSafe()
IgniteLocktrue if this lock is safe to use after node failure.
If not, IgniteInterruptedException is thrown on every other node after node failure.isFailoverSafe in interface IgniteLocktrue if this reentrant lock has failoverSafe set truepublic boolean isFair()
IgniteLocktrue if this lock is fair. Fairness flag can only be set on lock creation.isFair in interface IgniteLocktrue if this reentrant lock has fairness flag set true.public boolean isBroken()
isBroken in interface IgniteLockpublic void needCheckNotRemoved()
needCheckNotRemoved in interface GridCacheRemovableneedCheckNotRemoved in class AtomicDataStructureProxy<GridCacheLockState>public void writeExternal(ObjectOutput out) throws IOException
writeExternal in interface ExternalizableIOExceptionpublic void readExternal(ObjectInput in) throws IOException, ClassNotFoundException
readExternal in interface ExternalizableIOExceptionClassNotFoundExceptionpublic void close()
close in interface Closeableclose in interface AutoCloseableclose in interface IgniteLock
Follow @ApacheIgnite
Ignite Fabric : ver. 2.6.0 Release Date : July 10 2018