[webbeans-commits] Webbeans SVN: r1419 - in ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans: bootstrap and 2 other directories.
webbeans-commits at lists.jboss.org
webbeans-commits at lists.jboss.org
Thu Feb 5 07:26:45 EST 2009
Author: nickarls
Date: 2009-02-05 07:26:45 -0500 (Thu, 05 Feb 2009)
New Revision: 1419
Added:
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/conversation/ServletConversationManager.java
Removed:
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/conversation/DefaultConversationManager.java
Modified:
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/proxy/ClientProxyProvider.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bootstrap/WebBeansBootstrap.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/context/ContextMap.java
Log:
minor refactorings
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/proxy/ClientProxyProvider.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/proxy/ClientProxyProvider.java 2009-02-05 07:35:00 UTC (rev 1418)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/proxy/ClientProxyProvider.java 2009-02-05 12:26:45 UTC (rev 1419)
@@ -109,7 +109,7 @@
* not already exist
* @return the client proxy for the bean
*/
- @SuppressWarnings("unchecked")
+ // TODO: What is this create parameter? Something obsolete?
public <T> T getClientProxy(final Bean<T> bean)
{
return pool.putIfAbsent(bean, new Callable<T>()
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bootstrap/WebBeansBootstrap.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bootstrap/WebBeansBootstrap.java 2009-02-05 07:35:00 UTC (rev 1418)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bootstrap/WebBeansBootstrap.java 2009-02-05 12:26:45 UTC (rev 1419)
@@ -27,7 +27,7 @@
import org.jboss.webbeans.bootstrap.spi.EjbDiscovery;
import org.jboss.webbeans.bootstrap.spi.WebBeanDiscovery;
import org.jboss.webbeans.conversation.ConversationImpl;
-import org.jboss.webbeans.conversation.DefaultConversationManager;
+import org.jboss.webbeans.conversation.ServletConversationManager;
import org.jboss.webbeans.conversation.JavaSEConversationTerminator;
import org.jboss.webbeans.conversation.NumericConversationIdGenerator;
import org.jboss.webbeans.ejb.spi.EjbResolver;
@@ -103,7 +103,7 @@
beanDeployer.addBean(InjectionPointBean.of(manager));
beanDeployer.addClass(Transaction.class);
beanDeployer.addClass(ConversationImpl.class);
- beanDeployer.addClass(DefaultConversationManager.class);
+ beanDeployer.addClass(ServletConversationManager.class);
beanDeployer.addClass(JavaSEConversationTerminator.class);
beanDeployer.addClass(NumericConversationIdGenerator.class);
beanDeployer.addClass(SessionManager.class);
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/context/ContextMap.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/context/ContextMap.java 2009-02-05 07:35:00 UTC (rev 1418)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/context/ContextMap.java 2009-02-05 12:26:45 UTC (rev 1419)
@@ -20,12 +20,13 @@
import java.lang.annotation.Annotation;
import java.util.Collections;
import java.util.List;
-import java.util.concurrent.Callable;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CopyOnWriteArrayList;
import javax.context.Context;
-import org.jboss.webbeans.util.ConcurrentCache;
+import com.google.common.collect.ForwardingMap;
/**
* A map from a scope to a list of contexts
@@ -34,9 +35,14 @@
* @author Pete Muir
*
*/
-public class ContextMap extends ConcurrentCache<Class<? extends Annotation>, List<Context>>
+public class ContextMap extends ForwardingMap<Class<? extends Annotation>, List<Context>>
{
+ private Map<Class<? extends Annotation>, List<Context>> delegate;
+ public ContextMap() {
+ delegate = new ConcurrentHashMap<Class<? extends Annotation>, List<Context>>();
+ }
+
/**
* Gets the dependent context
*
@@ -64,7 +70,7 @@
*/
public List<Context> getContext(Class<? extends Annotation> scopeType)
{
- List<Context> contexts = getValue(scopeType);
+ List<Context> contexts = get(scopeType);
if (contexts == null)
{
return Collections.emptyList();
@@ -75,12 +81,6 @@
}
}
- @Override
- public String toString()
- {
- return "ContextMap holding " + delegate().size() + " contexts: " + delegate().keySet();
- }
-
/**
* Adds a context under a scope type
*
@@ -90,16 +90,25 @@
*/
public void add(Context context)
{
- List<Context> contexts = putIfAbsent(context.getScopeType(), new Callable<List<Context>>()
- {
+ List<Context> contexts = get(context.getScopeType());
+ if (contexts == null) {
+ contexts = new CopyOnWriteArrayList<Context>();
+ put(context.getScopeType(), contexts);
+ }
+ contexts.add(context);
+ }
- public List<Context> call() throws Exception
- {
- return new CopyOnWriteArrayList<Context>();
- }
+ @Override
+ protected Map<Class<? extends Annotation>, List<Context>> delegate()
+ {
+ return delegate;
+ }
- });
- contexts.add(context);
+ @Override
+ public String toString()
+ {
+ return "ContextMap holding " + delegate().size() + " contexts: " + delegate().keySet();
}
+
}
\ No newline at end of file
Deleted: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/conversation/DefaultConversationManager.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/conversation/DefaultConversationManager.java 2009-02-05 07:35:00 UTC (rev 1418)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/conversation/DefaultConversationManager.java 2009-02-05 12:26:45 UTC (rev 1419)
@@ -1,225 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2008, Red Hat Middleware LLC, and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * Licensed 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.jboss.webbeans.conversation;
-
-import java.io.Serializable;
-import java.util.Map;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.Future;
-
-import javax.context.SessionScoped;
-import javax.inject.Current;
-import javax.inject.Produces;
-import javax.servlet.http.HttpSession;
-
-import org.jboss.webbeans.bootstrap.WebBeansBootstrap;
-import org.jboss.webbeans.context.ConversationContext;
-import org.jboss.webbeans.conversation.bindings.ConversationConcurrentAccessTimeout;
-import org.jboss.webbeans.conversation.bindings.ConversationInactivityTimeout;
-import org.jboss.webbeans.log.LogProvider;
-import org.jboss.webbeans.log.Logging;
-
-/**
- * The default conversation manager
- *
- * @author Nicklas Karlsson
- *
- */
- at SessionScoped
-public class DefaultConversationManager implements ConversationManager, Serializable
-{
- private static LogProvider log = Logging.getLogProvider(WebBeansBootstrap.class);
-
- // The conversation terminator
- @Current
- private ConversationTerminator conversationTerminator;
-
- // The current conversation
- @Current
- private ConversationImpl currentConversation;
-
- // The current HTTP session
- @Current
- private HttpSession session;
-
- // The conversation timeout in milliseconds waiting for access to a blocked conversation
- @ConversationConcurrentAccessTimeout
- private long concurrentAccessTimeout;
-
- // The conversation inactivity timeout in milliseconds
- @ConversationInactivityTimeout
- private long inactivityTimeout;
-
- // A map of current active long-running conversation entries
- private Map<String, ConversationEntry> longRunningConversations;
-
- /**
- * Creates a new conversation manager
- */
- public DefaultConversationManager()
- {
- log.trace("Created " + getClass());
- longRunningConversations = new ConcurrentHashMap<String, ConversationEntry>();
- }
-
- @Produces
- @ConversationInactivityTimeout
- public long getConversationTimeoutInMilliseconds()
- {
- return 10 * 60 * 1000;
- }
-
- @Produces
- @ConversationConcurrentAccessTimeout
- public long getConversationConcurrentAccessTimeout()
- {
- return 1 * 1000;
- }
-
- public void beginOrRestoreConversation(String cid)
- {
- if (cid == null)
- {
- // No incoming conversation ID, nothing to do here, Conversation
- // factory will produce new transient conversation
- return;
- }
- if (!longRunningConversations.containsKey(cid))
- {
- // We got an incoming conversation ID but it was not in the map of
- // known ones, nothing to do, factory to the rescue
- log.info("Could not restore long-running conversation " + cid);
- return;
- }
- // Try to get a lock to the requested conversation, return and fall back
- // to new transient conversation from factory
- // if we fail
- try
- {
- if (!longRunningConversations.get(cid).lock(concurrentAccessTimeout))
- {
- log.info("Could not acquire conversation lock in " + concurrentAccessTimeout + "ms, giving up");
- return;
- }
- }
- catch (InterruptedException e)
- {
- log.info("Interrupted while trying to acquire lock");
- return;
- }
- // If we can't cancel the termination, release the lock, return and fall
- // back to new transient conversation from factory
- if (!longRunningConversations.get(cid).cancelTermination())
- {
- longRunningConversations.get(cid).unlock();
- log.info("Failed to cancel termination of conversation " + cid);
- }
- else
- {
- // If all goes well, set the identity of the current conversation to
- // match the fetched long-running one
- currentConversation.switchTo(cid, true, inactivityTimeout);
- }
- }
-
- public void cleanupConversation()
- {
- String cid = currentConversation.getId();
- if (currentConversation.isLongRunning())
- {
- Future<?> terminationHandle = scheduleForTermination(cid);
- // When the conversation ends, a long-running conversation needs to
- // start its self-destruct. We can have the case where the conversation
- // is a previously known conversation (that had it's termination canceled in the
- // beginConversation) or the case where we have a completely new long-running conversation.
- if (longRunningConversations.containsKey(currentConversation.getId()))
- {
- longRunningConversations.get(currentConversation.getId()).unlock();
- longRunningConversations.get(currentConversation.getId()).reScheduleTermination(terminationHandle);
- }
- else
- {
- ConversationEntry conversationEntry = ConversationEntry.of(cid, terminationHandle);
- longRunningConversations.put(cid, conversationEntry);
- }
- log.trace("Scheduling " + currentConversation + " for termination");
- }
- else
- {
- // If the conversation is not long-running it can be a transient
- // conversation that has been so from the start or it can be a
- // long-running conversation that has been demoted during the request
- log.trace("Destroying transient conversation " + currentConversation);
- if (longRunningConversations.containsKey(cid))
- {
- if (!longRunningConversations.get(cid).cancelTermination())
- {
- log.info("Failed to cancel termination of conversation " + cid);
- }
- longRunningConversations.get(cid).unlock();
- }
- ConversationContext.INSTANCE.destroy();
- }
- }
-
- private Future<?> scheduleForTermination(String cid)
- {
- Runnable terminationTask = new TerminationTask(cid);
- return conversationTerminator.scheduleForTermination(terminationTask, inactivityTimeout);
- }
-
- /**
- * A termination task that destroys the conversation entry
- *
- * @author Nicklas Karlsson
- *
- */
- private class TerminationTask implements Runnable
- {
- // The conversation ID to terminate
- private String cid;
-
- /**
- * Creates a new termination task
- *
- * @param cid The conversation ID
- */
- public TerminationTask(String cid)
- {
- this.cid = cid;
- }
-
- /**
- * Executes the termination
- */
- public void run()
- {
- log.trace("Conversation " + cid + " timed out and was terminated");
- longRunningConversations.remove(cid).destroy(session);
- }
- }
-
- public void destroyAllConversations()
- {
- for (ConversationEntry conversationEntry : longRunningConversations.values())
- {
- conversationEntry.destroy(session);
- }
- longRunningConversations.clear();
- }
-
-}
Copied: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/conversation/ServletConversationManager.java (from rev 1418, ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/conversation/DefaultConversationManager.java)
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/conversation/ServletConversationManager.java (rev 0)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/conversation/ServletConversationManager.java 2009-02-05 12:26:45 UTC (rev 1419)
@@ -0,0 +1,231 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed 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.jboss.webbeans.conversation;
+
+import java.io.Serializable;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.Future;
+
+import javax.context.SessionScoped;
+import javax.inject.Current;
+import javax.inject.Produces;
+import javax.servlet.http.HttpSession;
+
+import org.jboss.webbeans.bootstrap.WebBeansBootstrap;
+import org.jboss.webbeans.context.ConversationContext;
+import org.jboss.webbeans.conversation.bindings.ConversationConcurrentAccessTimeout;
+import org.jboss.webbeans.conversation.bindings.ConversationInactivityTimeout;
+import org.jboss.webbeans.log.LogProvider;
+import org.jboss.webbeans.log.Logging;
+
+/**
+ * The default conversation manager
+ *
+ * @author Nicklas Karlsson
+ *
+ */
+ at SessionScoped
+public class ServletConversationManager implements ConversationManager, Serializable
+{
+ private static LogProvider log = Logging.getLogProvider(WebBeansBootstrap.class);
+
+ // The conversation terminator
+ @Current
+ private ConversationTerminator conversationTerminator;
+
+ // The current conversation
+ @Current
+ private ConversationImpl currentConversation;
+
+ // The current HTTP session
+ @Current
+ private HttpSession session;
+
+ // The conversation timeout in milliseconds waiting for access to a blocked conversation
+ @ConversationConcurrentAccessTimeout
+ private long concurrentAccessTimeout;
+
+ // The conversation inactivity timeout in milliseconds
+ @ConversationInactivityTimeout
+ private long inactivityTimeout;
+
+ // A map of current active long-running conversation entries
+ private Map<String, ConversationEntry> longRunningConversations;
+
+ /**
+ * Creates a new conversation manager
+ */
+ public ServletConversationManager()
+ {
+ log.trace("Created " + getClass());
+ longRunningConversations = new ConcurrentHashMap<String, ConversationEntry>();
+ }
+
+ @Produces
+ @ConversationInactivityTimeout
+ public long getConversationTimeoutInMilliseconds()
+ {
+ return 10 * 60 * 1000;
+ }
+
+ @Produces
+ @ConversationConcurrentAccessTimeout
+ public long getConversationConcurrentAccessTimeout()
+ {
+ return 1 * 1000;
+ }
+
+ public void beginOrRestoreConversation(String cid)
+ {
+ if (cid == null)
+ {
+ // No incoming conversation ID, nothing to do here, continue with
+ // a transient conversation
+ return;
+ }
+ if (!longRunningConversations.containsKey(cid))
+ {
+ // We got an incoming conversation ID but it was not in the map of
+ // known ones, nothing to do. Log and return to continue with a
+ // transient conversation
+ log.info("Could not restore long-running conversation " + cid);
+ return;
+ }
+ // Try to get a lock to the requested conversation, log and return to
+ // continue with a transient conversation if we fail
+ try
+ {
+ if (!longRunningConversations.get(cid).lock(concurrentAccessTimeout))
+ {
+ log.info("Could not acquire conversation lock in " + concurrentAccessTimeout + "ms, giving up");
+ return;
+ }
+ }
+ catch (InterruptedException e)
+ {
+ log.info("Interrupted while trying to acquire lock");
+ return;
+ }
+ // If we can't cancel the termination, release the lock, return and continue
+ // with a transient conversation
+ if (!longRunningConversations.get(cid).cancelTermination())
+ {
+ longRunningConversations.get(cid).unlock();
+ log.info("Failed to cancel termination of conversation " + cid);
+ }
+ else
+ {
+ // If all goes well, set the identity of the current conversation to
+ // match the fetched long-running one
+ currentConversation.switchTo(cid, true, inactivityTimeout);
+ }
+ }
+
+ public void cleanupConversation()
+ {
+ String cid = currentConversation.getId();
+ if (currentConversation.isLongRunning())
+ {
+ Future<?> terminationHandle = scheduleForTermination(cid);
+ // When the conversation ends, a long-running conversation needs to
+ // start its self-destruct. We can have the case where the conversation
+ // is a previously known conversation (that had it's termination canceled in the
+ // beginConversation) or the case where we have a completely new long-running conversation.
+ if (longRunningConversations.containsKey(currentConversation.getId()))
+ {
+ longRunningConversations.get(currentConversation.getId()).unlock();
+ longRunningConversations.get(currentConversation.getId()).reScheduleTermination(terminationHandle);
+ }
+ else
+ {
+ ConversationEntry conversationEntry = ConversationEntry.of(cid, terminationHandle);
+ longRunningConversations.put(cid, conversationEntry);
+ }
+ log.trace("Scheduling " + currentConversation + " for termination");
+ }
+ else
+ {
+ // If the conversation is not long-running it can be a transient
+ // conversation that has been so from the start or it can be a
+ // long-running conversation that has been demoted during the request
+ log.trace("Destroying transient conversation " + currentConversation);
+ if (longRunningConversations.containsKey(cid))
+ {
+ if (!longRunningConversations.get(cid).cancelTermination())
+ {
+ log.info("Failed to cancel termination of conversation " + cid);
+ }
+ longRunningConversations.get(cid).unlock();
+ }
+ ConversationContext.INSTANCE.destroy();
+ }
+ }
+
+ /**
+ * Creates a termination task for and schedules it
+ *
+ * @param cid The id of the conversation to terminate
+ * @return The asynchronous job handle
+ */
+ private Future<?> scheduleForTermination(String cid)
+ {
+ Runnable terminationTask = new TerminationTask(cid);
+ return conversationTerminator.scheduleForTermination(terminationTask, inactivityTimeout);
+ }
+
+ /**
+ * A termination task that destroys the conversation entry
+ *
+ * @author Nicklas Karlsson
+ *
+ */
+ private class TerminationTask implements Runnable
+ {
+ // The conversation ID to terminate
+ private String cid;
+
+ /**
+ * Creates a new termination task
+ *
+ * @param cid The conversation ID
+ */
+ public TerminationTask(String cid)
+ {
+ this.cid = cid;
+ }
+
+ /**
+ * Executes the termination
+ */
+ public void run()
+ {
+ log.trace("Conversation " + cid + " timed out and was terminated");
+ longRunningConversations.remove(cid).destroy(session);
+ }
+ }
+
+ public void destroyAllConversations()
+ {
+ for (ConversationEntry conversationEntry : longRunningConversations.values())
+ {
+ conversationEntry.destroy(session);
+ }
+ longRunningConversations.clear();
+ }
+
+}
Property changes on: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/conversation/ServletConversationManager.java
___________________________________________________________________
Name: svn:mergeinfo
+
More information about the weld-commits
mailing list