NetKernel APIs


com.ten60.netkernel.util
Class AsynchLock

java.lang.Object
  extended bycom.ten60.netkernel.util.AsynchLock

public class AsynchLock
extends Object

Atomic lock request and aquire. unlock might return a released previously unaquired lock request if one exists.
not thread safe- external synchronization must be provided.


Constructor Summary
AsynchLock(int aKeyCount, int aContentionCount)
          Creates a new instance of AsynchLock
 
Method Summary
 Iterator getPendingReferences()
          returns an iterator over all pending lock request references
 boolean lock(Object aKey, Object aReference)
          Attempt to gain an exclusive lock on the given key, takes a reference object to hang onto if the lock fails to be granted that is then returned on an unlock when the lock has been granted
 Object unlock(Object aKey)
          releases a lock on the given key, this method must only be called after a lock has been granted.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AsynchLock

public AsynchLock(int aKeyCount,
                  int aContentionCount)
Creates a new instance of AsynchLock

Parameters:
aKeyCount - size to make lock map
aContentionCount - expected lock contention count- so as to allocate a list long enough to hold them without needing to expand
Method Detail

lock

public boolean lock(Object aKey,
                    Object aReference)
Attempt to gain an exclusive lock on the given key, takes a reference object to hang onto if the lock fails to be granted that is then returned on an unlock when the lock has been granted

Parameters:
aKey - the key object that we want to gain an exclusive lock on
aReference - a reference object for the request to lock
Returns:
true if the lock has been granted, false if not

unlock

public Object unlock(Object aKey)
releases a lock on the given key, this method must only be called after a lock has been granted. The returned lock request reference must be acted on by the client and not ignored.

Parameters:
aKey - the key object that we are releasing the exclusive lock on
Returns:
a lock request reference object to a previously ungranted lock request, null if there is none.

getPendingReferences

public Iterator getPendingReferences()
returns an iterator over all pending lock request references


NetKernel APIs


Copyright © 2002-2004 1060 Research Ltd. All Rights Reserved.