KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > springframework > webflow > conversation > impl > UtilConcurrentConversationLock


1 /*
2  * Copyright 2002-2006 the original author or authors.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy 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,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package org.springframework.webflow.conversation.impl;
17
18
19 import org.springframework.core.NestedRuntimeException;
20
21 import EDU.oswego.cs.dl.util.concurrent.ReentrantLock;
22
23 /**
24  * A conversation lock that relies on a {@link ReentrantLock} within Doug Lea's
25  * <a HREF="http://gee.cs.oswego.edu/dl/classes/EDU/oswego/cs/dl/util/concurrent/intro.html">util.concurrent</a>
26  * package. For use on JDK 1.3 and 1.4.
27  *
28  * @author Keith Donald
29  * @author Rob Harrop
30  */

31 class UtilConcurrentConversationLock implements ConversationLock {
32
33     /**
34      * The {@link ReentrantLock} instance.
35      */

36     private final ReentrantLock lock = new ReentrantLock();
37
38     /**
39      * Acquires the lock.
40      * @throws SystemInterruptedException if the lock cannot be acquired due to interruption
41      */

42     public void lock() {
43         try {
44             lock.acquire();
45         }
46         catch (InterruptedException JavaDoc e) {
47             throw new SystemInterruptedException("Unable to acquire lock.", e);
48         }
49     }
50
51     /**
52      * Releases the lock.
53      */

54     public void unlock() {
55         lock.release();
56     }
57     
58     /**
59      * <code>Exception</code> indicating that some {@link Thread} was
60      * {@link Thread#interrupt() interrupted} during processing and as
61      * such processing was halted.
62      * <p>
63      * Only used to wrap the checked {@link InterruptedException java.lang.InterruptedException}.
64      */

65     public static class SystemInterruptedException extends NestedRuntimeException {
66
67         /**
68          * Creates a new <code>SystemInterruptedException</code>.
69          * @param msg the <code>Exception</code> message
70          */

71         public SystemInterruptedException(String JavaDoc msg) {
72             super(msg);
73         }
74
75         /**
76          * Creates a new <code>SystemInterruptedException</code>.
77          * @param msg the <code>Exception</code> message
78          * @param cause the root cause of this <code>Exception</code>
79          */

80         public SystemInterruptedException(String JavaDoc msg, Throwable JavaDoc cause) {
81             super(msg, cause);
82         }
83     }
84 }
Popular Tags