Remove backport concurrency code

Backport concurrency code is no longer needed as JDK 1.5 is now a minimum requirement.  Removing JdkBackportConcurrentConversationLock has also 
removed the need for the package scoped ConversationLockFactory interface, 
this has been replaced with a factory method in
SessionBindingConversationManager.

Issues: SWF-1532
This commit is contained in:
Phillip Webb
2012-04-05 12:24:12 -07:00
parent ca20e95b98
commit d3ff99c239
4 changed files with 16 additions and 137 deletions

View File

@@ -87,12 +87,11 @@ class ConversationContainer implements Serializable {
/**
* Create a new conversation based on given parameters and add it to the container.
* @param parameters descriptive conversation parameters
* @param lockFactory the lock factory to use to create the conversation lock
* @param lock the conversation lock
* @return the created conversation
*/
public synchronized Conversation createConversation(ConversationParameters parameters,
ConversationLockFactory lockFactory) {
ContainedConversation conversation = new ContainedConversation(this, nextId(), lockFactory.createLock());
public synchronized Conversation createConversation(ConversationParameters parameters, ConversationLock lock) {
ContainedConversation conversation = new ContainedConversation(this, nextId(), lock);
conversation.putAttribute("name", parameters.getName());
conversation.putAttribute("caption", parameters.getCaption());
conversation.putAttribute("description", parameters.getDescription());
@@ -146,4 +145,4 @@ class ConversationContainer implements Serializable {
private boolean maxExceeded() {
return maxConversations > 0 && conversations.size() > maxConversations;
}
}
}

View File

@@ -1,67 +0,0 @@
/*
* Copyright 2004-2008 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.webflow.conversation.impl;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
/**
* Simple utility class for creating conversation lock instances based on the current execution environment.
*
* @author Keith Donald
* @author Rob Harrop
*/
class ConversationLockFactory {
private static final Log logger = LogFactory.getLog(ConversationLockFactory.class);
private static boolean backportConcurrentPresent;
static {
try {
Class.forName("edu.emory.mathcs.backport.java.util.concurrent.locks.ReentrantLock");
backportConcurrentPresent = true;
} catch (ClassNotFoundException ex) {
backportConcurrentPresent = false;
}
}
private int timeoutSeconds = 30;
/**
* Returns the period of time that can elapse before a lock attempt times out for locks created by this factory.
*/
public int getTimeoutSeconds() {
return timeoutSeconds;
}
/**
* Sets the period of time that can elapse before a lock attempt times out for locks created by this factory.
* @param timeoutSeconds the timeout period in seconds
*/
public void setTimeoutSeconds(int timeoutSeconds) {
this.timeoutSeconds = timeoutSeconds;
}
/**
* When running on Java 1.5+, returns a jdk5 concurrent lock. When running on older JDKs with the
* 'backport-util-concurrent' package available, returns a backport concurrent lock. In all other cases a "no-op"
* lock is returned.
*/
public ConversationLock createLock() {
return new JdkConcurrentConversationLock(timeoutSeconds);
}
}

View File

@@ -1,57 +0,0 @@
/*
* Copyright 2004-2008 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.webflow.conversation.impl;
import org.springframework.webflow.conversation.ConversationLockException;
import edu.emory.mathcs.backport.java.util.concurrent.TimeUnit;
import edu.emory.mathcs.backport.java.util.concurrent.locks.Lock;
import edu.emory.mathcs.backport.java.util.concurrent.locks.ReentrantLock;
/**
* A conversation lock that relies on backport-concurrent. For use on JDK 1.4
*
* @author Keith Donald
* @author Rob Harrop
*/
class JdkBackportConcurrentConversationLock implements ConversationLock {
private Lock lock = new ReentrantLock();
private int timeoutSeconds;
public JdkBackportConcurrentConversationLock(int timeoutSeconds) {
this.timeoutSeconds = timeoutSeconds;
}
public void lock() throws ConversationLockException {
try {
boolean acquired = lock.tryLock(timeoutSeconds, TimeUnit.SECONDS);
if (!acquired) {
throw new LockTimeoutException(timeoutSeconds);
}
} catch (InterruptedException e) {
throw new LockInterruptedException(e);
}
}
/**
* Releases the lock.
*/
public void unlock() {
lock.unlock();
}
}

View File

@@ -53,9 +53,9 @@ public class SessionBindingConversationManager implements ConversationManager {
private int maxConversations = 5;
/**
* The factory for creating conversation lock objects.
* The lock timeout in seconds.
*/
private ConversationLockFactory conversationLockFactory = new ConversationLockFactory();
private int lockTimeoutSeconds = 30;
/**
* Returns the key this conversation manager uses to store conversation data in the session.
@@ -94,22 +94,22 @@ public class SessionBindingConversationManager implements ConversationManager {
* default is 30 seconds.
*/
public int getLockTimeoutSeconds() {
return conversationLockFactory.getTimeoutSeconds();
return lockTimeoutSeconds;
}
/**
* Sets the time period that can elapse before a timeout occurs on an attempt to acquire a conversation lock. The
* default is 30 seconds.
* @param timeoutSeconds the timeout period in seconds
* @param lockTimeoutSeconds the timeout period in seconds
*/
public void setLockTimeoutSeconds(int timeoutSeconds) {
conversationLockFactory.setTimeoutSeconds(timeoutSeconds);
public void setLockTimeoutSeconds(int lockTimeoutSeconds) {
this.lockTimeoutSeconds = lockTimeoutSeconds;
}
// implementing conversation manager
public Conversation beginConversation(ConversationParameters conversationParameters) throws ConversationException {
return getConversationContainer().createConversation(conversationParameters, conversationLockFactory);
return getConversationContainer().createConversation(conversationParameters, createConversationLock());
}
public Conversation getConversation(ConversationId id) throws ConversationException {
@@ -126,6 +126,10 @@ public class SessionBindingConversationManager implements ConversationManager {
// hooks for subclassing
protected ConversationLock createConversationLock() {
return new JdkConcurrentConversationLock(lockTimeoutSeconds);
}
protected ConversationContainer createConversationContainer() {
return new ConversationContainer(maxConversations, sessionKey);
}
@@ -147,4 +151,4 @@ public class SessionBindingConversationManager implements ConversationManager {
return container;
}
}
}
}