Skip to content

Commit

Permalink
Big tidy up to concurrent multi-value data structures
Browse files Browse the repository at this point in the history
git-svn-id: http://anonsvn.jboss.org/repos/weld/ri/trunk@2300 1c488680-804c-0410-94cd-c6b725194a0e
  • Loading branch information
pmuir committed Apr 5, 2009
1 parent c2b5faa commit 842eb83
Show file tree
Hide file tree
Showing 23 changed files with 728 additions and 590 deletions.
146 changes: 80 additions & 66 deletions impl/src/main/java/org/jboss/webbeans/ManagerImpl.java
Expand Up @@ -65,11 +65,10 @@
import org.jboss.webbeans.bean.proxy.ClientProxyProvider;
import org.jboss.webbeans.bootstrap.api.ServiceRegistry;
import org.jboss.webbeans.context.ApplicationContext;
import org.jboss.webbeans.context.ContextMap;
import org.jboss.webbeans.context.CreationalContextImpl;
import org.jboss.webbeans.el.Namespace;
import org.jboss.webbeans.el.NamespaceManager;
import org.jboss.webbeans.event.EventManager;
import org.jboss.webbeans.event.EventObserver;
import org.jboss.webbeans.event.ObserverImpl;
import org.jboss.webbeans.injection.NonContextualInjector;
import org.jboss.webbeans.injection.resolution.ResolvableAnnotatedClass;
Expand All @@ -83,6 +82,10 @@
import org.jboss.webbeans.util.Beans;
import org.jboss.webbeans.util.Proxies;
import org.jboss.webbeans.util.Reflections;
import org.jboss.webbeans.util.collections.multi.ConcurrentSetHashMultiMap;
import org.jboss.webbeans.util.collections.multi.ConcurrentListHashMultiMap;
import org.jboss.webbeans.util.collections.multi.ConcurrentListMultiMap;
import org.jboss.webbeans.util.collections.multi.ConcurrentSetMultiMap;

/**
* Implementation of the Web Beans Manager.
Expand All @@ -95,53 +98,51 @@
*/
public class ManagerImpl implements WebBeansManager, Serializable
{




private static final Log log = Logging.getLog(ManagerImpl.class);

private static final long serialVersionUID = 3021562879133838561L;

// The JNDI key to place the manager under
public static final String JNDI_KEY = "java:app/Manager";

// The enabled deployment types from web-beans.xml
private transient List<Class<? extends Annotation>> enabledDeploymentTypes;

// The Web Beans event manager
private transient final EventManager eventManager;

// An executor service for asynchronous tasks
/*
* Application scoped services
* ****************************
*/
private transient final ExecutorService taskExecutor = Executors.newSingleThreadExecutor();

// An injection point metadata beans factory
private transient final ThreadLocal<Stack<InjectionPoint>> currentInjectionPoint;

// The bean resolver
private transient final Resolver resolver;

// The registered contexts
private transient final ContextMap contexts;
private transient final ServiceRegistry services;

// The client proxy pool
/*
* Application scoped data structures
* ***********************************
*/
private transient List<Class<? extends Annotation>> enabledDeploymentTypes;
private transient final ConcurrentListMultiMap<Class<? extends Annotation>, Context> contexts;
private transient final ClientProxyProvider clientProxyProvider;

// The registered beans
private transient List<Bean<?>> beans;

// The registered beans, mapped by implementation class
private transient final Map<Class<?>, EnterpriseBean<?>> newEnterpriseBeans;

private transient final Map<String, RIBean<?>> riBeans;

private transient final ServiceRegistry services;

private final transient Map<Bean<?>, Bean<?>> specializedBeans;



/*
* Activity scoped services
* *************************
*/
private transient final EventManager eventManager;
private transient final Resolver resolver;
private final transient NonContextualInjector nonContextualInjector;

private final transient NamespaceManager namespaceManager;

/*
* Activity scoped data structures
* ********************************
*/
private transient final ThreadLocal<Stack<InjectionPoint>> currentInjectionPoint;
private transient List<Bean<?>> beans;
private final transient Namespace rootNamespace;
private final ConcurrentSetMultiMap<Type, EventObserver<?>> registeredObservers;


/**
* Create a new, root, manager
Expand All @@ -158,12 +159,14 @@ public static ManagerImpl newRootManager(ServiceRegistry serviceRegistry)
return new ManagerImpl(
serviceRegistry,
new CopyOnWriteArrayList<Bean<?>>(),
new ConcurrentSetHashMultiMap<Type, EventObserver<?>>(),
new Namespace(),
new ConcurrentHashMap<Class<?>, EnterpriseBean<?>>(),
new ConcurrentHashMap<String, RIBean<?>>(),
new ClientProxyProvider(),
new ContextMap(),
new ConcurrentListHashMultiMap<Class<? extends Annotation>, Context>(),
new HashMap<Bean<?>, Bean<?>>(),
new NamespaceManager(new Namespace()),

defaultEnabledDeploymentTypes);
}

Expand All @@ -178,17 +181,20 @@ public static ManagerImpl newChildManager(ManagerImpl parentManager)
List<Bean<?>> beans = new CopyOnWriteArrayList<Bean<?>>();
beans.addAll(parentManager.getBeans());

NamespaceManager namespaceManager = new NamespaceManager(new Namespace(parentManager.getNamespaceManager().getRoot()));
ConcurrentSetMultiMap<Type, EventObserver<?>> registeredObservers = new ConcurrentSetHashMultiMap<Type, EventObserver<?>>();
registeredObservers.putAll(parentManager.getRegisteredObservers());
Namespace rootNamespace = new Namespace(parentManager.getRootNamespace());

return new ManagerImpl(
parentManager.getServices(),
beans,
beans,
registeredObservers,
rootNamespace,
parentManager.getNewEnterpriseBeanMap(),
parentManager.getRiBeans(),
parentManager.getRiBeans(),
parentManager.getClientProxyProvider(),
parentManager.getContexts(),
parentManager.getSpecializedBeans(),
namespaceManager,
parentManager.getEnabledDeploymentTypes());
}

Expand All @@ -199,27 +205,27 @@ public static ManagerImpl newChildManager(ManagerImpl parentManager)
*/
private ManagerImpl(
ServiceRegistry serviceRegistry,
List<Bean<?>> beans,
List<Bean<?>> beans,
ConcurrentSetMultiMap<Type, EventObserver<?>> registeredObservers,
Namespace rootNamespace,
Map<Class<?>, EnterpriseBean<?>> newEnterpriseBeans,
Map<String, RIBean<?>> riBeans,
ClientProxyProvider clientProxyProvider,
ContextMap contexts,
ConcurrentListMultiMap<Class<? extends Annotation>, Context> contexts,
Map<Bean<?>, Bean<?>> specializedBeans,
NamespaceManager namespaceManager,
List<Class<? extends Annotation>> enabledDeploymentTypes
)
{
this.services = serviceRegistry;
this.beans = beans;
this.newEnterpriseBeans = newEnterpriseBeans;
this.riBeans = riBeans;

this.clientProxyProvider = clientProxyProvider;
this.contexts = contexts;
this.specializedBeans = specializedBeans;

this.namespaceManager = namespaceManager;
this.registeredObservers = registeredObservers;
setEnabledDeploymentTypes(enabledDeploymentTypes);
this.rootNamespace = rootNamespace;

this.resolver = new Resolver(this);
this.eventManager = new EventManager(this);
Expand Down Expand Up @@ -273,7 +279,7 @@ public Manager addBean(Bean<?> bean)
}
resolver.clear();
beans.add(bean);
namespaceManager.register(bean);
registerBeanNamespace(bean);
return this;
}

