KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > quartz > impl > jdbcjobstore > Semaphore


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

17
18 /*
19  * Previously Copyright (c) 2001-2004 James House
20  */

21 package org.quartz.impl.jdbcjobstore;
22
23 import java.sql.Connection JavaDoc;
24
25 /**
26  * An interface for providing thread/resource locking in order to protect
27  * resources from being altered by multiple threads at the same time.
28  *
29  * @author jhouse
30  */

31 public interface Semaphore {
32
33     /*
34      * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
35      *
36      * Interface.
37      *
38      * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
39      */

40
41     /**
42      * Grants a lock on the identified resource to the calling thread (blocking
43      * until it is available).
44      *
45      * @param conn Database connection used to establish lock. Can be null if
46      * <code>{@link #requiresConnection()}</code> returns false.
47      *
48      * @return true if the lock was obtained.
49      */

50     boolean obtainLock(Connection JavaDoc conn, String JavaDoc lockName) throws LockException;
51
52     /**
53      * Release the lock on the identified resource if it is held by the calling
54      * thread.
55
56      * @param conn Database connection used to establish lock. Can be null if
57      * <code>{@link #requiresConnection()}</code> returns false.
58      */

59     void releaseLock(Connection JavaDoc conn, String JavaDoc lockName) throws LockException;
60
61     /**
62      * Determine whether the calling thread owns a lock on the identified
63      * resource.
64
65      * @param conn Database connection used to establish lock. Can be null if
66      * <code>{@link #requiresConnection()}</code> returns false.
67      */

68     boolean isLockOwner(Connection JavaDoc conn, String JavaDoc lockName) throws LockException;
69
70     /**
71      * Whether this Semaphore implementation requires a database connection for
72      * its lock management operations.
73      *
74      * @see #isLockOwner(Connection, String)
75      * @see #obtainLock(Connection, String)
76      * @see #releaseLock(Connection, String)
77      */

78     boolean requiresConnection();
79 }
80
Popular Tags