diff --git a/spring-webflow/src/main/java/org/springframework/webflow/definition/FlowDefinition.java b/spring-webflow/src/main/java/org/springframework/webflow/definition/FlowDefinition.java index 611b6dfa..6b8751ea 100644 --- a/spring-webflow/src/main/java/org/springframework/webflow/definition/FlowDefinition.java +++ b/spring-webflow/src/main/java/org/springframework/webflow/definition/FlowDefinition.java @@ -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(); + } \ No newline at end of file diff --git a/spring-webflow/src/main/java/org/springframework/webflow/definition/registry/FlowDefinitionHolder.java b/spring-webflow/src/main/java/org/springframework/webflow/definition/registry/FlowDefinitionHolder.java index 06dab5c2..6bd67dab 100644 --- a/spring-webflow/src/main/java/org/springframework/webflow/definition/registry/FlowDefinitionHolder.java +++ b/spring-webflow/src/main/java/org/springframework/webflow/definition/registry/FlowDefinitionHolder.java @@ -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(); + } \ No newline at end of file diff --git a/spring-webflow/src/main/java/org/springframework/webflow/definition/registry/FlowDefinitionRegistryImpl.java b/spring-webflow/src/main/java/org/springframework/webflow/definition/registry/FlowDefinitionRegistryImpl.java index 1512f1a0..0219c45e 100644 --- a/spring-webflow/src/main/java/org/springframework/webflow/definition/registry/FlowDefinitionRegistryImpl.java +++ b/spring-webflow/src/main/java/org/springframework/webflow/definition/registry/FlowDefinitionRegistryImpl.java @@ -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(); } } diff --git a/spring-webflow/src/main/java/org/springframework/webflow/definition/registry/StaticFlowDefinitionHolder.java b/spring-webflow/src/main/java/org/springframework/webflow/definition/registry/StaticFlowDefinitionHolder.java index 54bdea99..1b81f7ad 100644 --- a/spring-webflow/src/main/java/org/springframework/webflow/definition/registry/StaticFlowDefinitionHolder.java +++ b/spring-webflow/src/main/java/org/springframework/webflow/definition/registry/StaticFlowDefinitionHolder.java @@ -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; diff --git a/spring-webflow/src/main/java/org/springframework/webflow/engine/Flow.java b/spring-webflow/src/main/java/org/springframework/webflow/engine/Flow.java index a0127dcb..8158d0ff 100644 --- a/spring-webflow/src/main/java/org/springframework/webflow/engine/Flow.java +++ b/spring-webflow/src/main/java/org/springframework/webflow/engine/Flow.java @@ -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 diff --git a/spring-webflow/src/main/java/org/springframework/webflow/engine/builder/DefaultFlowHolder.java b/spring-webflow/src/main/java/org/springframework/webflow/engine/builder/DefaultFlowHolder.java index 83bac39c..ffcaab8f 100644 --- a/spring-webflow/src/main/java/org/springframework/webflow/engine/builder/DefaultFlowHolder.java +++ b/spring-webflow/src/main/java/org/springframework/webflow/engine/builder/DefaultFlowHolder.java @@ -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 { diff --git a/spring-webflow/src/test/java/org/springframework/webflow/definition/registry/FlowDefinitionRegistryImplTests.java b/spring-webflow/src/test/java/org/springframework/webflow/definition/registry/FlowDefinitionRegistryImplTests.java index d625a1fb..9d52566c 100644 --- a/spring-webflow/src/test/java/org/springframework/webflow/definition/registry/FlowDefinitionRegistryImplTests.java +++ b/spring-webflow/src/test/java/org/springframework/webflow/definition/registry/FlowDefinitionRegistryImplTests.java @@ -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() { + } + } } \ No newline at end of file diff --git a/spring-webflow/src/test/java/org/springframework/webflow/mvc/servlet/FlowHandlerMappingTests.java b/spring-webflow/src/test/java/org/springframework/webflow/mvc/servlet/FlowHandlerMappingTests.java index c1bd90e3..2f3e91d8 100644 --- a/spring-webflow/src/test/java/org/springframework/webflow/mvc/servlet/FlowHandlerMappingTests.java +++ b/spring-webflow/src/test/java/org/springframework/webflow/mvc/servlet/FlowHandlerMappingTests.java @@ -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 {