Skip to content

Commit

Permalink
update service layer
Browse files Browse the repository at this point in the history
git-svn-id: http://anonsvn.jboss.org/repos/weld/ri/trunk@3652 1c488680-804c-0410-94cd-c6b725194a0e
  • Loading branch information
pmuir committed Sep 7, 2009
1 parent 6d03489 commit d95dd45
Show file tree
Hide file tree
Showing 74 changed files with 805 additions and 320 deletions.
63 changes: 7 additions & 56 deletions impl/src/main/java/org/jboss/webbeans/BeanManagerImpl.java
Expand Up @@ -35,9 +35,6 @@
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.CopyOnWriteArraySet;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;

import javax.el.ELResolver;
Expand All @@ -64,7 +61,6 @@
import org.jboss.webbeans.bean.RIBean;
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.CreationalContextImpl;
import org.jboss.webbeans.context.WBCreationalContext;
import org.jboss.webbeans.ejb.EjbDescriptors;
Expand Down Expand Up @@ -169,7 +165,6 @@ public String toString()
* Application scoped services
* ***************************
*/
private transient final ExecutorService taskExecutor = Executors.newSingleThreadExecutor();
private transient final ServiceRegistry services;

/*
Expand Down Expand Up @@ -1083,7 +1078,7 @@ public BeanManagerImpl createActivity()
{
BeanManagerImpl childActivity = newChildActivityManager(this);
childActivities.add(childActivity);
CurrentManager.add(childActivity);
Container.instance().addActivity(childActivity);
return childActivity;
}

Expand Down Expand Up @@ -1177,56 +1172,7 @@ public Map<Contextual<?>, Contextual<?>> getSpecializedBeans()

protected Object readResolve()
{
return CurrentManager.get(id);
}

/**
* Provides access to the executor service used for asynchronous tasks.
*
* @return the ExecutorService for this manager
*/
public ExecutorService getTaskExecutor()
{
return taskExecutor;
}

public void shutdown()
{
log.trace("Ending application");
shutdownExecutors();
ApplicationContext applicationContext = getServices().get(ApplicationContext.class);
applicationContext.destroy();
applicationContext.setActive(false);
applicationContext.setBeanStore(null);
CurrentManager.clear();
}

/**
* Shuts down any executor services in the manager.
*/
protected void shutdownExecutors()
{
taskExecutor.shutdown();
try
{
// Wait a while for existing tasks to terminate
if (!taskExecutor.awaitTermination(60, TimeUnit.SECONDS))
{
taskExecutor.shutdownNow(); // Cancel currently executing tasks
// Wait a while for tasks to respond to being cancelled
if (!taskExecutor.awaitTermination(60, TimeUnit.SECONDS))
{
// Log the error here
}
}
}
catch (InterruptedException ie)
{
// (Re-)Cancel if current thread also interrupted
taskExecutor.shutdownNow();
// Preserve interrupt status
Thread.currentThread().interrupt();
}
return Container.instance().activityManager(id);
}

protected ClientProxyProvider getClientProxyProvider()
Expand Down Expand Up @@ -1414,5 +1360,10 @@ public <T> EnterpriseBean<T> getBean(EjbDescriptor<T> descriptor)
{
return (EnterpriseBean<T>) getEnterpriseBeans().get(descriptor);
}

public void cleanup()
{
services.cleanup();
}

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

import java.util.Map;
import java.util.Map.Entry;
import java.util.concurrent.ConcurrentHashMap;

import org.jboss.webbeans.bootstrap.BeanDeployment;
import org.jboss.webbeans.bootstrap.api.ServiceRegistry;
import org.jboss.webbeans.bootstrap.api.Singleton;
import org.jboss.webbeans.bootstrap.api.SingletonProvider;
import org.jboss.webbeans.bootstrap.spi.BeanDeploymentArchive;

/**
* A Web Beans application container
*
* @author pmuir
*
*/
public class Container
{

private final static Singleton<Container> instance;

static
{
instance = SingletonProvider.instance().create(Container.class);
}

/**
* Get the container for the current application deployment
*
* @return
*/
public static Container instance()
{
return instance.get();
}


/**
* Initialize the container for the current application deployment
*
* @param deploymentManager
* @param deploymentServices
*/
public static void initialize(BeanManagerImpl deploymentManager, ServiceRegistry deploymentServices)
{
Container instance = new Container(deploymentManager, deploymentServices);
Container.instance.set(instance);
}

// The deployment bean manager
private final BeanManagerImpl deploymentManager;

// A map of managers keyed by ID, used for activities
private final Map<Integer, BeanManagerImpl> activities;

// A map of BDA -> bean managers
private final Map<BeanDeploymentArchive, BeanManagerImpl> beanDeploymentArchives;

private final ServiceRegistry deploymentServices;

private boolean initialized = false;

public Container(BeanManagerImpl deploymentManager, ServiceRegistry deploymentServices)
{
this.deploymentManager = deploymentManager;
this.activities = new ConcurrentHashMap<Integer, BeanManagerImpl>();
this.activities.put(deploymentManager.getId(), deploymentManager);
this.beanDeploymentArchives = new ConcurrentHashMap<BeanDeploymentArchive, BeanManagerImpl>();
this.deploymentServices = deploymentServices;
}

/**
* Cause the container to be cleaned up, including all registered bean
* managers, and all deployment services
*/
public void cleanup()
{
// TODO We should probably cleanup the bean managers for activities?
activities.clear();

for (BeanManagerImpl beanManager : beanDeploymentArchives.values())
{
beanManager.cleanup();
}
beanDeploymentArchives.clear();

deploymentServices.cleanup();
deploymentManager.cleanup();
}

/**
* Gets the manager for this application deployment
*
*/
public BeanManagerImpl deploymentManager()
{
return deploymentManager;
}
public Map<BeanDeploymentArchive, BeanManagerImpl> beanDeploymentArchives()
{
return beanDeploymentArchives;
}

/**
* Get the activity manager for a given key
*
* @param key
* @return
*/
public BeanManagerImpl activityManager(Integer key)
{
return activities.get(key);
}

/**
* Add an activity
*
* @param manager
* @return
*/
public Integer addActivity(BeanManagerImpl manager)
{
Integer id = manager.getId();
activities.put(id, manager);
return id;
}

/**
* Get the services for this application deployment
*
* @return the deploymentServices
*/
public ServiceRegistry deploymentServices()
{
return deploymentServices;
}

/**
* Add sub-deployment units to the container
*
* @param beanDeployments
*/
public void putBeanDeployments(Map<BeanDeploymentArchive, BeanDeployment> beanDeployments)
{
for (Entry<BeanDeploymentArchive, BeanDeployment> entry : beanDeployments.entrySet())
{
beanDeploymentArchives.put(entry.getKey(), entry.getValue().getBeanManager());
addActivity(entry.getValue().getBeanManager());
}
}

/**
* Check if the application container is fully initialized
*
* @return the initialized
*/
public boolean isInitialized()
{
return initialized;
}

/**
* Put the application container into an initialized state
*
* @param initialized the initialized to set
*/
public void setInitialized(boolean initialized)
{
this.initialized = initialized;
}

}
5 changes: 5 additions & 0 deletions impl/src/main/java/org/jboss/webbeans/ContextualIdStore.java
Expand Up @@ -69,4 +69,9 @@ public Integer getId(Contextual<?> contextual)
return id;
}
}

public void cleanup()
{
contextuals.clear();
}
}

0 comments on commit d95dd45

Please sign in to comment.