Package org.apache.deltaspike.cdise.api

Examples of org.apache.deltaspike.cdise.api.ContextControl


        {
            try
            {
                automaticScopeHandlingActive.set(Boolean.TRUE);

                ContextControl contextControl = container.getContextControl();

                List<Class<? extends Annotation>> scopeClasses = new ArrayList<Class<? extends Annotation>>();

                Collections.addAll(scopeClasses, this.testControl.startScopes());

                if (this.testControl.startScopes().length == 0)
                {
                    addScopesForDefaultBehavior(scopeClasses);
                }

                for (Class<? extends Annotation> scopeAnnotation : scopeClasses)
                {
                    if (this.parent != null && this.parent.isScopeStarted(scopeAnnotation))
                    {
                        continue;
                    }

                    if (isRestrictedScope(scopeAnnotation, restrictedScopes))
                    {
                        continue;
                    }

                    try
                    {
                        //force a clean context - TODO discuss onScopeStopped call
                        contextControl.stopContext(scopeAnnotation);

                        contextControl.startContext(scopeAnnotation);
                        this.startedScopes.add(scopeAnnotation);

                        onScopeStarted(scopeAnnotation);
                    }
                    catch (RuntimeException e)
View Full Code Here


    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());
View Full Code Here

    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();
    }
View Full Code Here

    {

        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();
View Full Code Here

            CdiTestSuiteRunner.setContainerStarted(true);
        }

        private void startScopes(CdiContainer container, Class<? extends Annotation>... restrictedScopes)
        {
            ContextControl contextControl = container.getContextControl();

            List<Class<? extends Annotation>> scopeClasses = new ArrayList<Class<? extends Annotation>>();

            Collections.addAll(scopeClasses, this.testControl.startScopes());

            if (this.testControl.startScopes().length == 0)
            {
                addScopesForDefaultBehavior(scopeClasses);
            }

            for (Class<? extends Annotation> scopeAnnotation : scopeClasses)
            {
                if (this.parent != null && this.parent.isScopeStarted(scopeAnnotation))
                {
                    continue;
                }

                if (isRestrictedScope(scopeAnnotation, restrictedScopes))
                {
                    continue;
                }

                try
                {
                    //force a clean context - TODO discuss onScopeStopped call
                    contextControl.stopContext(scopeAnnotation);

                    contextControl.startContext(scopeAnnotation);
                    this.startedScopes.add(scopeAnnotation);

                    onScopeStarted(scopeAnnotation);
                }
                catch (RuntimeException e)
View Full Code Here

    @Override
    public void requestDestroyed(ServletRequestEvent servletRequestEvent)
    {
        LOG.log(Level.FINER,"Request done.");
        ContextControl contextControl = (ContextControl)servletRequestEvent.getServletRequest()
                .getAttribute(CDI_REQ_CONTEXT);
        contextControl.stopContext(RequestScoped.class);
    }
View Full Code Here

    @Override
    public void requestInitialized(ServletRequestEvent servletRequestEvent)
    {
        LOG.log(Level.FINER,"Incoming request.");
        ContextControl contextControl = getContextControl();
        servletRequestEvent.getServletRequest().setAttribute(CDI_REQ_CONTEXT, contextControl);
        contextControl.startContext(RequestScoped.class);
    }
View Full Code Here

        // Start the CDI container
        CdiContainer cdiContainer = CdiContainerLoader.getCdiContainer();
        cdiContainer.boot();

        // Starting the application-context allows to use @ApplicationScoped beans
        ContextControl contextControl = cdiContainer.getContextControl();
        contextControl.startContext(ApplicationScoped.class);

        MainApplication main = BeanProvider.getContextualReference(MainApplication.class, false);

        main.run();
        // Stop de CDI container
View Full Code Here

TOP

Related Classes of org.apache.deltaspike.cdise.api.ContextControl

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.