Search in sources :

Example 1 with SetupAction

use of org.jboss.as.server.deployment.SetupAction in project wildfly by wildfly.

the class AbstractService method invokeLifecycleMethod.

protected void invokeLifecycleMethod(final Method method, final LifecycleContext context) throws InvocationTargetException, IllegalAccessException {
    if (method != null) {
        try {
            for (SetupAction action : setupActions) {
                action.setup(Collections.<String, Object>emptyMap());
            }
            final ClassLoader old = WildFlySecurityManager.setCurrentContextClassLoaderPrivileged(this.mbeanContextClassLoader);
            try {
                method.invoke(mBeanInstance);
            } finally {
                WildFlySecurityManager.setCurrentContextClassLoaderPrivileged(old);
            }
        } finally {
            ListIterator<SetupAction> it = setupActions.listIterator(setupActions.size());
            while (it.hasPrevious()) {
                SetupAction action = it.previous();
                action.teardown(Collections.<String, Object>emptyMap());
            }
        }
    }
}
Also used : SetupAction(org.jboss.as.server.deployment.SetupAction)

Example 2 with SetupAction

use of org.jboss.as.server.deployment.SetupAction in project wildfly by wildfly.

the class UndertowDeploymentInfoService method start.

@Override
public synchronized void start(final StartContext startContext) throws StartException {
    ClassLoader oldTccl = Thread.currentThread().getContextClassLoader();
    try {
        Thread.currentThread().setContextClassLoader(module.getClassLoader());
        DeploymentInfo deploymentInfo = createServletConfig();
        deploymentInfo.setConfidentialPortManager(getConfidentialPortManager());
        handleDistributable(deploymentInfo);
        if (securityFunction.getOptionalValue() == null) {
            handleIdentityManager(deploymentInfo);
            handleJASPIMechanism(deploymentInfo);
            handleJACCAuthorization(deploymentInfo);
            handleAuthManagerLogout(deploymentInfo, mergedMetaData);
            if (mergedMetaData.isUseJBossAuthorization()) {
                deploymentInfo.setAuthorizationManager(new JbossAuthorizationManager(deploymentInfo.getAuthorizationManager()));
            }
        }
        handleAdditionalAuthenticationMechanisms(deploymentInfo);
        SessionConfigMetaData sessionConfig = mergedMetaData.getSessionConfig();
        if (sharedSessionManagerConfig != null && sharedSessionManagerConfig.getSessionConfig() != null) {
            sessionConfig = sharedSessionManagerConfig.getSessionConfig();
        }
        ServletSessionConfig config = null;
        //default session config
        SessionCookieConfig defaultSessionConfig = container.getValue().getSessionCookieConfig();
        if (defaultSessionConfig != null) {
            config = new ServletSessionConfig();
            if (defaultSessionConfig.getName() != null) {
                config.setName(defaultSessionConfig.getName());
            }
            if (defaultSessionConfig.getDomain() != null) {
                config.setDomain(defaultSessionConfig.getDomain());
            }
            if (defaultSessionConfig.getHttpOnly() != null) {
                config.setHttpOnly(defaultSessionConfig.getHttpOnly());
            }
            if (defaultSessionConfig.getSecure() != null) {
                config.setSecure(defaultSessionConfig.getSecure());
            }
            if (defaultSessionConfig.getMaxAge() != null) {
                config.setMaxAge(defaultSessionConfig.getMaxAge());
            }
            if (defaultSessionConfig.getComment() != null) {
                config.setComment(defaultSessionConfig.getComment());
            }
        }
        SecureRandomSessionIdGenerator sessionIdGenerator = new SecureRandomSessionIdGenerator();
        sessionIdGenerator.setLength(container.getValue().getSessionIdLength());
        deploymentInfo.setSessionIdGenerator(sessionIdGenerator);
        boolean sessionTimeoutSet = false;
        if (sessionConfig != null) {
            if (sessionConfig.getSessionTimeoutSet()) {
                deploymentInfo.setDefaultSessionTimeout(sessionConfig.getSessionTimeout() * 60);
                sessionTimeoutSet = true;
            }
            CookieConfigMetaData cookieConfig = sessionConfig.getCookieConfig();
            if (config == null) {
                config = new ServletSessionConfig();
            }
            if (cookieConfig != null) {
                if (cookieConfig.getName() != null) {
                    config.setName(cookieConfig.getName());
                }
                if (cookieConfig.getDomain() != null) {
                    config.setDomain(cookieConfig.getDomain());
                }
                if (cookieConfig.getComment() != null) {
                    config.setComment(cookieConfig.getComment());
                }
                config.setSecure(cookieConfig.getSecure());
                config.setPath(cookieConfig.getPath());
                config.setMaxAge(cookieConfig.getMaxAge());
                config.setHttpOnly(cookieConfig.getHttpOnly());
            }
            List<SessionTrackingModeType> modes = sessionConfig.getSessionTrackingModes();
            if (modes != null && !modes.isEmpty()) {
                final Set<SessionTrackingMode> trackingModes = new HashSet<>();
                for (SessionTrackingModeType mode : modes) {
                    switch(mode) {
                        case COOKIE:
                            trackingModes.add(SessionTrackingMode.COOKIE);
                            break;
                        case SSL:
                            trackingModes.add(SessionTrackingMode.SSL);
                            break;
                        case URL:
                            trackingModes.add(SessionTrackingMode.URL);
                            break;
                    }
                }
                config.setSessionTrackingModes(trackingModes);
            }
        }
        if (!sessionTimeoutSet) {
            deploymentInfo.setDefaultSessionTimeout(container.getValue().getDefaultSessionTimeout() * 60);
        }
        if (config != null) {
            deploymentInfo.setServletSessionConfig(config);
        }
        for (final SetupAction action : setupActions) {
            deploymentInfo.addThreadSetupAction(new UndertowThreadSetupAction(action));
        }
        if (initialHandlerChainWrappers != null) {
            for (HandlerWrapper handlerWrapper : initialHandlerChainWrappers) {
                deploymentInfo.addInitialHandlerChainWrapper(handlerWrapper);
            }
        }
        if (innerHandlerChainWrappers != null) {
            for (HandlerWrapper handlerWrapper : innerHandlerChainWrappers) {
                deploymentInfo.addInnerHandlerChainWrapper(handlerWrapper);
            }
        }
        if (outerHandlerChainWrappers != null) {
            for (HandlerWrapper handlerWrapper : outerHandlerChainWrappers) {
                deploymentInfo.addOuterHandlerChainWrapper(handlerWrapper);
            }
        }
        if (threadSetupActions != null) {
            for (ThreadSetupHandler threadSetupAction : threadSetupActions) {
                deploymentInfo.addThreadSetupAction(threadSetupAction);
            }
        }
        deploymentInfo.setServerName(serverEnvironmentInjectedValue.getValue().getProductConfig().getPrettyVersionString());
        if (undertowService.getValue().isStatisticsEnabled()) {
            deploymentInfo.setMetricsCollector(new UndertowMetricsCollector());
        }
        ControlPoint controlPoint = controlPointInjectedValue.getOptionalValue();
        if (controlPoint != null) {
            deploymentInfo.addOuterHandlerChainWrapper(GlobalRequestControllerHandler.wrapper(controlPoint, allowSuspendedRequests));
        }
        container.getValue().getAuthenticationMechanisms().entrySet().forEach(e -> deploymentInfo.addAuthenticationMechanism(e.getKey(), e.getValue()));
        deploymentInfo.setUseCachedAuthenticationMechanism(!deploymentInfo.getAuthenticationMechanisms().containsKey(SingleSignOnService.AUTHENTICATION_MECHANISM_NAME));
        this.deploymentInfo = deploymentInfo;
    } finally {
        Thread.currentThread().setContextClassLoader(oldTccl);
    }
}
Also used : SessionConfigMetaData(org.jboss.metadata.web.spec.SessionConfigMetaData) JbossAuthorizationManager(org.wildfly.extension.undertow.security.JbossAuthorizationManager) SessionTrackingMode(javax.servlet.SessionTrackingMode) CookieConfigMetaData(org.jboss.metadata.web.spec.CookieConfigMetaData) SetupAction(org.jboss.as.server.deployment.SetupAction) SecurityContextThreadSetupAction(org.wildfly.extension.undertow.security.SecurityContextThreadSetupAction) ControlPoint(org.wildfly.extension.requestcontroller.ControlPoint) ServletSessionConfig(io.undertow.servlet.api.ServletSessionConfig) HandlerWrapper(io.undertow.server.HandlerWrapper) ThreadSetupHandler(io.undertow.servlet.api.ThreadSetupHandler) SecureRandomSessionIdGenerator(io.undertow.server.session.SecureRandomSessionIdGenerator) SessionCookieConfig(org.wildfly.extension.undertow.SessionCookieConfig) DeploymentInfo(io.undertow.servlet.api.DeploymentInfo) WebSocketDeploymentInfo(io.undertow.websockets.jsr.WebSocketDeploymentInfo) SessionTrackingModeType(org.jboss.metadata.web.spec.SessionTrackingModeType) LinkedHashSet(java.util.LinkedHashSet) HashSet(java.util.HashSet)

