Spring-WebFlow是否提供了一种了解当前正在执行的流的数量的方法?
我可以使用全局bean来解决它,但也许WebFlow提供了开箱即用的解决方案。
编辑:根据要求,这里所谓的“Global Bean”解决方案基于 FlowExecutionListenerAdapter
package your.package;
import org.apache.log4j.Logger;
import org.springframework.webflow.core.collection.AttributeMap;
import org.springframework.webflow.definition.StateDefinition;
import org.springframework.webflow.definition.TransitionDefinition;
import org.springframework.webflow.execution.FlowExecutionListenerAdapter;
import org.springframework.webflow.execution.FlowSession;
import org.springframework.webflow.execution.RequestContext;
public class FlowExecutionListener extends FlowExecutionListenerAdapter {
private static Logger logger = Logger.getLogger(FlowExecutionListener.class);
private int sessionCount = 0;
@Override
public void sessionStarted(final RequestContext context, final FlowSession session) {
super.sessionStarted(context, session);
sessionCount++;
logger.debug("sessionStarted, state: " + session.getState().getId() + ", count: " + sessionCount);
}
@Override
public void sessionEnded(final RequestContext context, final FlowSession session, final String outcome, final AttributeMap output) {
super.sessionEnded(context, session, outcome, output);
sessionCount--;
logger.debug("sessionEnded, state: " + session.getState().getId() + ", count: " + sessionCount);
}
}
bean必须在Spring级注册:
<bean id="flowExecutionListener" class="your.package.FlowExecutionListener" />
EDIT2:
如果您的应用程序中有多个WebFlow,则会将全部计为活动流。如果您想单独对帐户进行帐户,可以使用 session.getDefinition()。getId()获取流的ID。