org.jboss.weld.environment.se.WeldContainer Maven / Gradle / Ivy
/*
* JBoss, Home of Professional Open Source
* Copyright 2009, Red Hat, Inc. and/or its affiliates, 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.weld.environment.se;
import java.util.Collection;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
import javax.enterprise.context.spi.CreationalContext;
import javax.enterprise.event.Event;
import javax.enterprise.inject.Instance;
import javax.enterprise.inject.Vetoed;
import javax.enterprise.inject.spi.BeanManager;
import org.jboss.weld.AbstractCDI;
import org.jboss.weld.Container;
import org.jboss.weld.ContainerState;
import org.jboss.weld.bean.builtin.BeanManagerProxy;
import org.jboss.weld.bootstrap.api.Bootstrap;
import org.jboss.weld.bootstrap.api.Singleton;
import org.jboss.weld.bootstrap.api.SingletonProvider;
import org.jboss.weld.bootstrap.spi.BeanDeploymentArchive;
import org.jboss.weld.bootstrap.spi.Deployment;
import org.jboss.weld.environment.ContainerInstance;
import org.jboss.weld.environment.deployment.WeldDeployment;
import org.jboss.weld.environment.se.events.ContainerInitialized;
import org.jboss.weld.environment.se.events.ContainerShutdown;
import org.jboss.weld.environment.se.logging.WeldSELogger;
import org.jboss.weld.inject.WeldInstance;
import org.jboss.weld.literal.DestroyedLiteral;
import org.jboss.weld.literal.InitializedLiteral;
import org.jboss.weld.manager.BeanManagerImpl;
import org.jboss.weld.util.collections.ImmutableList;
/**
* Represents a Weld SE container.
*
*
* An new instance can be initialized using the Weld builder:
*
*
*
* WeldContainer container = new Weld().initialize();
*
*
*
* It's also possible to obtain the instance of a running container by id:
*
*
*
* WeldContainer container = WeldContainer.instance("myCustomId");
*
*
*
* {@link #shutdown()} must be always called to shutdown the container properly. AutoCloseable is implemented, so the container is automatically shut down when
* leaving the try-with-resources block:
*
*
*
* try (WeldContainer container = new Weld().initialize()) {
* container.select(Foo.class).get();
* }
*
*
*
* The container is also registered as a {@link javax.inject.Singleton} bean.
*
*
*
* Provides convenient access to beans, BeanManager and events, which is particularly helpful when bootstrapping an application in Java SE:
*
*
*
* Foo foo = container.select(Foo.class).get();
* container.getBeanManager().fireEvent(new Bar())
* container.event().select(Bar.class).fire(new Bar());
*
*
* @author Peter Royle
* @author Martin Kouba
* @see Weld
*/
@Vetoed
public class WeldContainer extends AbstractCDI