Example 3 with SetupAction

use of org.jboss.as.server.deployment.SetupAction in project wildfly by wildfly.

the class WeldDeploymentProcessor method deploy.

@Override
public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
    final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
    final DeploymentUnit parent = Utils.getRootDeploymentUnit(deploymentUnit);
    final ServiceTarget serviceTarget = phaseContext.getServiceTarget();
    final ResourceRoot deploymentRoot = deploymentUnit.getAttachment(Attachments.DEPLOYMENT_ROOT);
    if (!WeldDeploymentMarker.isPartOfWeldDeployment(deploymentUnit)) {
        //if there are CDI annotation present and this is the top level deployment we log a warning
        if (deploymentUnit.getParent() == null && CdiAnnotationMarker.cdiAnnotationsPresent(deploymentUnit)) {
            WeldLogger.DEPLOYMENT_LOGGER.cdiAnnotationsButNotBeanArchive(deploymentUnit.getName());
        }
        return;
    }
    //add a dependency on the weld service to web deployments
    final ServiceName weldBootstrapServiceName = parent.getServiceName().append(WeldBootstrapService.SERVICE_NAME);
    ServiceName weldStartServiceName = parent.getServiceName().append(WeldStartService.SERVICE_NAME);
    deploymentUnit.addToAttachmentList(Attachments.WEB_DEPENDENCIES, weldStartServiceName);
    final Set<ServiceName> dependencies = new HashSet<ServiceName>();
    // we only start weld on top level deployments
    if (deploymentUnit.getParent() != null) {
        return;
    }
    WeldLogger.DEPLOYMENT_LOGGER.startingServicesForCDIDeployment(phaseContext.getDeploymentUnit().getName());
    final Module module = deploymentUnit.getAttachment(Attachments.MODULE);
    final ModuleSpecification moduleSpecification = deploymentUnit.getAttachment(Attachments.MODULE_SPECIFICATION);
    final Set<BeanDeploymentArchiveImpl> beanDeploymentArchives = new HashSet<BeanDeploymentArchiveImpl>();
    final Map<ModuleIdentifier, BeanDeploymentModule> bdmsByIdentifier = new HashMap<ModuleIdentifier, BeanDeploymentModule>();
    final Map<ModuleIdentifier, ModuleSpecification> moduleSpecByIdentifier = new HashMap<ModuleIdentifier, ModuleSpecification>();
    final Map<ModuleIdentifier, EEModuleDescriptor> eeModuleDescriptors = new HashMap<>();
    // the root module only has access to itself. For most deployments this will be the only module
    // for ear deployments this represents the ear/lib directory.
    // war and jar deployment visibility will depend on the dependencies that
    // exist in the application, and mirror inter module dependencies
    final BeanDeploymentModule rootBeanDeploymentModule = deploymentUnit.getAttachment(WeldAttachments.BEAN_DEPLOYMENT_MODULE);
    putIfValueNotNull(eeModuleDescriptors, module.getIdentifier(), rootBeanDeploymentModule.getModuleDescriptor());
    bdmsByIdentifier.put(module.getIdentifier(), rootBeanDeploymentModule);
    moduleSpecByIdentifier.put(module.getIdentifier(), moduleSpecification);
    beanDeploymentArchives.addAll(rootBeanDeploymentModule.getBeanDeploymentArchives());
    final List<DeploymentUnit> subDeployments = deploymentUnit.getAttachmentList(Attachments.SUB_DEPLOYMENTS);
    final Set<ClassLoader> subDeploymentLoaders = new HashSet<ClassLoader>();
    final ServiceLoader<DeploymentUnitDependenciesProvider> dependenciesProviders = ServiceLoader.load(DeploymentUnitDependenciesProvider.class, WildFlySecurityManager.getClassLoaderPrivileged(WeldDeploymentProcessor.class));
    final ServiceLoader<ModuleServicesProvider> moduleServicesProviders = ServiceLoader.load(ModuleServicesProvider.class, WildFlySecurityManager.getClassLoaderPrivileged(WeldDeploymentProcessor.class));
    getDependencies(deploymentUnit, dependencies, dependenciesProviders);
    for (DeploymentUnit subDeployment : subDeployments) {
        getDependencies(subDeployment, dependencies, dependenciesProviders);
        final Module subDeploymentModule = subDeployment.getAttachment(Attachments.MODULE);
        if (subDeploymentModule == null) {
            continue;
        }
        subDeploymentLoaders.add(subDeploymentModule.getClassLoader());
        final ModuleSpecification subDeploymentModuleSpec = subDeployment.getAttachment(Attachments.MODULE_SPECIFICATION);
        final BeanDeploymentModule bdm = subDeployment.getAttachment(WeldAttachments.BEAN_DEPLOYMENT_MODULE);
        if (bdm == null) {
            continue;
        }
        // add the modules bdas to the global set of bdas
        beanDeploymentArchives.addAll(bdm.getBeanDeploymentArchives());
        bdmsByIdentifier.put(subDeploymentModule.getIdentifier(), bdm);
        moduleSpecByIdentifier.put(subDeploymentModule.getIdentifier(), subDeploymentModuleSpec);
        putIfValueNotNull(eeModuleDescriptors, subDeploymentModule.getIdentifier(), bdm.getModuleDescriptor());
        //we have to do this here as the aggregate components are not available in earlier phases
        final ResourceRoot subDeploymentRoot = subDeployment.getAttachment(Attachments.DEPLOYMENT_ROOT);
        // Add module services to bean deployment module
        for (Entry<Class<? extends Service>, Service> entry : ServiceLoaders.loadModuleServices(moduleServicesProviders, deploymentUnit, subDeployment, subDeploymentModule, subDeploymentRoot).entrySet()) {
            bdm.addService(entry.getKey(), Reflections.cast(entry.getValue()));
        }
    }
    for (Map.Entry<ModuleIdentifier, BeanDeploymentModule> entry : bdmsByIdentifier.entrySet()) {
        final ModuleSpecification bdmSpec = moduleSpecByIdentifier.get(entry.getKey());
        final BeanDeploymentModule bdm = entry.getValue();
        if (bdm == rootBeanDeploymentModule) {
            // the root module only has access to itself
            continue;
        }
        for (ModuleDependency dependency : bdmSpec.getSystemDependencies()) {
            BeanDeploymentModule other = bdmsByIdentifier.get(dependency.getIdentifier());
            if (other != null && other != bdm) {
                bdm.addBeanDeploymentModule(other);
            }
        }
    }
    Map<Class<? extends Service>, Service> rootModuleServices = ServiceLoaders.loadModuleServices(moduleServicesProviders, deploymentUnit, deploymentUnit, module, deploymentRoot);
    // Add root module services to root bean deployment module
    for (Entry<Class<? extends Service>, Service> entry : rootModuleServices.entrySet()) {
        rootBeanDeploymentModule.addService(entry.getKey(), Reflections.cast(entry.getValue()));
    }
    // Add root module services to additional bean deployment archives
    for (final BeanDeploymentArchiveImpl additional : deploymentUnit.getAttachmentList(WeldAttachments.ADDITIONAL_BEAN_DEPLOYMENT_MODULES)) {
        beanDeploymentArchives.add(additional);
        for (Entry<Class<? extends Service>, Service> entry : rootModuleServices.entrySet()) {
            additional.getServices().add(entry.getKey(), Reflections.cast(entry.getValue()));
        }
    }
    final Collection<Metadata<Extension>> extensions = WeldPortableExtensions.getPortableExtensions(deploymentUnit).getExtensions();
    final WeldDeployment deployment = new WeldDeployment(beanDeploymentArchives, extensions, module, subDeploymentLoaders, deploymentUnit, rootBeanDeploymentModule, eeModuleDescriptors);
    final WeldBootstrapService weldBootstrapService = new WeldBootstrapService(deployment, WildFlyWeldEnvironment.INSTANCE, deploymentUnit.getName());
    installBootstrapConfigurationService(deployment, parent);
    // Add root module services to WeldDeployment
    for (Entry<Class<? extends Service>, Service> entry : rootModuleServices.entrySet()) {
        weldBootstrapService.addWeldService(entry.getKey(), Reflections.cast(entry.getValue()));
    }
    // add the weld service
    final ServiceBuilder<WeldBootstrapService> weldBootstrapServiceBuilder = serviceTarget.addService(weldBootstrapServiceName, weldBootstrapService);
    weldBootstrapServiceBuilder.addDependencies(TCCLSingletonService.SERVICE_NAME);
    weldBootstrapServiceBuilder.addDependency(WeldExecutorServices.SERVICE_NAME, ExecutorServices.class, weldBootstrapService.getExecutorServices());
    weldBootstrapServiceBuilder.addDependency(Services.JBOSS_SERVER_EXECUTOR, ExecutorService.class, weldBootstrapService.getServerExecutor());
    // Install additional services
    final ServiceLoader<BootstrapDependencyInstaller> installers = ServiceLoader.load(BootstrapDependencyInstaller.class, WildFlySecurityManager.getClassLoaderPrivileged(WeldDeploymentProcessor.class));
    for (BootstrapDependencyInstaller installer : installers) {
        ServiceName serviceName = installer.install(serviceTarget, deploymentUnit, jtsEnabled);
        // Add dependency for recognized services
        if (ServiceNames.WELD_SECURITY_SERVICES_SERVICE_NAME.getSimpleName().equals(serviceName.getSimpleName())) {
            weldBootstrapServiceBuilder.addDependency(serviceName, SecurityServices.class, weldBootstrapService.getSecurityServices());
        } else if (ServiceNames.WELD_TRANSACTION_SERVICES_SERVICE_NAME.getSimpleName().equals(serviceName.getSimpleName())) {
            weldBootstrapServiceBuilder.addDependency(serviceName, TransactionServices.class, weldBootstrapService.getWeldTransactionServices());
        }
    }
    weldBootstrapServiceBuilder.install();
    final List<SetupAction> setupActions = new ArrayList<SetupAction>();
    JavaNamespaceSetup naming = deploymentUnit.getAttachment(org.jboss.as.ee.naming.Attachments.JAVA_NAMESPACE_SETUP_ACTION);
    if (naming != null) {
        setupActions.add(naming);
    }
    final WeldStartService weldStartService = new WeldStartService(setupActions, module.getClassLoader(), Utils.getRootDeploymentUnit(deploymentUnit).getServiceName());
    ServiceBuilder<WeldStartService> startService = serviceTarget.addService(weldStartServiceName, weldStartService).addDependency(weldBootstrapServiceName, WeldBootstrapService.class, weldStartService.getBootstrap()).addDependencies(dependencies);
    // make sure JNDI bindings are up
    startService.addDependency(JndiNamingDependencyProcessor.serviceName(deploymentUnit));
    // [WFLY-5232]
    startService.addDependencies(getJNDISubsytemDependencies());
    final EarMetaData earConfig = deploymentUnit.getAttachment(org.jboss.as.ee.structure.Attachments.EAR_METADATA);
    if (earConfig == null || !earConfig.getInitializeInOrder()) {
        // in-order install of sub-deployments may result in service dependencies deadlocks if the jndi dependency services of subdeployments are added as dependencies
        for (DeploymentUnit sub : subDeployments) {
            startService.addDependency(JndiNamingDependencyProcessor.serviceName(sub));
        }
    }
    startService.install();
}
Also used : ModuleDependency(org.jboss.as.server.deployment.module.ModuleDependency) HashMap(java.util.HashMap) Metadata(org.jboss.weld.bootstrap.spi.Metadata) ArrayList(java.util.ArrayList) DeploymentUnitDependenciesProvider(org.jboss.as.weld.spi.DeploymentUnitDependenciesProvider) WeldDeployment(org.jboss.as.weld.deployment.WeldDeployment) EarMetaData(org.jboss.metadata.ear.spec.EarMetaData) ResourceRoot(org.jboss.as.server.deployment.module.ResourceRoot) BootstrapDependencyInstaller(org.jboss.as.weld.spi.BootstrapDependencyInstaller) WeldStartService(org.jboss.as.weld.WeldStartService) ModuleIdentifier(org.jboss.modules.ModuleIdentifier) WeldBootstrapService(org.jboss.as.weld.WeldBootstrapService) HashSet(java.util.HashSet) ModuleServicesProvider(org.jboss.as.weld.spi.ModuleServicesProvider) BeanDeploymentArchiveImpl(org.jboss.as.weld.deployment.BeanDeploymentArchiveImpl) JavaNamespaceSetup(org.jboss.as.ee.naming.JavaNamespaceSetup) ServiceTarget(org.jboss.msc.service.ServiceTarget) TCCLSingletonService(org.jboss.as.weld.services.TCCLSingletonService) DefaultNamespaceContextSelectorService(org.jboss.as.naming.service.DefaultNamespaceContextSelectorService) Service(org.jboss.weld.bootstrap.api.Service) WeldBootstrapService(org.jboss.as.weld.WeldBootstrapService) NamingService(org.jboss.as.naming.service.NamingService) WeldStartService(org.jboss.as.weld.WeldStartService) ExecutorService(java.util.concurrent.ExecutorService) SetupAction(org.jboss.as.server.deployment.SetupAction) ServiceName(org.jboss.msc.service.ServiceName) TransactionServices(org.jboss.weld.transaction.spi.TransactionServices) ModuleSpecification(org.jboss.as.server.deployment.module.ModuleSpecification) Module(org.jboss.modules.Module) BeanDeploymentModule(org.jboss.as.weld.deployment.BeanDeploymentModule) BeanDeploymentModule(org.jboss.as.weld.deployment.BeanDeploymentModule) DeploymentUnit(org.jboss.as.server.deployment.DeploymentUnit) Map(java.util.Map) HashMap(java.util.HashMap) EEModuleDescriptor(org.jboss.weld.bootstrap.spi.EEModuleDescriptor)

