01: /*
02: * Copyright 2004-2007 the original author or authors.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy 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,
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: import org.springframework.core.NestedRuntimeException;
19:
20: import EDU.oswego.cs.dl.util.concurrent.ReentrantLock;
21:
22: /**
23: * A conversation lock that relies on a {@link ReentrantLock} within Doug Lea's
24: * <a href="http://gee.cs.oswego.edu/dl/classes/EDU/oswego/cs/dl/util/concurrent/intro.html">util.concurrent</a>
25: * package. For use on JDK 1.3 and 1.4.
26: *
27: * @author Keith Donald
28: * @author Rob Harrop
29: */
30: class UtilConcurrentConversationLock implements ConversationLock {
31:
32: /**
33: * The {@link ReentrantLock} instance.
34: */
35: private final ReentrantLock lock = new ReentrantLock();
36:
37: /**
38: * Acquires the lock.
39: * @throws SystemInterruptedException if the lock cannot be acquired due to interruption
40: */
41: public void lock() {
42: try {
43: lock.acquire();
44: } catch (InterruptedException e) {
45: throw new SystemInterruptedException(
46: "Unable to acquire lock.", e);
47: }
48: }
49:
50: /**
51: * Releases the lock.
52: */
53: public void unlock() {
54: lock.release();
55: }
56:
57: /**
58: * <code>Exception</code> indicating that some {@link Thread} was
59: * {@link Thread#interrupt() interrupted} during processing and as
60: * such processing was halted.
61: * <p>
62: * Only used to wrap the checked {@link InterruptedException java.lang.InterruptedException}.
63: */
64: public static class SystemInterruptedException extends
65: NestedRuntimeException {
66:
67: /**
68: * Creates a new <code>SystemInterruptedException</code>.
69: * @param msg the <code>Exception</code> message
70: */
71: public SystemInterruptedException(String 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 msg, Throwable cause) {
81: super(msg, cause);
82: }
83: }
84: }
|