KickJava   Java API By Example, From Geeks To Geeks.

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


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 import org.apache.commons.logging.Log;
19 import org.apache.commons.logging.LogFactory;
20 import org.springframework.core.JdkVersion;
21
22 /**
23  * Simple utility class for creating conversation lock instances based on the
24  * current execution environment.
25  *
26  * @author Keith Donald
27  * @author Rob Harrop
28  */

29 public class ConversationLockFactory {
30
31     private static final Log logger = LogFactory.getLog(ConversationLockFactory.class);
32
33     private static boolean utilConcurrentPresent;
34
35     static {
36         try {
37             Class.forName("EDU.oswego.cs.dl.util.concurrent.ReentrantLock");
38             utilConcurrentPresent = true;
39         }
40         catch (ClassNotFoundException JavaDoc ex) {
41             utilConcurrentPresent = false;
42         }
43     }
44
45     /**
46      * When running on Java 1.5+, returns a jdk5 concurrent lock. When running on older JDKs with
47      * the 'util.concurrent' package available, returns a util concurrent lock.
48      * In all other cases a "no-op" lock is returned.
49      */

50     public static ConversationLock createLock() {
51         if (JdkVersion.getMajorJavaVersion() >= JdkVersion.JAVA_15) {
52             return new JdkConcurrentConversationLock();
53         }
54         else if (utilConcurrentPresent) {
55             return new UtilConcurrentConversationLock();
56         }
57         else {
58             logger.warn("Unable to enable conversation locking. Switch to Java 5 or above, "
59                     + "or put the 'util.concurrent' package on the classpath "
60                     + "to enable locking in your environment.");
61             return NoOpConversationLock.INSTANCE;
62         }
63     }
64 }
Popular Tags