You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by sk...@apache.org on 2009/02/22 13:53:02 UTC

svn commit: r746665 - in /myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra: FactoryFinder.java conversation/ConversationContextFactory.java conversation/ConversationContextFactoryImpl.java conversation/ConversationManager.java

Author: skitching
Date: Sun Feb 22 12:53:01 2009
New Revision: 746665

URL: http://svn.apache.org/viewvc?rev=746665&view=rev
Log:
Fix ORCHESTRA-33 : No way to configure ConversationContext timeout.
This patch adds a ConversationContextFactory interface, then allows the
user to configure their own impl of this interface (or use the default
implementation with the appropriate timeout set via property injection).

Added:
    myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/FactoryFinder.java   (with props)
    myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/conversation/ConversationContextFactory.java   (with props)
    myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/conversation/ConversationContextFactoryImpl.java   (with props)
Modified:
    myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/conversation/ConversationManager.java

Added: myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/FactoryFinder.java
URL: http://svn.apache.org/viewvc/myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/FactoryFinder.java?rev=746665&view=auto
==============================================================================
--- myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/FactoryFinder.java (added)
+++ myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/FactoryFinder.java Sun Feb 22 12:53:01 2009
@@ -0,0 +1,60 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.apache.myfaces.orchestra;
+
+import org.apache.myfaces.orchestra.conversation.ConversationContextFactory;
+import org.apache.myfaces.orchestra.frameworkAdapter.FrameworkAdapter;
+
+import org.apache.myfaces.orchestra.conversation.ConversationContextFactoryImpl;
+
+/**
+ * A factory of factory classes, just like the JSF javax.faces.FactoryFinder class.
+ */
+public class FactoryFinder
+{
+    // The key of an optional bean that the user can define in the DI framework to override
+    // the settings of the ConversationContextFactory used by Orchestra.
+    public static final String CONVERSATION_CONTEXT_FACTORY_KEY
+        = ConversationContextFactory.class.getName();
+
+    private static final ConversationContextFactory CONVERSATION_CONTEXT_FACTORY_DFLT
+        = new ConversationContextFactoryImpl();
+
+    /**
+     * Return an object that implements interface ConversationContextFactory.
+     * <p>
+     * Normally, the returned object will be an instance of ConversationContextFactoryImpl.
+     * However users can configure a bean in the DI framework to specify a different class - or to
+     * return an instance of ConversationContextFactoryImpl with a custom timeout value configured.
+     */
+    public static ConversationContextFactory getConversationContextFactory()
+    {
+        FrameworkAdapter fa = FrameworkAdapter.getCurrentInstance();
+        ConversationContextFactory factory = (ConversationContextFactory) fa.getBean(
+                CONVERSATION_CONTEXT_FACTORY_KEY);
+
+        if (factory == null)
+        {
+            factory = CONVERSATION_CONTEXT_FACTORY_DFLT;
+        }
+
+        return factory;
+    }
+}

Propchange: myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/FactoryFinder.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/conversation/ConversationContextFactory.java
URL: http://svn.apache.org/viewvc/myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/conversation/ConversationContextFactory.java?rev=746665&view=auto
==============================================================================
--- myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/conversation/ConversationContextFactory.java (added)
+++ myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/conversation/ConversationContextFactory.java Sun Feb 22 12:53:01 2009
@@ -0,0 +1,29 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.apache.myfaces.orchestra.conversation;
+
+/**
+ * An object that is capable of creating a fully-configured instance of a
+ * conversation context with a particular id.
+ */
+public interface ConversationContextFactory
+{
+    ConversationContext createConversationContext(ConversationContext parent, long id);
+}

Propchange: myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/conversation/ConversationContextFactory.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/conversation/ConversationContextFactoryImpl.java
URL: http://svn.apache.org/viewvc/myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/conversation/ConversationContextFactoryImpl.java?rev=746665&view=auto
==============================================================================
--- myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/conversation/ConversationContextFactoryImpl.java (added)
+++ myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/conversation/ConversationContextFactoryImpl.java Sun Feb 22 12:53:01 2009
@@ -0,0 +1,49 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.apache.myfaces.orchestra.conversation;
+
+/**
+ * An object that is capable of creating a fully-configured instance of a
+ * conversation context with a particular id.
+ */
+public class ConversationContextFactoryImpl implements  ConversationContextFactory
+{
+    // Default timeout for contexts: 30 minutes.
+    public static final long DFLT_TIMEOUT_MINS = 30;
+
+    private long timeoutMillis = DFLT_TIMEOUT_MINS * 60L * 1000L;
+
+    public void setTimeoutSecs(long secs)
+    {
+        timeoutMillis = secs * 1000L;
+    }
+
+    public void setTimeoutMins(long mins)
+    {
+        timeoutMillis = mins * 60L * 1000L;
+    }
+
+    public ConversationContext createConversationContext(ConversationContext parent, long id)
+    {
+        ConversationContext ctx = new ConversationContext(parent, id);
+        ctx.setTimeout(timeoutMillis);
+        return ctx;
+    }
+}

Propchange: myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/conversation/ConversationContextFactoryImpl.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/conversation/ConversationManager.java
URL: http://svn.apache.org/viewvc/myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/conversation/ConversationManager.java?rev=746665&r1=746664&r2=746665&view=diff
==============================================================================
--- myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/conversation/ConversationManager.java (original)
+++ myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/conversation/ConversationManager.java Sun Feb 22 12:53:01 2009
@@ -21,6 +21,7 @@
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
+import org.apache.myfaces.orchestra.FactoryFinder;
 import org.apache.myfaces.orchestra.frameworkAdapter.FrameworkAdapter;
 import org.apache.myfaces.orchestra.lib.OrchestraException;
 import org.apache.myfaces.orchestra.requestParameterProvider.RequestParameterProviderManager;
@@ -268,7 +269,8 @@
                     conversationContextId);
             if (conversationContext == null)
             {
-                conversationContext = new ConversationContext(null, conversationContextId.longValue());
+                ConversationContextFactory factory = FactoryFinder.getConversationContextFactory();
+                conversationContext = factory.createConversationContext(null, conversationContextId.longValue());
                 conversationContexts.put(conversationContextId, conversationContext);
 
                 // TODO: add the "user" name here, otherwise this debugging is not very useful
@@ -290,7 +292,8 @@
     public ConversationContext createConversationContext(ConversationContext parent)
     {
         Long ctxId = createNextConversationContextId();
-        ConversationContext ctx = new ConversationContext(parent, ctxId.longValue());
+        ConversationContextFactory factory = FactoryFinder.getConversationContextFactory();
+        ConversationContext ctx = factory.createConversationContext(parent, ctxId.longValue());
 
         synchronized(this)
         {