You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mina.apache.org by ni...@apache.org on 2008/03/25 23:17:44 UTC
svn commit: r641048 -
/mina/trunk/statemachine/src/main/java/org/apache/mina/statemachine/context/IoSessionStateContextLookup.java
Author: niklas
Date: Tue Mar 25 15:17:40 2008
New Revision: 641048
URL: http://svn.apache.org/viewvc?rev=641048&view=rev
Log:
DIRMINA-558: The session attribute name used can now be configured in the constructor. By using a custom attribute name several state machines may now be running for the same session.
Modified:
mina/trunk/statemachine/src/main/java/org/apache/mina/statemachine/context/IoSessionStateContextLookup.java
Modified: mina/trunk/statemachine/src/main/java/org/apache/mina/statemachine/context/IoSessionStateContextLookup.java
URL: http://svn.apache.org/viewvc/mina/trunk/statemachine/src/main/java/org/apache/mina/statemachine/context/IoSessionStateContextLookup.java?rev=641048&r1=641047&r2=641048&view=diff
==============================================================================
--- mina/trunk/statemachine/src/main/java/org/apache/mina/statemachine/context/IoSessionStateContextLookup.java (original)
+++ mina/trunk/statemachine/src/main/java/org/apache/mina/statemachine/context/IoSessionStateContextLookup.java Tue Mar 25 15:17:40 2008
@@ -30,38 +30,64 @@
*/
public class IoSessionStateContextLookup extends AbstractStateContextLookup {
/**
- * The name of the {@link IoSession} attribute used to store the
+ * The default name of the {@link IoSession} attribute used to store the
* {@link StateContext} object.
*/
- public static final String STATE_CONTEXT =
+ public static final String DEFAULT_SESSION_ATTRIBUTE_NAME =
IoSessionStateContextLookup.class.getName() + ".stateContext";
+ private final String sessionAttributeName;
+
/**
* Creates a new instance using a {@link DefaultStateContextFactory} to
* create {@link StateContext} objects for new {@link IoSession}s.
*/
public IoSessionStateContextLookup() {
- this(new DefaultStateContextFactory());
+ this(new DefaultStateContextFactory(), DEFAULT_SESSION_ATTRIBUTE_NAME);
}
/**
+ * Creates a new instance using a {@link DefaultStateContextFactory} to
+ * create {@link StateContext} objects for new {@link IoSession}s.
+ *
+ * @param sessionAttributeName the name of the {@link IoSession} attribute
+ * used to store the {@link StateContext} object.
+ */
+ public IoSessionStateContextLookup(String sessionAttributeName) {
+ this(new DefaultStateContextFactory(), sessionAttributeName);
+ }
+
+ /**
* Creates a new instance using the specified {@link StateContextFactory} to
* create {@link StateContext} objects for new {@link IoSession}s.
*
* @param contextFactory the {@link StateContextFactory}.
*/
public IoSessionStateContextLookup(StateContextFactory contextFactory) {
- super(contextFactory);
+ this(contextFactory, DEFAULT_SESSION_ATTRIBUTE_NAME);
}
+ /**
+ * Creates a new instance using the specified {@link StateContextFactory} to
+ * create {@link StateContext} objects for new {@link IoSession}s.
+ *
+ * @param contextFactory the {@link StateContextFactory}.
+ * @param sessionAttributeName the name of the {@link IoSession} attribute
+ * used to store the {@link StateContext} object.
+ */
+ public IoSessionStateContextLookup(StateContextFactory contextFactory, String sessionAttributeName) {
+ super(contextFactory);
+ this.sessionAttributeName = sessionAttributeName;
+ }
+
protected StateContext lookup(Object eventArg) {
IoSession session = (IoSession) eventArg;
- return (StateContext) session.getAttribute(STATE_CONTEXT);
+ return (StateContext) session.getAttribute(sessionAttributeName);
}
protected void store(Object eventArg, StateContext context) {
IoSession session = (IoSession) eventArg;
- session.setAttribute(STATE_CONTEXT, context);
+ session.setAttribute(sessionAttributeName, context);
}
protected boolean supports(Class<?> c) {