Search in sources :

Example 6 with CdiContainer

use of org.apache.deltaspike.cdise.api.CdiContainer in project HotswapAgent by HotswapProjects.

the class HAAbstractUnitTest method startContainer.

protected void startContainer() {
    CdiContainer cdiContainer = CdiContainerLoader.getCdiContainer();
    cdiContainer.boot();
    ContextControl contextControl = cdiContainer.getContextControl();
    contextControl.startContext(ApplicationScoped.class);
    contextControl.startContext(SessionScoped.class);
    contextControl.startContext(RequestScoped.class);
}
Also used : ContextControl(org.apache.deltaspike.cdise.api.ContextControl) CdiContainer(org.apache.deltaspike.cdise.api.CdiContainer)

Example 7 with CdiContainer

use of org.apache.deltaspike.cdise.api.CdiContainer in project camel by apache.

the class Main method doStart.

@Override
protected void doStart() throws Exception {
    // TODO: Use standard CDI Java SE support when CDI 2.0 becomes a prerequisite
    CdiContainer container = getCdiContainer();
    container.boot();
    container.getContextControl().startContexts();
    cdiContainer = container;
    super.doStart();
    postProcessContext();
    warnIfNoCamelFound();
}
Also used : CdiContainer(org.apache.deltaspike.cdise.api.CdiContainer) CdiContainerLoader.getCdiContainer(org.apache.deltaspike.cdise.api.CdiContainerLoader.getCdiContainer)

Example 8 with CdiContainer

use of org.apache.deltaspike.cdise.api.CdiContainer in project deltaspike by apache.

the class SimpleSchedulerExample method main.

public static void main(String[] args) throws InterruptedException {
    CdiContainer cdiContainer = CdiContainerLoader.getCdiContainer();
    cdiContainer.boot();
    ContextControl contextControl = cdiContainer.getContextControl();
    contextControl.startContext(ApplicationScoped.class);
    GlobalResultHolder globalResultHolder = BeanProvider.getContextualReference(GlobalResultHolder.class);
    while (globalResultHolder.getCount() < 100) {
        Thread.sleep(500);
        LOG.info("current count: " + globalResultHolder.getCount());
    }
    LOG.info("completed!");
    contextControl.stopContext(ApplicationScoped.class);
    cdiContainer.shutdown();
}
Also used : ContextControl(org.apache.deltaspike.cdise.api.ContextControl) CdiContainer(org.apache.deltaspike.cdise.api.CdiContainer)

Example 9 with CdiContainer

use of org.apache.deltaspike.cdise.api.CdiContainer in project deltaspike by apache.

the class ConfigExample method main.

public static void main(String[] args) {
    CdiContainer cdiContainer = CdiContainerLoader.getCdiContainer();
    cdiContainer.boot();
    ContextControl contextControl = cdiContainer.getContextControl();
    contextControl.startContext(ApplicationScoped.class);
    SettingsBean settingsBean = BeanProvider.getContextualReference(SettingsBean.class, false);
    LOG.info("configured int-value #1: " + settingsBean.getIntProperty1());
    LOG.info("configured long-value #2: " + settingsBean.getProperty2());
    LOG.info("configured inverse-value #2: " + settingsBean.getInverseProperty());
    LOG.info("configured location (custom config): " + settingsBean.getLocationId().name());
    cdiContainer.shutdown();
}
Also used : ContextControl(org.apache.deltaspike.cdise.api.ContextControl) CdiContainer(org.apache.deltaspike.cdise.api.CdiContainer)

Example 10 with CdiContainer

use of org.apache.deltaspike.cdise.api.CdiContainer in project deltaspike by apache.

the class SimpleBeanLookupExample method main.

/**
     * Entry point
     *
     * @param args currently not used
     */
public static void main(String[] args) {
    CdiContainer cdiContainer = CdiContainerLoader.getCdiContainer();
    cdiContainer.boot();
    ContextControl contextControl = cdiContainer.getContextControl();
    contextControl.startContext(ApplicationScoped.class);
    //containerControl.startContexts();
    //or:
    //cdiContainer.start();
    List<EchoService> echoServiceList = BeanProvider.getContextualReferences(EchoService.class, false);
    for (EchoService echoService : echoServiceList) {
        LOG.info(echoService.echo("Hello CDI bean!"));
    }
    LOG.info("---");
    echoServiceList = BeanProvider.getContextualReferences(EchoService.class, false, false);
    for (EchoService echoService : echoServiceList) {
        LOG.info(echoService.echo("Hello non dependent CDI scoped bean!"));
    }
    LOG.info("---");
    EchoService defaultEchoService = BeanProvider.getContextualReference(DefaultEchoService.class, false);
    LOG.info(defaultEchoService.echo("Hello explicitly resolved CDI bean!"));
    defaultEchoService = BeanProvider.getContextualReference("defaultEchoService", false, EchoService.class);
    LOG.info(defaultEchoService.echo("Hello CDI bean resolved by name!"));
    OptionalService optionalService = BeanProvider.getContextualReference(OptionalService.class, true);
    if (optionalService == null) {
        LOG.info("No (optional) implementation found for " + OptionalService.class.getName());
    } else {
        LOG.severe("Unexpected implementation found: " + optionalService.getClass().getName());
    }
    contextControl.stopContext(ApplicationScoped.class);
    cdiContainer.shutdown();
//or:
//containerControl.stopContexts();
//cdiContainer.shutdownContainer();
//cdiContainer.stopContext(ApplicationScoped.class); //doesn't work with weld right now - see WELD-1072
}
Also used : DefaultEchoService(org.apache.deltaspike.example.echo.DefaultEchoService) EchoService(org.apache.deltaspike.example.echo.EchoService) ContextControl(org.apache.deltaspike.cdise.api.ContextControl) OptionalService(org.apache.deltaspike.example.optional.OptionalService) CdiContainer(org.apache.deltaspike.cdise.api.CdiContainer)

Aggregations

CdiContainer (org.apache.deltaspike.cdise.api.CdiContainer)15 Test (org.junit.Test)8 BeanManager (javax.enterprise.inject.spi.BeanManager)6 ContextControl (org.apache.deltaspike.cdise.api.ContextControl)5 CarRepair (org.apache.deltaspike.cdise.tck.beans.CarRepair)5 Bean (javax.enterprise.inject.spi.Bean)4 Car (org.apache.deltaspike.cdise.tck.beans.Car)3 ContextNotActiveException (javax.enterprise.context.ContextNotActiveException)2 Connection (java.sql.Connection)1 SQLException (java.sql.SQLException)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 NamingException (javax.naming.NamingException)1 DataSource (javax.sql.DataSource)1 CdiContainerLoader.getCdiContainer (org.apache.deltaspike.cdise.api.CdiContainerLoader.getCdiContainer)1 Foo (org.apache.deltaspike.cdise.openejb.bean.Foo)1 TestUser (org.apache.deltaspike.cdise.tck.beans.TestUser)1 LockedCDIImplementation (org.apache.deltaspike.cdise.tck.control.LockedCDIImplementation)1 DefaultEchoService (org.apache.deltaspike.example.echo.DefaultEchoService)1 EchoService (org.apache.deltaspike.example.echo.EchoService)1 OptionalService (org.apache.deltaspike.example.optional.OptionalService)1