01: /*
02: * Copyright 2004-2005 OpenSymphony
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License"); you may not
05: * use this file except in compliance with the License. You may obtain a copy
06: * of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
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;
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 conn, String lockName)
51: throws LockException;
52:
53: /**
54: * Release the lock on the identified resource if it is held by the calling
55: * thread.
56:
57: * @param conn Database connection used to establish lock. Can be null if
58: * <code>{@link #requiresConnection()}</code> returns false.
59: */
60: void releaseLock(Connection conn, String lockName)
61: throws LockException;
62:
63: /**
64: * Determine whether the calling thread owns a lock on the identified
65: * resource.
66:
67: * @param conn Database connection used to establish lock. Can be null if
68: * <code>{@link #requiresConnection()}</code> returns false.
69: */
70: boolean isLockOwner(Connection conn, String lockName)
71: throws LockException;
72:
73: /**
74: * Whether this Semaphore implementation requires a database connection for
75: * its lock management operations.
76: *
77: * @see #isLockOwner(Connection, String)
78: * @see #obtainLock(Connection, String)
79: * @see #releaseLock(Connection, String)
80: */
81: boolean requiresConnection();
82: }
|