Example 4 with SetupAction

use of org.jboss.as.server.deployment.SetupAction in project wildfly by wildfly.

the class ApplicationClientStartService method start.

@Override
public synchronized void start(final StartContext context) throws StartException {
    final ServiceContainer serviceContainer = context.getController().getServiceContainer();
    thread = new Thread(new Runnable() {

        @Override
        public void run() {
            final ClassLoader oldTccl = WildFlySecurityManager.getCurrentContextClassLoaderPrivileged();
            try {
                try {
                    WildFlySecurityManager.setCurrentContextClassLoaderPrivileged(classLoader);
                    applicationClientDeploymentServiceInjectedValue.getValue().getDeploymentCompleteLatch().await();
                    NamespaceContextSelector.setDefault(namespaceContextSelectorInjectedValue);
                    try {
                        //perform any additional setup that may be needed
                        for (SetupAction action : setupActions) {
                            action.setup(Collections.<String, Object>emptyMap());
                        }
                        //do static injection etc
                        instance = applicationClientComponent.getValue().createInstance();
                        mainMethod.invoke(null, new Object[] { parameters });
                    } finally {
                        final ListIterator<SetupAction> iterator = setupActions.listIterator(setupActions.size());
                        Throwable error = null;
                        while (iterator.hasPrevious()) {
                            SetupAction action = iterator.previous();
                            try {
                                action.teardown(Collections.<String, Object>emptyMap());
                            } catch (Throwable e) {
                                error = e;
                            }
                        }
                        if (error != null) {
                            throw new RuntimeException(error);
                        }
                    }
                } catch (Exception e) {
                    ROOT_LOGGER.exceptionRunningAppClient(e, e.getClass().getSimpleName());
                } finally {
                    WildFlySecurityManager.setCurrentContextClassLoaderPrivileged(oldTccl);
                }
            } finally {
                serviceContainer.shutdown();
            }
        }
    });
    thread.start();
    Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {

        @Override
        public void run() {
            if (serviceContainer != null) {
                serviceContainer.shutdown();
            }
        }
    }));
}
Also used : ServiceContainer(org.jboss.msc.service.ServiceContainer) SetupAction(org.jboss.as.server.deployment.SetupAction) StartException(org.jboss.msc.service.StartException)

