KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > tomcat > jni > Lock


1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */

17
18 package org.apache.tomcat.jni;
19
20 /** Lock
21  *
22  * @author Mladen Turk
23  * @version $Revision: 467222 $, $Date: 2006-10-24 05:17:11 +0200 (mar., 24 oct. 2006) $
24  */

25
26 public class Lock {
27
28     /**
29      * Enumerated potential types for APR process locking methods
30      * <br /><b>Warning :</b> Check APR_HAS_foo_SERIALIZE defines to see if the platform supports
31      * APR_LOCK_foo. Only APR_LOCK_DEFAULT is portable.
32      */

33
34     public static final int APR_LOCK_FCNTL = 0; /** fcntl() */
35     public static final int APR_LOCK_FLOCK = 1; /** flock() */
36     public static final int APR_LOCK_SYSVSEM = 2; /** System V Semaphores */
37     public static final int APR_LOCK_PROC_PTHREAD = 3; /** POSIX pthread process-based locking */
38     public static final int APR_LOCK_POSIXSEM = 4; /** POSIX semaphore process-based locking */
39     public static final int APR_LOCK_DEFAULT = 5; /** Use the default process lock */
40
41     /**
42      * Create and initialize a mutex that can be used to synchronize processes.
43      * <br /><b>Warning :</b> Check APR_HAS_foo_SERIALIZE defines to see if the platform supports
44      * APR_LOCK_foo. Only APR_LOCK_DEFAULT is portable.
45      * @param fname A file name to use if the lock mechanism requires one. This
46      * argument should always be provided. The lock code itself will
47      * determine if it should be used.
48      * @param mech The mechanism to use for the interprocess lock, if any; one of
49      * <PRE>
50      * APR_LOCK_FCNTL
51      * APR_LOCK_FLOCK
52      * APR_LOCK_SYSVSEM
53      * APR_LOCK_POSIXSEM
54      * APR_LOCK_PROC_PTHREAD
55      * APR_LOCK_DEFAULT pick the default mechanism for the platform
56      * </PRE>
57      * @param pool the pool from which to allocate the mutex.
58      * @return Newly created mutex.
59      */

60     public static native long create(String JavaDoc fname, int mech, long pool)
61         throws Error JavaDoc;
62
63     /**
64      * Re-open a mutex in a child process.
65      * This function must be called to maintain portability, even
66      * if the underlying lock mechanism does not require it.
67      * @param fname A file name to use if the mutex mechanism requires one. This
68      * argument should always be provided. The mutex code itself will
69      * determine if it should be used. This filename should be the
70      * same one that was passed to apr_proc_mutex_create().
71      * @param pool The pool to operate on.
72      * @return Newly opened mutex.
73      */

74     public static native long childInit(String JavaDoc fname, long pool)
75         throws Error JavaDoc;
76
77     /**
78      * Acquire the lock for the given mutex. If the mutex is already locked,
79      * the current thread will be put to sleep until the lock becomes available.
80      * @param mutex the mutex on which to acquire the lock.
81      */

82     public static native int lock(long mutex);
83
84     /**
85      * Attempt to acquire the lock for the given mutex. If the mutex has already
86      * been acquired, the call returns immediately with APR_EBUSY. Note: it
87      * is important that the APR_STATUS_IS_EBUSY(s) macro be used to determine
88      * if the return value was APR_EBUSY, for portability reasons.
89      * @param mutex the mutex on which to attempt the lock acquiring.
90      */

91     public static native int trylock(long mutex);
92
93     /**
94      * Release the lock for the given mutex.
95      * @param mutex the mutex from which to release the lock.
96      */

97     public static native int unlock(long mutex);
98
99     /**
100      * Destroy the mutex and free the memory associated with the lock.
101      * @param mutex the mutex to destroy.
102      */

103     public static native int destroy(long mutex);
104
105     /**
106      * Return the name of the lockfile for the mutex, or NULL
107      * if the mutex doesn't use a lock file
108      */

109     public static native String JavaDoc lockfile(long mutex);
110
111     /**
112      * Display the name of the mutex, as it relates to the actual method used.
113      * This matches the valid options for Apache's AcceptMutex directive
114      * @param mutex the name of the mutex
115      */

116     public static native String JavaDoc name(long mutex);
117
118     /**
119      * Display the name of the default mutex: APR_LOCK_DEFAULT
120      */

121     public static native String JavaDoc defname();
122
123 }
124
Popular Tags