1 /***
2 *
3 * Copyright 2005 LogicBlaze, Inc. http://www.logicblaze.com
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * 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.logicblaze.lingo.lock;
19
20 import edu.emory.mathcs.backport.java.util.concurrent.locks.ReadWriteLock;
21 import edu.emory.mathcs.backport.java.util.concurrent.locks.ReentrantReadWriteLock;
22
23 import javax.jms.JMSException;
24
25 import java.util.HashMap;
26 import java.util.Map;
27
28 /***
29 * A simple implementation which just uses in-JVM locks.
30 *
31 * @version $Revision: 1.1 $
32 */
33 public class NonDeadlockLockManager implements LockManager {
34
35 private Map locks = new HashMap();
36
37 public ReadWriteLock getLock(String id) {
38 ReadWriteLock answer = null;
39 synchronized(locks) {
40 answer = (ReadWriteLock) locks.get(id);
41 if (answer == null) {
42 answer = createLock(id);
43 locks.put(id, answer);
44 }
45 }
46 return answer ;
47 }
48
49 /***
50 * Factory method to create a new read write lock
51 */
52 protected ReadWriteLock createLock(String id) {
53 return new ReentrantReadWriteLock();
54 }
55
56 public void start() throws JMSException {
57 }
58
59 public void stop() throws JMSException {
60 }
61
62 }