KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*-
2  * See the file LICENSE for redistribution information.
3  *
4  * Copyright (c) 2002,2006 Oracle. All rights reserved.
5  *
6  * $Id: Latch.java,v 1.82 2006/10/30 21:14:19 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 public interface Latch {
15
16     /**
17      * Set the latch name, used for latches in objects instantiated from
18      * the log.
19      */

20     public void setName(String JavaDoc name);
21
22     /**
23      * Acquire a latch for exclusive/write access.
24      *
25      * <p>Wait for the latch if some other thread is holding it. If there are
26      * threads waiting for access, they will be granted the latch on a FIFO
27      * basis. When the method returns, the latch is held for exclusive
28      * access.</p>
29      *
30      * @throws LatchException if the latch is already held by the calling
31      * thread.
32      *
33      * @throws RunRecoveryException if an InterruptedException exception
34      * occurs.
35      */

36     public void acquire()
37     throws DatabaseException;
38
39     /**
40      * Acquire a latch for exclusive/write access, but do not block if it's not
41      * available.
42      *
43      * @return true if the latch was acquired, false if it is not available.
44      *
45      * @throws LatchException if the latch is already held by the calling
46      * thread.
47      */

48     public boolean acquireNoWait()
49     throws LatchException;
50
51     /**
52      * Release the latch. If there are other thread(s) waiting for the latch,
53      * one is woken up and granted the latch. If the latch was not owned by
54      * the caller, just return;
55      */

56     public void releaseIfOwner();
57
58     /**
59      * Release the latch. If there are other thread(s) waiting for the latch,
60      * they are woken up and granted the latch.
61      *
62      * @throws LatchNotHeldException if the latch is not currently held.
63      */

64     public void release()
65     throws LatchNotHeldException;
66
67     /**
68      * Return true if the current thread holds this latch.
69      *
70      * @return true if we hold this latch. False otherwise.
71      */

72     public boolean isOwner();
73
74     /**
75      * Used only for unit tests.
76      *
77      * @return the thread that currently holds the latch for exclusive access.
78      */

79     public Thread JavaDoc owner();
80
81     /**
82      * Return the number of threads waiting.
83      *
84      * @return the number of threads waiting for the latch.
85      */

86     public int nWaiters();
87
88     /**
89      * @return a LatchStats object with information about this latch.
90      */

91     public LatchStats getLatchStats();
92
93     /**
94      * Formats a latch owner and waiters.
95      */

96     public String JavaDoc toString();
97 }
98
Popular Tags