com.hazelcast.core
Interface ILock

All Superinterfaces:
DistributedObject, Lock
All Known Implementing Classes:
ClientLockProxy, LockProxy

public interface ILock
extends Lock, DistributedObject

Distributed implementation of Lock.

Example


     Lock mylock = Hazelcast.getLock(mylockobject); mylock.lock();
 try {
      // do something
 } finally {
      mylock.unlock();
 }
 //Lock on Map
      IMap map = Hazelcast.getMap("customers"); map.lock("1");
 try {
      // do something
 } finally {
 map.unlock("1"); }
 

See Also:
Lock

Method Summary
 void forceUnlock()
          Releases the lock regardless of the lock owner.
 Object getKey()
          Deprecated. use DistributedObject.getName() instead.
 int getLockCount()
          Returns re-entrant lock hold count, regardless of lock ownership.
 long getRemainingLeaseTime()
          Returns remaining lease time in milliseconds.
 boolean isLocked()
          Returns whether this lock is locked or not.
 boolean isLockedByCurrentThread()
          Returns whether this lock is locked by current thread or not.
 void lock()
          
 void lock(long leaseTime, TimeUnit timeUnit)
          Acquires the lock for the specified lease time.
 Condition newCondition()
          This method is not implemented! Use newCondition(String) instead.
 ICondition newCondition(String name)
          Returns a new ICondition instance that is bound to this ILock instance with given name.
 boolean tryLock()
          
 boolean tryLock(long time, TimeUnit unit)
          
 void unlock()
          Releases the lock.
 
Methods inherited from interface java.util.concurrent.locks.Lock
lockInterruptibly
 
Methods inherited from interface com.hazelcast.core.DistributedObject
destroy, getId, getName, getPartitionKey, getServiceName
 

Method Detail

getKey

@Deprecated
Object getKey()
Deprecated. use DistributedObject.getName() instead.

Returns the lock object, the key for this lock instance.

Returns:
lock object.

lock

void lock()

Specified by:
lock in interface Lock

tryLock

boolean tryLock()

Specified by:
tryLock in interface Lock

tryLock

boolean tryLock(long time,
                TimeUnit unit)
                throws InterruptedException

Specified by:
tryLock in interface Lock
Throws:
InterruptedException

unlock

void unlock()
Releases the lock.

Specified by:
unlock in interface Lock

lock

void lock(long leaseTime,
          TimeUnit timeUnit)
Acquires the lock for the specified lease time.

After lease time, lock will be released..

If the lock is not available then the current thread becomes disabled for thread scheduling purposes and lies dormant until the lock has been acquired.

Parameters:
leaseTime - time to wait before releasing the lock.
timeUnit - unit of time for the lease time.
Throws:
IllegalMonitorStateException - if the current thread does not hold this lock

forceUnlock

void forceUnlock()
Releases the lock regardless of the lock owner. It always successfully unlocks, never blocks, and returns immediately.


newCondition

Condition newCondition()
This method is not implemented! Use newCondition(String) instead.

Specified by:
newCondition in interface Lock
Throws:
UnsupportedOperationException

newCondition

ICondition newCondition(String name)
Returns a new ICondition instance that is bound to this ILock instance with given name.

Before waiting on the condition the lock must be held by the current thread. A call to Condition.await() will atomically release the lock before waiting and re-acquire the lock before the wait returns.

Parameters:
name - identifier of the new condition instance
Returns:
A new ICondition instance for this ILock instance
Throws:
NullPointerException - if name is null.

isLocked

boolean isLocked()
Returns whether this lock is locked or not.

Returns:
true if this lock is locked, false otherwise.

isLockedByCurrentThread

boolean isLockedByCurrentThread()
Returns whether this lock is locked by current thread or not.

Returns:
true if this lock is locked by current thread, false otherwise.

getLockCount

int getLockCount()
Returns re-entrant lock hold count, regardless of lock ownership.

Returns:
the lock hold count.

getRemainingLeaseTime

long getRemainingLeaseTime()
Returns remaining lease time in milliseconds. If the lock is not locked then -1 will be returned.

Returns:
remaining lease time in milliseconds.


Copyright © 2015 Hazelcast, Inc.. All Rights Reserved.