Example 5 with SetupAction

use of org.jboss.as.server.deployment.SetupAction in project wildfly by wildfly.

the class WeldStartService method start.

@Override
public void start(final StartContext context) throws StartException {
    /*
         * Weld service restarts are not supported. Therefore, if we detect that Weld is being restarted we
         * trigger restart of the entire deployment.
         */
    if (runOnce.get()) {
        ServiceController<?> controller = context.getController().getServiceContainer().getService(deploymentServiceName);
        controller.addListener(new AbstractServiceListener<Object>() {

            @Override
            public void transition(final ServiceController<?> controller, final ServiceController.Transition transition) {
                if (transition.getAfter().equals(ServiceController.Substate.DOWN)) {
                    controller.setMode(Mode.ACTIVE);
                    controller.removeListener(this);
                }
            }
        });
        controller.setMode(Mode.NEVER);
        return;
    }
    runOnce.set(true);
    ClassLoader oldTccl = WildFlySecurityManager.getCurrentContextClassLoaderPrivileged();
    try {
        for (SetupAction action : setupActions) {
            action.setup(null);
        }
        WildFlySecurityManager.setCurrentContextClassLoaderPrivileged(classLoader);
        bootstrap.getValue().getBootstrap().startInitialization();
        bootstrap.getValue().getBootstrap().deployBeans();
        bootstrap.getValue().getBootstrap().validateBeans();
        bootstrap.getValue().getBootstrap().endInitialization();
    } finally {
        for (SetupAction action : setupActions) {
            try {
                action.teardown(null);
            } catch (Exception e) {
                WeldLogger.DEPLOYMENT_LOGGER.exceptionClearingThreadState(e);
            }
        }
        WildFlySecurityManager.setCurrentContextClassLoaderPrivileged(oldTccl);
    }
}
Also used : ServiceController(org.jboss.msc.service.ServiceController) SetupAction(org.jboss.as.server.deployment.SetupAction) StartException(org.jboss.msc.service.StartException)

Aggregations

SetupAction (org.jboss.as.server.deployment.SetupAction)7 HashSet (java.util.HashSet)3 DeploymentUnit (org.jboss.as.server.deployment.DeploymentUnit)3 Module (org.jboss.modules.Module)3 DeploymentInfo (io.undertow.servlet.api.DeploymentInfo)2 DeploymentUnitProcessingException (org.jboss.as.server.deployment.DeploymentUnitProcessingException)2 ResourceRoot (org.jboss.as.server.deployment.module.ResourceRoot)2 ServiceName (org.jboss.msc.service.ServiceName)2 StartException (org.jboss.msc.service.StartException)2 HandlerWrapper (io.undertow.server.HandlerWrapper)1 SecureRandomSessionIdGenerator (io.undertow.server.session.SecureRandomSessionIdGenerator)1 ServletSessionConfig (io.undertow.servlet.api.ServletSessionConfig)1 ThreadSetupHandler (io.undertow.servlet.api.ThreadSetupHandler)1 WebSocketDeploymentInfo (io.undertow.websockets.jsr.WebSocketDeploymentInfo)1 File (java.io.File)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 Method (java.lang.reflect.Method)1 MalformedURLException (java.net.MalformedURLException)1 URL (java.net.URL)1