KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sleepycat > je > latch > SharedLatch


1 /*-
2  * See the file LICENSE for redistribution information.
3  *
4  * Copyright (c) 2002,2006 Oracle. All rights reserved.
5  *
6  * $Id: SharedLatch.java,v 1.17 2006/10/30 21:14:20 bostic Exp $
7  */

8
9 package com.sleepycat.je.latch;
10
11 import com.sleepycat.je.DatabaseException;
12 import com.sleepycat.je.RunRecoveryException;
13
14 /**
15  * Simple thread-based non-transactional reader-writer/shared-exclusive latch.
16  *
17  * Latches provide simple exclusive or shared transient locks on objects.
18  * Latches are expected to be held for short, defined periods of time. No
19  * deadlock detection is provided so it is the caller's responsibility to
20  * sequence latch acquisition in an ordered fashion to avoid deadlocks.
21  */

22 public interface SharedLatch {
23
24     /**
25      * Set the latch name, used for latches in objects instantiated from the
26      * log.
27      */

28     public void setName(String JavaDoc name);
29
30     /**
31      * Indicate whether this latch should be tracked in the debugging
32      * LatchSupport.latchTable.
33      * Always return true so this can be called under an assert.
34      */

35     public boolean setNoteLatch(boolean noteLatch);
36
37     /**
38      * Indicate whether this latch can only be set exclusively (not shared).
39      * Used for BIN latches that are Shared, but should only be latched
40      * exclusively.
41      */

42     public void setExclusiveOnly(boolean exclusiveOnly);
43
44     /**
45      * Acquire a latch for exclusive/write access. If the thread already holds
46      * the latch for shared access, it cannot be upgraded and LatchException
47      * will be thrown.
48      *
49      * Wait for the latch if some other thread is holding it. If there are
50      * threads waiting for access, they will be granted the latch on a FIFO
51      * basis if fair latches are enabled. When the method returns, the latch
52      * is held for exclusive access.
53      *
54      * @throws LatchException if the latch is already held by the current
55      * thread for shared access.
56      */

57     public void acquireExclusive()
58     throws DatabaseException;
59
60     /**
61      * Probe a latch for exclusive access, but don't block if it's not
62      * available.
63      *
64      * @return true if the latch was acquired, false if it is not available.
65      *
66      * @throws LatchException if the latch is already held by the calling
67      * thread.
68      */

69     public boolean acquireExclusiveNoWait()
70     throws DatabaseException;
71
72     /**
73      * Acquire a latch for shared/read access. Nesting is allowed, that is,
74      * the latch may be acquired more than once by the same thread.
75      *
76      * @throws RunRecoveryException if an InterruptedException exception
77      * occurs.
78      */

79     public void acquireShared()
80         throws DatabaseException;
81
82     /**
83      * Release an exclusive or shared latch. If there are other thread(s)
84      * waiting for the latch, they are woken up and granted the latch.
85      */

86     public void release()
87     throws LatchNotHeldException;
88
89     public boolean isWriteLockedByCurrentThread();
90
91     /**
92      * Release the latch. If there are other thread(s) waiting for the latch,
93      * one is woken up and granted the latch. If the latch was not owned by
94      * the caller, just return.
95      */

96     public void releaseIfOwner()
97     throws LatchNotHeldException;
98
99     /**
100      * Return true if this thread is an owner, reader, or write.
101      */

102     public boolean isOwner();
103 }
104
Popular Tags