com.sleepycat.je.latch
Class Java5SharedLatchImpl

java.lang.Object
  extended by java.util.concurrent.locks.ReentrantReadWriteLock
      extended by com.sleepycat.je.latch.Java5SharedLatchImpl
All Implemented Interfaces:
SharedLatch, java.io.Serializable, java.util.concurrent.locks.ReadWriteLock

 class Java5SharedLatchImpl
extends java.util.concurrent.locks.ReentrantReadWriteLock
implements SharedLatch

Java5SharedLatchImpl provides an implementation of the SharedLatch interface. By using a wrapper class we can avoid link errors when we run in Java 1.4 JVMs. LatchSupport will only reference this class if it knows that the ReentrantReadWriteLock class is available at runtime through Class.forName(). LatchSupport only references this class through the SharedLatch interface and only constructs this using Class.forName("Java5SharedLatchImpl").newInstance();


Nested Class Summary
 
Nested classes/interfaces inherited from class java.util.concurrent.locks.ReentrantReadWriteLock
java.util.concurrent.locks.ReentrantReadWriteLock.ReadLock, java.util.concurrent.locks.ReentrantReadWriteLock.WriteLock
 
Constructor Summary
Java5SharedLatchImpl()
           
 
Method Summary
 void acquireExclusive()
          Acquire a latch for exclusive/write access.
 boolean acquireExclusiveNoWait()
          Probe a latch for exclusive access, but don't block if it's not available.
 void acquireShared()
          Acquire a latch for shared/read access.
 boolean isOwner()
          Return true if this thread is an owner, reader, or write.
 void release()
          Release an exclusive or shared latch.
 void releaseIfOwner()
          Release the latch.
 void setExclusiveOnly(boolean exclusiveOnly)
          Indicate whether this latch can only be set exclusively (not shared).
 void setName(java.lang.String name)
          Set the latch name, used for latches in objects instantiated from the log.
 boolean setNoteLatch(boolean noteLatch)
          If noteLatch is true, then track latch usage in the latchTable.
 
Methods inherited from class java.util.concurrent.locks.ReentrantReadWriteLock
getOwner, getQueuedReaderThreads, getQueuedThreads, getQueuedWriterThreads, getQueueLength, getReadHoldCount, getReadLockCount, getWaitingThreads, getWaitQueueLength, getWriteHoldCount, hasQueuedThread, hasQueuedThreads, hasWaiters, isFair, isWriteLocked, isWriteLockedByCurrentThread, readLock, toString, writeLock
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface com.sleepycat.je.latch.SharedLatch
isWriteLockedByCurrentThread
 

Constructor Detail

Java5SharedLatchImpl

Java5SharedLatchImpl()
Method Detail

setExclusiveOnly

public void setExclusiveOnly(boolean exclusiveOnly)
Description copied from interface: SharedLatch
Indicate whether this latch can only be set exclusively (not shared). Used for BIN latches that are Shared, but should only be latched exclusively.

Specified by:
setExclusiveOnly in interface SharedLatch

setName

public void setName(java.lang.String name)
Set the latch name, used for latches in objects instantiated from the log.

Specified by:
setName in interface SharedLatch

setNoteLatch

public boolean setNoteLatch(boolean noteLatch)
If noteLatch is true, then track latch usage in the latchTable. Always return true so this can be called as an assert.

Specified by:
setNoteLatch in interface SharedLatch

acquireExclusive

public void acquireExclusive()
                      throws DatabaseException
Acquire a latch for exclusive/write access. Wait for the latch if some other thread is holding it. If there are threads waiting for access, they will be granted the latch on a FIFO basis if fair latches are set. When the method returns, the latch is held for exclusive access.

Specified by:
acquireExclusive in interface SharedLatch
Throws:
LatchException - if the latch is already held by the current thread for exclusive access.
DatabaseException

acquireExclusiveNoWait

public boolean acquireExclusiveNoWait()
                               throws DatabaseException
Description copied from interface: SharedLatch
Probe a latch for exclusive access, but don't block if it's not available.

Specified by:
acquireExclusiveNoWait in interface SharedLatch
Returns:
true if the latch was acquired, false if it is not available.
Throws:
LatchException - if the latch is already held by the calling thread.
DatabaseException

acquireShared

public void acquireShared()
                   throws DatabaseException
Acquire a latch for shared/read access.

Specified by:
acquireShared in interface SharedLatch
Throws:
RunRecoveryException - if an InterruptedException exception occurs.
DatabaseException

isOwner

public boolean isOwner()
Description copied from interface: SharedLatch
Return true if this thread is an owner, reader, or write.

Specified by:
isOwner in interface SharedLatch

release

public void release()
             throws LatchNotHeldException
Release an exclusive or shared latch. If there are other thread(s) waiting for the latch, they are woken up and granted the latch.

Specified by:
release in interface SharedLatch
Throws:
LatchNotHeldException

releaseIfOwner

public void releaseIfOwner()
                    throws LatchNotHeldException
Description copied from interface: SharedLatch
Release the latch. If there are other thread(s) waiting for the latch, one is woken up and granted the latch. If the latch was not owned by the caller, just return.

Specified by:
releaseIfOwner in interface SharedLatch
Throws:
LatchNotHeldException


Copyright 2004,2008 Oracle. All rights reserved.