Expand Down Expand Up @@ -466,11 +472,25 @@ public void setBeans(Set<RIBean<?>> beans)
newEnterpriseBeans.put(bean.getType(), (EnterpriseBean<?>) bean);
}
riBeans.put(bean.getId(), bean);
namespaceManager.register(bean);
registerBeanNamespace(bean);
}
resolver.clear();
}
}

protected void registerBeanNamespace(Bean<?> bean)
{
if (bean.getName() != null && bean.getName().indexOf('.') > 0)
{
String name = bean.getName().substring(0, bean.getName().lastIndexOf('.'));
String[] hierarchy = name.split("\\.");
Namespace namespace = getRootNamespace();
for (String s : hierarchy)
{
namespace = namespace.putIfAbsent(s);
}
}
}

/**
* Gets the class-mapped beans. For internal use.
Expand Down Expand Up @@ -507,7 +527,7 @@ public Map<String, RIBean<?>> getRiBeans()
*/
public Manager addContext(Context context)
{
contexts.add(context);
contexts.put(context.getScopeType(), context);
return this;
}

Expand Down Expand Up @@ -622,7 +642,7 @@ public void fireEvent(Object event, Annotation... bindings)
public Context getContext(Class<? extends Annotation> scopeType)
{
List<Context> activeContexts = new ArrayList<Context>();
for (Context context : contexts.getContext(scopeType))
for (Context context : contexts.get(scopeType))
{
if (context.isActive())
{
Expand All @@ -640,17 +660,6 @@ public Context getContext(Class<? extends Annotation> scopeType)
return activeContexts.iterator().next();
}

/**
* Direct access to built in contexts. For internal use.
*
* @param scopeType The scope type of the context
* @return The context
*/
public Context getBuiltInContext(Class<? extends Annotation> scopeType)
{
return contexts.getBuiltInContext(scopeType);
}

/**
* Returns an instance of a bean
*
Expand Down Expand Up @@ -936,11 +945,6 @@ public Resolver getResolver()
{
return resolver;
}

public NamespaceManager getNamespaceManager()
{
return namespaceManager;
}

/**
* Gets a string representation
Expand Down Expand Up @@ -1067,9 +1071,19 @@ protected ClientProxyProvider getClientProxyProvider()
return clientProxyProvider;
}

protected ContextMap getContexts()
protected ConcurrentListMultiMap<Class<? extends Annotation>, Context> getContexts()
{
return contexts;
}

public ConcurrentSetMultiMap<Type, EventObserver<?>> getRegisteredObservers()
{
return registeredObservers;
}

public Namespace getRootNamespace()
{
return rootNamespace;
}

}
26 changes: 26 additions & 0 deletions impl/src/main/java/org/jboss/webbeans/Test.java
@@ -0,0 +1,26 @@
/*
* 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;

/**
* @author Pete Muir
*
*/
public class Test
{

}
Expand Up @@ -12,6 +12,12 @@
import org.jboss.webbeans.introspector.AnnotatedItem;
import org.jboss.webbeans.introspector.ForwardingAnnotatedItem;

/**
* AnnotatedItem transformer which can be used for FacadeBeans
*
* @author Pete Muir
*
*/
public class FacadeBeanAnnotatedItemTransformer implements AnnotatedItemTransformer
{

Expand Down

0 comments on commit 842eb83

Please sign in to comment.