[webbeans-commits] Webbeans SVN: r2505 - in ri/trunk: impl/src/main/java/org/jboss/webbeans/context and 5 other directories.
webbeans-commits at lists.jboss.org
webbeans-commits at lists.jboss.org
Fri Apr 17 20:17:35 EDT 2009
Author: pete.muir at jboss.org
Date: 2009-04-17 20:17:35 -0400 (Fri, 17 Apr 2009)
New Revision: 2505
Added:
ri/trunk/spi/src/main/java/org/jboss/webbeans/bootstrap/api/Singleton.java
ri/trunk/spi/src/main/java/org/jboss/webbeans/bootstrap/api/SingletonProvider.java
ri/trunk/spi/src/main/java/org/jboss/webbeans/bootstrap/api/helpers/IsolatedStaticSingletonProvider.java
ri/trunk/spi/src/main/java/org/jboss/webbeans/bootstrap/api/helpers/TCCLSingletonProvider.java
Modified:
ri/trunk/impl/src/main/java/org/jboss/webbeans/CurrentManager.java
ri/trunk/impl/src/main/java/org/jboss/webbeans/context/ApplicationContext.java
ri/trunk/impl/src/main/java/org/jboss/webbeans/context/ContextLifecycle.java
ri/trunk/impl/src/main/java/org/jboss/webbeans/context/ConversationContext.java
ri/trunk/impl/src/main/java/org/jboss/webbeans/context/DependentContext.java
ri/trunk/impl/src/main/java/org/jboss/webbeans/context/RequestContext.java
ri/trunk/impl/src/main/java/org/jboss/webbeans/context/SessionContext.java
ri/trunk/impl/src/main/java/org/jboss/webbeans/conversation/ServletConversationManager.java
ri/trunk/impl/src/main/java/org/jboss/webbeans/jsf/WebBeansPhaseListener.java
ri/trunk/impl/src/main/java/org/jboss/webbeans/servlet/ServletLifecycle.java
ri/trunk/impl/src/main/java/org/jboss/webbeans/servlet/WebBeansListener.java
Log:
WBRI-190, thanks to Sahoo
Modified: ri/trunk/impl/src/main/java/org/jboss/webbeans/CurrentManager.java
===================================================================
--- ri/trunk/impl/src/main/java/org/jboss/webbeans/CurrentManager.java 2009-04-17 18:35:02 UTC (rev 2504)
+++ ri/trunk/impl/src/main/java/org/jboss/webbeans/CurrentManager.java 2009-04-18 00:17:35 UTC (rev 2505)
@@ -1,4 +1,10 @@
/*
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
+ *
+ * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
+ *
+ * Use is subject to license terms.
+ *
* 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
@@ -9,7 +15,7 @@
* 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,
+ * 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.
@@ -20,24 +26,33 @@
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
+import javax.inject.TypeLiteral;
+import org.jboss.webbeans.bootstrap.api.Singleton;
+import org.jboss.webbeans.bootstrap.api.SingletonProvider;
+
+
/**
* Access point for getting/setting current Managager
*
* @author Gavin King
+ * @author Sanjeeb.Sahoo at Sun.COM
+ * @author Pete Muir
*/
public class CurrentManager
{
+
+ private static class IntegerMaangerImplMap extends TypeLiteral<Map<Integer, ManagerImpl>> {}
// The root manager instance
- private static ManagerImpl rootManager;
+ private static Singleton<ManagerImpl> rootManager = SingletonProvider.instance().create(ManagerImpl.class);
- private final static Map<Integer, ManagerImpl> managers = new ConcurrentHashMap<Integer, ManagerImpl>();
+ private final static Singleton<Map<Integer, ManagerImpl>> managers = SingletonProvider.instance().create(new IntegerMaangerImplMap().getRawType());
public static void cleanup()
{
- rootManager = null;
- managers.clear();
+ rootManager.set(null);
+ managers.get().clear();
}
/**
@@ -47,7 +62,7 @@
*/
public static ManagerImpl rootManager()
{
- return rootManager;
+ return rootManager.get();
}
/**
@@ -57,19 +72,23 @@
*/
public static void setRootManager(ManagerImpl managerImpl)
{
- rootManager = managerImpl;
- managers.put(managerImpl.getId(), managerImpl);
+ rootManager.set(managerImpl);
+ if (managers.get() == null)
+ {
+ managers.set(new ConcurrentHashMap<Integer, ManagerImpl>());
+ }
+ managers.get().put(managerImpl.getId(), managerImpl);
}
public static ManagerImpl get(Integer key)
{
- return managers.get(key);
+ return managers.get().get(key);
}
public static Integer add(ManagerImpl manager)
{
Integer id = manager.getId();
- managers.put(id, manager);
+ managers.get().put(id, manager);
return id;
}
Modified: ri/trunk/impl/src/main/java/org/jboss/webbeans/context/ApplicationContext.java
===================================================================
--- ri/trunk/impl/src/main/java/org/jboss/webbeans/context/ApplicationContext.java 2009-04-17 18:35:02 UTC (rev 2504)
+++ ri/trunk/impl/src/main/java/org/jboss/webbeans/context/ApplicationContext.java 2009-04-18 00:17:35 UTC (rev 2505)
@@ -1,4 +1,10 @@
/*
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
+ *
+ * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
+ *
+ * Use is subject to license terms.
+ *
* 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
@@ -21,6 +27,8 @@
import javax.context.ApplicationScoped;
+import org.jboss.webbeans.bootstrap.api.Singleton;
+import org.jboss.webbeans.bootstrap.api.SingletonProvider;
import org.jboss.webbeans.context.api.BeanStore;
/**
@@ -33,17 +41,18 @@
public class ApplicationContext extends AbstractMapContext
{
- private static ApplicationContext INSTANCE;
-
+ private static Singleton<ApplicationContext> INSTANCE = SingletonProvider.instance().create(ApplicationContext.class);
+
public static ApplicationContext instance()
{
- return INSTANCE;
+ return INSTANCE.get();
}
public static ApplicationContext create()
{
- INSTANCE = new ApplicationContext();
- return instance();
+ ApplicationContext context = new ApplicationContext();
+ INSTANCE.set(context);
+ return context;
}
// The beans
Modified: ri/trunk/impl/src/main/java/org/jboss/webbeans/context/ContextLifecycle.java
===================================================================
--- ri/trunk/impl/src/main/java/org/jboss/webbeans/context/ContextLifecycle.java 2009-04-17 18:35:02 UTC (rev 2504)
+++ ri/trunk/impl/src/main/java/org/jboss/webbeans/context/ContextLifecycle.java 2009-04-18 00:17:35 UTC (rev 2505)
@@ -1,6 +1,31 @@
+/*
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
+ *
+ * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
+ *
+ * Use is subject to license terms.
+ *
+ * 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.context;
import org.jboss.webbeans.CurrentManager;
+import org.jboss.webbeans.bootstrap.api.Singleton;
+import org.jboss.webbeans.bootstrap.api.SingletonProvider;
import org.jboss.webbeans.context.api.BeanStore;
import org.jboss.webbeans.conversation.ConversationManager;
import org.jboss.webbeans.log.LogProvider;
@@ -17,16 +42,16 @@
public class ContextLifecycle
{
- private static ContextLifecycle instance;
+ private static Singleton<ContextLifecycle> instance = SingletonProvider.instance().create(ContextLifecycle.class);
public static ContextLifecycle instance()
{
- return instance;
+ return instance.get();
}
protected static void setInstance(ContextLifecycle instance)
{
- ContextLifecycle.instance = instance;
+ ContextLifecycle.instance.set(instance);
}
private static LogProvider log = Logging.getLogProvider(ContextLifecycle.class);
@@ -69,8 +94,8 @@
protected void restoreConversation(String id, BeanStore conversationBeanStore)
{
log.trace("Starting conversation " + id);
- ConversationContext.INSTANCE.setBeanStore(conversationBeanStore);
- ConversationContext.INSTANCE.setActive(true);
+ ConversationContext.instance().setBeanStore(conversationBeanStore);
+ ConversationContext.instance().setActive(true);
}
protected void destroyConversation(String id, ConversationBeanStore conversationBeanStore)
Modified: ri/trunk/impl/src/main/java/org/jboss/webbeans/context/ConversationContext.java
===================================================================
--- ri/trunk/impl/src/main/java/org/jboss/webbeans/context/ConversationContext.java 2009-04-17 18:35:02 UTC (rev 2504)
+++ ri/trunk/impl/src/main/java/org/jboss/webbeans/context/ConversationContext.java 2009-04-18 00:17:35 UTC (rev 2505)
@@ -1,4 +1,10 @@
/*
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
+ *
+ * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
+ *
+ * Use is subject to license terms.
+ *
* 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
@@ -9,7 +15,7 @@
* 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,
+ * 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.
@@ -21,6 +27,8 @@
import org.jboss.webbeans.log.LogProvider;
import org.jboss.webbeans.log.Logging;
+import org.jboss.webbeans.bootstrap.api.Singleton;
+import org.jboss.webbeans.bootstrap.api.SingletonProvider;
/**
* The conversation context
@@ -31,12 +39,19 @@
{
private static LogProvider log = Logging.getLogProvider(ConversationContext.class);
- public static ConversationContext INSTANCE;
+ private static Singleton<ConversationContext> INSTANCE =
+ SingletonProvider.instance().create(ConversationContext.class);
+ public static ConversationContext instance()
+ {
+ return INSTANCE.get();
+ }
+
public static ConversationContext create()
{
- INSTANCE = new ConversationContext();
- return INSTANCE;
+ ConversationContext context = new ConversationContext();
+ INSTANCE.set(context);
+ return context;
}
/**
@@ -55,5 +70,4 @@
String beanStoreInfo = getBeanStore() == null ? "" : getBeanStore().toString();
return active + "conversation context " + beanStoreInfo;
}
-
}
Modified: ri/trunk/impl/src/main/java/org/jboss/webbeans/context/DependentContext.java
===================================================================
--- ri/trunk/impl/src/main/java/org/jboss/webbeans/context/DependentContext.java 2009-04-17 18:35:02 UTC (rev 2504)
+++ ri/trunk/impl/src/main/java/org/jboss/webbeans/context/DependentContext.java 2009-04-18 00:17:35 UTC (rev 2505)
@@ -1,4 +1,10 @@
/*
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
+ *
+ * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
+ *
+ * Use is subject to license terms.
+ *
* 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
@@ -9,7 +15,7 @@
* 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,
+ * 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.
@@ -24,6 +30,9 @@
import javax.context.CreationalContext;
import javax.context.Dependent;
+import org.jboss.webbeans.bootstrap.api.Singleton;
+import org.jboss.webbeans.bootstrap.api.SingletonProvider;
+
/**
* The dependent context
*
@@ -31,17 +40,18 @@
*/
public class DependentContext extends AbstractContext
{
- private static DependentContext INSTANCE;
+ private static Singleton<DependentContext> INSTANCE = SingletonProvider.instance().create(DependentContext.class);
public static DependentContext instance()
{
- return INSTANCE;
+ return INSTANCE.get();
}
public static DependentContext create()
{
- INSTANCE = new DependentContext();
- return instance();
+ DependentContext ctx = new DependentContext();
+ INSTANCE.set(ctx);
+ return ctx;
}
private final ThreadLocal<AtomicInteger> reentrantActiveCount;
Modified: ri/trunk/impl/src/main/java/org/jboss/webbeans/context/RequestContext.java
===================================================================
--- ri/trunk/impl/src/main/java/org/jboss/webbeans/context/RequestContext.java 2009-04-17 18:35:02 UTC (rev 2504)
+++ ri/trunk/impl/src/main/java/org/jboss/webbeans/context/RequestContext.java 2009-04-18 00:17:35 UTC (rev 2505)
@@ -1,4 +1,10 @@
/*
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
+ *
+ * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
+ *
+ * Use is subject to license terms.
+ *
* 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
@@ -9,7 +15,7 @@
* 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,
+ * 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.
@@ -19,6 +25,9 @@
import javax.context.RequestScoped;
+import org.jboss.webbeans.bootstrap.api.Singleton;
+import org.jboss.webbeans.bootstrap.api.SingletonProvider;
+
/**
* The request context
*
@@ -27,17 +36,18 @@
public class RequestContext extends AbstractThreadLocalMapContext
{
- private static RequestContext INSTANCE;
-
+ private static Singleton<RequestContext> INSTANCE = SingletonProvider.instance().create(RequestContext.class);
+
public static RequestContext instance()
{
- return INSTANCE;
+ return INSTANCE.get();
}
public static RequestContext create()
{
- INSTANCE = new RequestContext();
- return instance();
+ RequestContext context = new RequestContext();
+ INSTANCE.set(context);
+ return context;
}
/**
@@ -61,5 +71,5 @@
{
return false;
}
-
+
}
Modified: ri/trunk/impl/src/main/java/org/jboss/webbeans/context/SessionContext.java
===================================================================
--- ri/trunk/impl/src/main/java/org/jboss/webbeans/context/SessionContext.java 2009-04-17 18:35:02 UTC (rev 2504)
+++ ri/trunk/impl/src/main/java/org/jboss/webbeans/context/SessionContext.java 2009-04-18 00:17:35 UTC (rev 2505)
@@ -1,4 +1,10 @@
/*
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
+ *
+ * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
+ *
+ * Use is subject to license terms.
+ *
* 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
@@ -9,7 +15,7 @@
* 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,
+ * 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.
@@ -19,6 +25,8 @@
import javax.context.SessionScoped;
+import org.jboss.webbeans.bootstrap.api.Singleton;
+import org.jboss.webbeans.bootstrap.api.SingletonProvider;
import org.jboss.webbeans.log.LogProvider;
import org.jboss.webbeans.log.Logging;
@@ -31,17 +39,18 @@
{
private static LogProvider log = Logging.getLogProvider(SessionContext.class);
- private static SessionContext INSTANCE;
+ private static Singleton<SessionContext> INSTANCE = SingletonProvider.instance().create(SessionContext.class);
public static SessionContext instance()
{
- return INSTANCE;
+ return INSTANCE.get();
}
public static SessionContext create()
{
- INSTANCE = new SessionContext();
- return instance();
+ SessionContext context = new SessionContext();
+ INSTANCE.set(context);
+ return context;
}
/**
Modified: ri/trunk/impl/src/main/java/org/jboss/webbeans/conversation/ServletConversationManager.java
===================================================================
--- ri/trunk/impl/src/main/java/org/jboss/webbeans/conversation/ServletConversationManager.java 2009-04-17 18:35:02 UTC (rev 2504)
+++ ri/trunk/impl/src/main/java/org/jboss/webbeans/conversation/ServletConversationManager.java 2009-04-18 00:17:35 UTC (rev 2505)
@@ -1,4 +1,10 @@
/*
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
+ *
+ * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
+ *
+ * Use is subject to license terms.
+ *
* 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
@@ -9,7 +15,7 @@
* 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,
+ * 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.
@@ -196,7 +202,7 @@
longRunningConversation.cancelTermination();
longRunningConversation.unlock();
}
- ConversationContext.INSTANCE.destroy();
+ ConversationContext.instance().destroy();
}
// If the conversation has been switched from one long
// running-conversation to another with
Modified: ri/trunk/impl/src/main/java/org/jboss/webbeans/jsf/WebBeansPhaseListener.java
===================================================================
--- ri/trunk/impl/src/main/java/org/jboss/webbeans/jsf/WebBeansPhaseListener.java 2009-04-17 18:35:02 UTC (rev 2504)
+++ ri/trunk/impl/src/main/java/org/jboss/webbeans/jsf/WebBeansPhaseListener.java 2009-04-18 00:17:35 UTC (rev 2505)
@@ -1,4 +1,10 @@
/*
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
+ *
+ * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
+ *
+ * Use is subject to license terms.
+ *
* 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
@@ -9,7 +15,7 @@
* 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,
+ * 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.
@@ -113,8 +119,8 @@
CurrentManager.rootManager().getInstanceByType(HttpSessionManager.class).setSession(session);
CurrentManager.rootManager().getInstanceByType(ConversationManager.class).beginOrRestoreConversation(PhaseHelper.getConversationId());
String cid = CurrentManager.rootManager().getInstanceByType(Conversation.class).getId();
- ConversationContext.INSTANCE.setBeanStore(new ConversationBeanStore(session, cid));
- ConversationContext.INSTANCE.setActive(true);
+ ConversationContext.instance().setBeanStore(new ConversationBeanStore(session, cid));
+ ConversationContext.instance().setActive(true);
}
/**
@@ -124,7 +130,7 @@
{
log.trace("In after render reponse phase");
CurrentManager.rootManager().getInstanceByType(ConversationManager.class).cleanupConversation();
- ConversationContext.INSTANCE.setActive(false);
+ ConversationContext.instance().setActive(false);
}
public PhaseId getPhaseId()
Modified: ri/trunk/impl/src/main/java/org/jboss/webbeans/servlet/ServletLifecycle.java
===================================================================
--- ri/trunk/impl/src/main/java/org/jboss/webbeans/servlet/ServletLifecycle.java 2009-04-17 18:35:02 UTC (rev 2504)
+++ ri/trunk/impl/src/main/java/org/jboss/webbeans/servlet/ServletLifecycle.java 2009-04-18 00:17:35 UTC (rev 2505)
@@ -1,4 +1,10 @@
/*
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
+ *
+ * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
+ *
+ * Use is subject to license terms.
+ *
* 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
@@ -9,7 +15,7 @@
* 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,
+ * 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.
@@ -41,9 +47,12 @@
public static final String REQUEST_ATTRIBUTE_NAME = ServletLifecycle.class.getName() + ".requestBeanStore";
- static
+ // This is a temporray solution. We should remove the static field from
+ // ContextLifecycle and just tie the lifecycle of ContextLifecycle
+ // with that of manager.
+ public ServletLifecycle()
{
- ContextLifecycle.setInstance(new ServletLifecycle());
+ ContextLifecycle.setInstance(this);
}
public static ServletLifecycle instance()
Modified: ri/trunk/impl/src/main/java/org/jboss/webbeans/servlet/WebBeansListener.java
===================================================================
--- ri/trunk/impl/src/main/java/org/jboss/webbeans/servlet/WebBeansListener.java 2009-04-17 18:35:02 UTC (rev 2504)
+++ ri/trunk/impl/src/main/java/org/jboss/webbeans/servlet/WebBeansListener.java 2009-04-18 00:17:35 UTC (rev 2505)
@@ -1,4 +1,10 @@
/*
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
+ *
+ * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
+ *
+ * Use is subject to license terms.
+ *
* 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
@@ -9,7 +15,7 @@
* 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,
+ * 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.
@@ -40,7 +46,7 @@
public WebBeansListener()
{
- lifecycle = ServletLifecycle.instance();
+ lifecycle = new ServletLifecycle();
}
/**
Added: ri/trunk/spi/src/main/java/org/jboss/webbeans/bootstrap/api/Singleton.java
===================================================================
--- ri/trunk/spi/src/main/java/org/jboss/webbeans/bootstrap/api/Singleton.java (rev 0)
+++ ri/trunk/spi/src/main/java/org/jboss/webbeans/bootstrap/api/Singleton.java 2009-04-18 00:17:35 UTC (rev 2505)
@@ -0,0 +1,57 @@
+/*
+ * 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.
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
+ *
+ * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
+ *
+ * Use is subject to license terms.
+ *
+ * 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.bootstrap.api;
+
+/**
+ * Holds a reference to an application singleton. This singleton is used
+ * internally by Web Beans to store various application scoped objects.
+ *
+ * This allows Web Beans to operate as a shared library. In a shared mode, the
+ * same instance of WebBeans implementation is used by all the applications in
+ * a server environment. In the exclusive mode, each application loads a
+ * separate copy of WebBeans implementation at the application level.
+ *
+ * Alternative implementations of Singleton can be used as required
+ *
+ * @see SingletonProvider
+ * @author Sanjeeb.Sahoo at Sun.COM
+ * @author Pete Muir
+ */
+public interface Singleton<T>
+{
+ /**
+ * Access the singleton
+ *
+ * @return a singleton object
+ */
+ public T get();
+
+ /**
+ * Store a singleton
+ *
+ * @param object the object to store
+ */
+ public void set(T object);
+}
Property changes on: ri/trunk/spi/src/main/java/org/jboss/webbeans/bootstrap/api/Singleton.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: ri/trunk/spi/src/main/java/org/jboss/webbeans/bootstrap/api/SingletonProvider.java
===================================================================
--- ri/trunk/spi/src/main/java/org/jboss/webbeans/bootstrap/api/SingletonProvider.java (rev 0)
+++ ri/trunk/spi/src/main/java/org/jboss/webbeans/bootstrap/api/SingletonProvider.java 2009-04-18 00:17:35 UTC (rev 2505)
@@ -0,0 +1,118 @@
+/*
+ * 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.
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
+ *
+ * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
+ *
+ * Use is subject to license terms.
+ *
+ * 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.bootstrap.api;
+
+import org.jboss.webbeans.bootstrap.api.helpers.IsolatedStaticSingletonProvider;
+import org.jboss.webbeans.bootstrap.api.helpers.TCCLSingletonProvider;
+
+/**
+ * A provider of {@link Singleton}s
+ *
+ * @see IsolatedStaticSingletonProvider
+ * @see TCCLSingletonProvider
+ *
+ * @author Sanjeeb.Sahoo at Sun.COM
+ * @author Pete Muir
+ */
+public abstract class SingletonProvider
+{
+ /*
+ * Singleton pattern. Upon first access (see instance()), it initializes
+ * itself by a default implementation. Containers are free to explicitly
+ * initialize it by calling initialize() method.
+ */
+ private static volatile SingletonProvider INSTANCE;
+
+ private static final String DEFAULT_SCOPE_FACTORY = IsolatedStaticSingletonProvider.class.getName();
+
+ public static SingletonProvider instance()
+ {
+ if (INSTANCE == null)
+ {
+ synchronized (SingletonProvider.class)
+ {
+ if (INSTANCE == null)
+ {
+ /*
+ * TODO: We should discover ScopeFactory implementation using
+ * Service Provider Mechanism. In the absence of any explicitly
+ * configured service, should we default to the default
+ * implementation.
+ */
+ initializeWithDefaultScope();
+ }
+ }
+ }
+ return INSTANCE;
+ }
+
+ protected SingletonProvider()
+ {
+ }
+
+ /**
+ * Create a new singleton
+ *
+ * @param expectedType represents the type of Java object stored in the singleton
+ * @return a singelton
+ */
+ public abstract <T> Singleton<T> create(Class<? extends T> expectedType);
+
+ /**
+ * Initialize with the default instance
+ */
+ private static void initializeWithDefaultScope()
+ {
+ try
+ {
+ Class<?> aClass = Class.forName(DEFAULT_SCOPE_FACTORY);
+ INSTANCE = (SingletonProvider) aClass.newInstance();
+ }
+ catch (Exception e)
+ {
+ throw new RuntimeException(e);
+ }
+ }
+
+ /**
+ * Initialize with an explicit instance
+ *
+ * @param instance
+ */
+ public static void initialize(SingletonProvider instance)
+ {
+ synchronized (SingletonProvider.class)
+ {
+ if (INSTANCE == null)
+ {
+ INSTANCE = instance;
+ }
+ else
+ {
+ throw new RuntimeException("ScopeFactory is already initialized with " + INSTANCE);
+ }
+ }
+ }
+
+}
Property changes on: ri/trunk/spi/src/main/java/org/jboss/webbeans/bootstrap/api/SingletonProvider.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: ri/trunk/spi/src/main/java/org/jboss/webbeans/bootstrap/api/helpers/IsolatedStaticSingletonProvider.java
===================================================================
--- ri/trunk/spi/src/main/java/org/jboss/webbeans/bootstrap/api/helpers/IsolatedStaticSingletonProvider.java (rev 0)
+++ ri/trunk/spi/src/main/java/org/jboss/webbeans/bootstrap/api/helpers/IsolatedStaticSingletonProvider.java 2009-04-18 00:17:35 UTC (rev 2505)
@@ -0,0 +1,59 @@
+/*
+ * 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.
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
+ *
+ * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
+ *
+ * Use is subject to license terms.
+ *
+ * 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.bootstrap.api.helpers;
+
+import org.jboss.webbeans.bootstrap.api.Singleton;
+import org.jboss.webbeans.bootstrap.api.SingletonProvider;
+
+/**
+ *
+ * A singleton provider that assumes an isolated classloder per application
+ *
+ * @author Sanjeeb.Sahoo at Sun.COM
+ * @author Pete Muir
+ */
+public class IsolatedStaticSingletonProvider extends SingletonProvider
+{
+
+ @Override
+ public <T> Singleton<T> create(Class<? extends T> type)
+ {
+ return new IsolatedStaticSingleton<T>();
+ }
+
+ private static class IsolatedStaticSingleton<T> implements Singleton<T>
+ {
+ private T object;
+
+ public T get()
+ {
+ return object;
+ }
+
+ public void set(T object)
+ {
+ this.object = object;
+ }
+ }
+}
Property changes on: ri/trunk/spi/src/main/java/org/jboss/webbeans/bootstrap/api/helpers/IsolatedStaticSingletonProvider.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: ri/trunk/spi/src/main/java/org/jboss/webbeans/bootstrap/api/helpers/TCCLSingletonProvider.java
===================================================================
--- ri/trunk/spi/src/main/java/org/jboss/webbeans/bootstrap/api/helpers/TCCLSingletonProvider.java (rev 0)
+++ ri/trunk/spi/src/main/java/org/jboss/webbeans/bootstrap/api/helpers/TCCLSingletonProvider.java 2009-04-18 00:17:35 UTC (rev 2505)
@@ -0,0 +1,84 @@
+/*
+ * 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.
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
+ *
+ * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
+ *
+ * Use is subject to license terms.
+ *
+ * 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.bootstrap.api.helpers;
+
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+import java.util.Hashtable;
+import java.util.Map;
+
+import org.jboss.webbeans.bootstrap.api.Singleton;
+import org.jboss.webbeans.bootstrap.api.SingletonProvider;
+
+/**
+ * Singleton provider that uses the Thread Context ClassLoader to differentiate
+ * between applications
+ *
+ * @author Sanjeeb.Sahoo at Sun.COM
+ * @author Pete Muir
+ */
+public class TCCLSingletonProvider extends SingletonProvider
+{
+
+ @Override
+ public <T> Singleton<T> create(Class<? extends T> type)
+ {
+ return new TCCLSingleton<T>();
+ }
+
+ private static class TCCLSingleton<T> implements Singleton<T>
+ {
+ // use Hashtable for concurrent access
+ private final Map<ClassLoader, T> store = new Hashtable<ClassLoader, T>();
+
+ public T get()
+ {
+ return store.get(getClassLoader());
+ }
+
+ public void set(T object)
+ {
+ store.put(getClassLoader(), object);
+ }
+
+ private ClassLoader getClassLoader()
+ {
+ SecurityManager sm = System.getSecurityManager();
+ if (sm != null)
+ {
+ return AccessController.doPrivileged(new PrivilegedAction<ClassLoader>()
+ {
+ public ClassLoader run()
+ {
+ return Thread.currentThread().getContextClassLoader();
+ }
+ });
+ }
+ else
+ {
+ return Thread.currentThread().getContextClassLoader();
+ }
+ }
+ }
+}
Property changes on: ri/trunk/spi/src/main/java/org/jboss/webbeans/bootstrap/api/helpers/TCCLSingletonProvider.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
More information about the weld-commits
mailing list