com.bigdata.concurrent
Class NamedReadWriteLock<T>

java.lang.Object
  extended by com.bigdata.concurrent.NamedReadWriteLock<T>
Type Parameters:
T - The generic type for the "name". This MUST implement hashCode() and equals() since the instances of this type will serve as keys in a Map.

public class NamedReadWriteLock<T>
extends Object

A factory for named ReadWriteLocks. A simple ReadWriteLock manages access to a single resource. However, a NamedReadWriteLock manages access to the members of a set of named resources. This is more efficient when the latency of the operation once the lock is acquired is significant, e.g., an RMI call or a disk IO.

The locks are stored in a WeakHashMap so that they will be garbage collected if there are no threads waiting in the queue for a given named lock.

Version:
$Id: NamedReadWriteLock.java 2265 2009-10-26 12:51:06Z thompsonbry $
Author:
Bryan Thompson

Constructor Summary
NamedReadWriteLock()
           
 
Method Summary
 Lock acquireReadLock(T name)
          Block until the ReentrantReadWriteLock.ReadLock for the named resource is available, then Lock.lock() the Lock and returns the Lock.
 Lock acquireReadLock(T name, long timeout, TimeUnit unit)
           
 Lock acquireWriteLock(T name)
           
 Lock acquireWriteLock(T name, long timeout, TimeUnit unit)
           
protected  ReentrantReadWriteLock lockFactory(T name)
          Return the canonical instance of the lock for a named resource.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

NamedReadWriteLock

public NamedReadWriteLock()
Method Detail

lockFactory

protected ReentrantReadWriteLock lockFactory(T name)
Return the canonical instance of the lock for a named resource.

Parameters:
name - The name.
Returns:
The canonical instance of the lock for that name.

acquireReadLock

public Lock acquireReadLock(T name)
Block until the ReentrantReadWriteLock.ReadLock for the named resource is available, then Lock.lock() the Lock and returns the Lock.

Parameters:
name - The name of the resource whose Lock is desired.
Returns:
The Lock. It will have already been Lock.lock()ed.

acquireReadLock

public Lock acquireReadLock(T name,
                            long timeout,
                            TimeUnit unit)
                     throws InterruptedException,
                            TimeoutException
Throws:
InterruptedException
TimeoutException

acquireWriteLock

public Lock acquireWriteLock(T name)

acquireWriteLock

public Lock acquireWriteLock(T name,
                             long timeout,
                             TimeUnit unit)
                      throws InterruptedException,
                             TimeoutException
Throws:
InterruptedException
TimeoutException


Copyright © 2006-2011 SYSTAP, LLC. All Rights Reserved.