Skip to content

Commit

Permalink
WBRI-190, thanks to Sahoo
Browse files Browse the repository at this point in the history
git-svn-id: http://anonsvn.jboss.org/repos/weld/ri/trunk@2505 1c488680-804c-0410-94cd-c6b725194a0e
  • Loading branch information
pmuir committed Apr 18, 2009
1 parent a806ecd commit bcbe157
Show file tree
Hide file tree
Showing 15 changed files with 494 additions and 53 deletions.
39 changes: 29 additions & 10 deletions impl/src/main/java/org/jboss/webbeans/CurrentManager.java
@@ -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
Expand All @@ -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.
Expand All @@ -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@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();
}

/**
Expand All @@ -47,7 +62,7 @@ public static void cleanup()
*/
public static ManagerImpl rootManager()
{
return rootManager;
return rootManager.get();
}

/**
Expand All @@ -57,19 +72,23 @@ public static ManagerImpl rootManager()
*/
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;
}

Expand Down
@@ -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
Expand All @@ -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;

/**
Expand All @@ -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
Expand Down
@@ -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;
Expand All @@ -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);
Expand Down Expand Up @@ -69,8 +94,8 @@ public void endRequest(String id, BeanStore requestBeanStore)
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)
Expand Down
@@ -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
Expand All @@ -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.
Expand All @@ -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
Expand All @@ -31,12 +39,19 @@ public class ConversationContext extends AbstractThreadLocalMapContext
{
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;
}

/**
Expand All @@ -55,5 +70,4 @@ public String toString()
String beanStoreInfo = getBeanStore() == null ? "" : getBeanStore().toString();
return active + "conversation context " + beanStoreInfo;
}

}
@@ -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
Expand All @@ -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.
Expand All @@ -24,24 +30,28 @@
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
*
* @author Nicklas Karlsson
*/
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;
Expand Down
24 changes: 17 additions & 7 deletions impl/src/main/java/org/jboss/webbeans/context/RequestContext.java
@@ -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
Expand All @@ -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.
Expand All @@ -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
*
Expand All @@ -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;
}

/**
Expand All @@ -61,5 +71,5 @@ protected boolean isCreationLockRequired()
{
return false;
}

}

0 comments on commit bcbe157

Please sign in to comment.