code review of ams fix

This commit is contained in:
Keith Donald
2008-11-05 11:55:16 +00:00
parent 9bf63fa36d
commit cee30f62ee
8 changed files with 45 additions and 16 deletions

View File

@@ -87,4 +87,9 @@ public interface FlowDefinition extends Annotated {
*/
public boolean inDevelopment();
/**
* Destroy this flow definition, releasing any resources. After the flow is destroyed it cannot be started again.
*/
public void destroy();
}

View File

@@ -56,4 +56,11 @@ public interface FlowDefinitionHolder {
*/
public void refresh() throws FlowDefinitionConstructionException;
/**
* Indicates that the system is being shutdown and any resources flow resources should be released. After this
* method is called, calls to {@link #getFlowDefinition()} are undefined. Should only be called once. May be a no-op
* if the held flow was never constructed to begin with.
*/
public void destroy();
}

View File

@@ -21,9 +21,6 @@ import java.util.TreeMap;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.DisposableBean;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.core.style.ToStringCreator;
import org.springframework.util.Assert;
import org.springframework.webflow.definition.FlowDefinition;
@@ -34,7 +31,7 @@ import org.springframework.webflow.definition.FlowDefinition;
* @author Keith Donald
* @author Scott Andrews
*/
public class FlowDefinitionRegistryImpl implements FlowDefinitionRegistry, DisposableBean {
public class FlowDefinitionRegistryImpl implements FlowDefinitionRegistry {
private static final Log logger = LogFactory.getLog(FlowDefinitionRegistryImpl.class);
@@ -106,17 +103,10 @@ public class FlowDefinitionRegistryImpl implements FlowDefinitionRegistry, Dispo
registerFlowDefinition(new StaticFlowDefinitionHolder(definition));
}
// implementing DisposableBean
public void destroy() throws Exception {
Iterator flowDefinitionKeyIt = flowDefinitions.keySet().iterator();
while (flowDefinitionKeyIt.hasNext()) {
FlowDefinitionHolder holder = this.getFlowDefinitionHolder((String) flowDefinitionKeyIt.next());
FlowDefinition flowDefinition = holder.getFlowDefinition();
ApplicationContext context = flowDefinition.getApplicationContext();
if (context instanceof ConfigurableApplicationContext) {
((ConfigurableApplicationContext) context).close();
}
public void destroy() {
Iterator it = flowDefinitions.keySet().iterator();
while (it.hasNext()) {
getFlowDefinitionHolder((String) it.next()).destroy();
}
}

View File

@@ -53,6 +53,10 @@ class StaticFlowDefinitionHolder implements FlowDefinitionHolder {
// nothing to do
}
public void destroy() {
flowDefinition.destroy();
}
public boolean equals(Object o) {
if (!(o instanceof StaticFlowDefinitionHolder)) {
return false;

View File

@@ -28,6 +28,7 @@ import org.apache.commons.logging.LogFactory;
import org.springframework.binding.mapping.Mapper;
import org.springframework.binding.mapping.MappingResults;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.core.style.StylerUtils;
import org.springframework.core.style.ToStringCreator;
import org.springframework.util.Assert;
@@ -591,6 +592,12 @@ public class Flow extends AnnotatedObject implements FlowDefinition {
}
}
public void destroy() {
if (applicationContext != null && applicationContext instanceof ConfigurableApplicationContext) {
((ConfigurableApplicationContext) applicationContext).close();
}
}
/**
* Handle an exception that occurred during an execution of this flow.
* @param exception the exception that occurred

View File

@@ -42,7 +42,7 @@ public class DefaultFlowHolder implements FlowDefinitionHolder {
private static final Log logger = LogFactory.getLog(DefaultFlowHolder.class);
/**
* The flow definition assembled by this assembler.
* The flow definition assembled by this assembler, initially null.
*/
private FlowDefinition flowDefinition;
@@ -95,6 +95,12 @@ public class DefaultFlowHolder implements FlowDefinitionHolder {
assembleFlow();
}
public void destroy() {
if (flowDefinition != null) {
flowDefinition.destroy();
}
}
// internal helpers
private void assembleFlow() throws FlowDefinitionConstructionException {

View File

@@ -143,6 +143,10 @@ public class FlowDefinitionRegistryImplTests extends TestCase {
public boolean inDevelopment() {
return false;
}
public void destroy() {
}
}
private static class BarFlow implements FlowDefinition {
@@ -188,5 +192,8 @@ public class FlowDefinitionRegistryImplTests extends TestCase {
return false;
}
public void destroy() {
}
}
}

View File

@@ -130,6 +130,9 @@ public class FlowHandlerMappingTests extends TestCase {
throw new UnsupportedOperationException("Auto-generated method stub");
}
public void destroy() {
}
}
public static class CustomFlowHandler implements FlowHandler {