Search in sources :

Example 6 with StartException

use of org.jboss.msc.service.StartException in project wildfly by wildfly.

the class PersistenceUnitServiceImpl method start.

@Override
public void start(final StartContext context) throws StartException {
    final ExecutorService executor = executorInjector.getValue();
    final AccessControlContext accessControlContext = AccessController.doPrivileged(GetAccessControlContextAction.getInstance());
    final Runnable task = new Runnable() {

        // run async in a background thread
        @Override
        public void run() {
            PrivilegedAction<Void> privilegedAction = new PrivilegedAction<Void>() {

                // run as security privileged action
                @Override
                public Void run() {
                    ClassLoader old = Thread.currentThread().getContextClassLoader();
                    Thread.currentThread().setContextClassLoader(classLoader);
                    if (javaNamespaceSetup != null) {
                        javaNamespaceSetup.setup(Collections.<String, Object>emptyMap());
                    }
                    try {
                        PhaseOnePersistenceUnitServiceImpl phaseOnePersistenceUnitService = phaseOnePersistenceUnitServiceInjectedValue.getOptionalValue();
                        WritableServiceBasedNamingStore.pushOwner(deploymentUnitServiceName);
                        Object wrapperBeanManagerLifeCycle = null;
                        // creating container EntityManagerFactory
                        if (validatorFactory != null) {
                            properties.getValue().put(VALIDATOR_FACTORY, validatorFactory);
                        }
                        // handle phase 2 of 2 of bootstrapping the persistence unit
                        if (phaseOnePersistenceUnitService != null) {
                            ROOT_LOGGER.startingPersistenceUnitService(2, pu.getScopedPersistenceUnitName());
                            // indicate that the second phase of bootstrapping the persistence unit has started
                            phaseOnePersistenceUnitService.setSecondPhaseStarted(true);
                            if (beanManagerInjector.getOptionalValue() != null) {
                                wrapperBeanManagerLifeCycle = phaseOnePersistenceUnitService.getBeanManagerLifeCycle();
                                // update the bean manager proxy to the actual CDI bean manager
                                proxyBeanManager = phaseOnePersistenceUnitService.getBeanManager();
                                proxyBeanManager.setDelegate(beanManagerInjector.getOptionalValue());
                            }
                            EntityManagerFactoryBuilder emfBuilder = phaseOnePersistenceUnitService.getEntityManagerFactoryBuilder();
                            // persistence unit bootstrap.
                            if (validatorFactory != null) {
                                emfBuilder.withValidatorFactory(validatorFactory);
                            }
                            // get the EntityManagerFactory from the second phase of the persistence unit bootstrap
                            entityManagerFactory = emfBuilder.build();
                        } else {
                            ROOT_LOGGER.startingService("Persistence Unit", pu.getScopedPersistenceUnitName());
                            // start the persistence unit in one pass (1 of 1)
                            pu.setTempClassLoaderFactory(new TempClassLoaderFactoryImpl(classLoader));
                            pu.setJtaDataSource(jtaDataSource.getOptionalValue());
                            pu.setNonJtaDataSource(nonJtaDataSource.getOptionalValue());
                            if (beanManagerInjector.getOptionalValue() != null) {
                                proxyBeanManager = new ProxyBeanManager();
                                proxyBeanManager.setDelegate(beanManagerInjector.getOptionalValue());
                                wrapperBeanManagerLifeCycle = persistenceProviderAdaptor.beanManagerLifeCycle(proxyBeanManager);
                                if (wrapperBeanManagerLifeCycle != null) {
                                    // pass the wrapper object representing the bean manager life cycle object
                                    properties.getValue().put(CDI_BEAN_MANAGER, wrapperBeanManagerLifeCycle);
                                } else {
                                    properties.getValue().put(CDI_BEAN_MANAGER, proxyBeanManager);
                                }
                            }
                            entityManagerFactory = createContainerEntityManagerFactory();
                        }
                        persistenceUnitRegistry.add(getScopedPersistenceUnitName(), getValue());
                        if (wrapperBeanManagerLifeCycle != null) {
                            beanManagerAfterDeploymentValidation.register(persistenceProviderAdaptor, wrapperBeanManagerLifeCycle);
                        }
                        context.complete();
                    } catch (Throwable t) {
                        context.failed(new StartException(t));
                    } finally {
                        Thread.currentThread().setContextClassLoader(old);
                        // release the temp classloader factory (only needed when creating the EMF)
                        pu.setTempClassLoaderFactory(null);
                        WritableServiceBasedNamingStore.popOwner();
                        if (javaNamespaceSetup != null) {
                            javaNamespaceSetup.teardown(Collections.<String, Object>emptyMap());
                        }
                    }
                    return null;
                }
            };
            WildFlySecurityManager.doChecked(privilegedAction, accessControlContext);
        }
    };
    try {
        executor.execute(task);
    } catch (RejectedExecutionException e) {
        task.run();
    } finally {
        context.asynchronous();
    }
}
Also used : EntityManagerFactoryBuilder(org.jipijapa.plugin.spi.EntityManagerFactoryBuilder) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) AccessControlContext(java.security.AccessControlContext) PrivilegedAction(java.security.PrivilegedAction) ExecutorService(java.util.concurrent.ExecutorService) TempClassLoaderFactoryImpl(org.jboss.as.jpa.classloader.TempClassLoaderFactoryImpl) ProxyBeanManager(org.jboss.as.jpa.beanmanager.ProxyBeanManager) StartException(org.jboss.msc.service.StartException)

Example 7 with StartException

use of org.jboss.msc.service.StartException in project wildfly by wildfly.

the class PhaseOnePersistenceUnitServiceImpl method start.

@Override
public void start(final StartContext context) throws StartException {
    final ExecutorService executor = executorInjector.getValue();
    final AccessControlContext accessControlContext = AccessController.doPrivileged(GetAccessControlContextAction.getInstance());
    final Runnable task = new Runnable() {

        // run async in a background thread
        @Override
        public void run() {
            PrivilegedAction<Void> privilegedAction = new PrivilegedAction<Void>() {

                // run as security privileged action
                @Override
                public Void run() {
                    try {
                        ROOT_LOGGER.startingPersistenceUnitService(1, pu.getScopedPersistenceUnitName());
                        pu.setTempClassLoaderFactory(new TempClassLoaderFactoryImpl(classLoader));
                        pu.setJtaDataSource(jtaDataSource.getOptionalValue());
                        pu.setNonJtaDataSource(nonJtaDataSource.getOptionalValue());
                        if (proxyBeanManager != null) {
                            if (wrapperBeanManagerLifeCycle != null) {
                                // pass the wrapper object representing the bean manager life cycle object
                                properties.getValue().put(CDI_BEAN_MANAGER, wrapperBeanManagerLifeCycle);
                            } else {
                                properties.getValue().put(CDI_BEAN_MANAGER, proxyBeanManager);
                            }
                        }
                        WritableServiceBasedNamingStore.pushOwner(deploymentUnitServiceName);
                        entityManagerFactoryBuilder = createContainerEntityManagerFactoryBuilder();
                        context.complete();
                    } catch (Throwable t) {
                        context.failed(new StartException(t));
                    } finally {
                        // release the temp classloader factory (only needed when creating the EMF)
                        pu.setTempClassLoaderFactory(null);
                        WritableServiceBasedNamingStore.popOwner();
                    }
                    return null;
                }
            };
            WildFlySecurityManager.doChecked(privilegedAction, accessControlContext);
        }
    };
    try {
        executor.execute(task);
    } catch (RejectedExecutionException e) {
        task.run();
    } finally {
        context.asynchronous();
    }
}
Also used : AccessControlContext(java.security.AccessControlContext) PrivilegedAction(java.security.PrivilegedAction) ExecutorService(java.util.concurrent.ExecutorService) TempClassLoaderFactoryImpl(org.jboss.as.jpa.classloader.TempClassLoaderFactoryImpl) StartException(org.jboss.msc.service.StartException) RejectedExecutionException(java.util.concurrent.RejectedExecutionException)

Example 8 with StartException

use of org.jboss.msc.service.StartException in project wildfly by wildfly.

the class AbstractPojoPhase method startInternal.

protected void startInternal(StartContext context) throws StartException {
    try {
        executeInstalls();
        // only after describe do we have a bean
        if (getLifecycleState().isAfter(BeanState.DESCRIBED)) {
            addCallbacks(true);
            addCallbacks(false);
            ServiceRegistry registry = context.getController().getServiceContainer();
            InstancesService.addInstance(registry, context.getChildTarget(), getLifecycleState(), getBean());
        }
        // do we have a next phase
        final AbstractPojoPhase nextPhase = createNextPhase();
        if (nextPhase != null) {
            final BeanState state = getLifecycleState();
            final BeanState next = state.next();
            final BeanMetaDataConfig beanConfig = getBeanConfig();
            final ServiceName name = BeanMetaDataConfig.toBeanName(beanConfig.getName(), next);
            final ServiceTarget serviceTarget = context.getChildTarget();
            final ServiceBuilder serviceBuilder = serviceTarget.addService(name, nextPhase);
            registerAliases(serviceBuilder, next);
            final ConfigVisitor visitor = new DefaultConfigVisitor(serviceBuilder, state, getModule(), getIndex(), getBeanInfo());
            beanConfig.visit(visitor);
            nextPhase.setModule(getModule());
            nextPhase.setBeanConfig(getBeanConfig());
            nextPhase.setIndex(getIndex());
            nextPhase.setBeanInfo(getBeanInfo());
            nextPhase.setBean(getBean());
            serviceBuilder.install();
        }
    } catch (Throwable t) {
        throw new StartException(t);
    }
}
Also used : DefaultConfigVisitor(org.jboss.as.pojo.descriptor.DefaultConfigVisitor) ConfigVisitor(org.jboss.as.pojo.descriptor.ConfigVisitor) DefaultConfigVisitor(org.jboss.as.pojo.descriptor.DefaultConfigVisitor) BeanState(org.jboss.as.pojo.BeanState) BeanMetaDataConfig(org.jboss.as.pojo.descriptor.BeanMetaDataConfig) ServiceName(org.jboss.msc.service.ServiceName) ServiceTarget(org.jboss.msc.service.ServiceTarget) StartException(org.jboss.msc.service.StartException) ServiceRegistry(org.jboss.msc.service.ServiceRegistry) ServiceBuilder(org.jboss.msc.service.ServiceBuilder)

Example 9 with StartException

use of org.jboss.msc.service.StartException in project wildfly by wildfly.

the class DescribedPojoPhase method startInternal.

@SuppressWarnings("unchecked")
protected void startInternal(StartContext context) throws StartException {
    try {
        setModule(getBeanConfig().getModule().getInjectedModule().getValue());
        String beanClass = getBeanConfig().getBeanClass();
        if (beanClass != null) {
            Class clazz = Class.forName(beanClass, false, getModule().getClassLoader());
            setBeanInfo(new DefaultBeanInfo(getIndex(), clazz));
        }
    } catch (Exception e) {
        throw new StartException(e);
    }
    super.startInternal(context);
}
Also used : StartException(org.jboss.msc.service.StartException) StartException(org.jboss.msc.service.StartException)

Example 10 with StartException

use of org.jboss.msc.service.StartException in project wildfly by wildfly.

the class ArjunaRecoveryManagerService method start.

public synchronized void start(StartContext context) throws StartException {
    // Recovery env bean
    final RecoveryEnvironmentBean recoveryEnvironmentBean = recoveryPropertyManager.getRecoveryEnvironmentBean();
    final SocketBinding recoveryBinding = recoveryBindingInjector.getValue();
    recoveryEnvironmentBean.setRecoveryInetAddress(recoveryBinding.getSocketAddress().getAddress());
    recoveryEnvironmentBean.setRecoveryPort(recoveryBinding.getSocketAddress().getPort());
    final SocketBinding statusBinding = statusBindingInjector.getValue();
    recoveryEnvironmentBean.setTransactionStatusManagerInetAddress(statusBinding.getSocketAddress().getAddress());
    recoveryEnvironmentBean.setTransactionStatusManagerPort(statusBinding.getSocketAddress().getPort());
    recoveryEnvironmentBean.setRecoveryListener(recoveryListener);
    if (recoveryListener) {
        ManagedBinding binding = ManagedBinding.Factory.createSimpleManagedBinding(recoveryBinding);
        bindingManager.getValue().getNamedRegistry().registerBinding(binding);
    }
    final List<String> recoveryExtensions = new ArrayList<String>();
    // must be first
    recoveryExtensions.add(CommitMarkableResourceRecordRecoveryModule.class.getName());
    recoveryExtensions.add(AtomicActionRecoveryModule.class.getName());
    recoveryExtensions.add(TORecoveryModule.class.getName());
    final List<String> expiryScanners;
    if (System.getProperty("RecoveryEnvironmentBean.expiryScannerClassNames") != null) {
        expiryScanners = recoveryEnvironmentBean.getExpiryScannerClassNames();
    } else {
        expiryScanners = new ArrayList<String>();
        expiryScanners.add(ExpiredTransactionStatusManagerScanner.class.getName());
    }
    if (!jts) {
        recoveryExtensions.add(com.arjuna.ats.internal.jta.recovery.arjunacore.XARecoveryModule.class.getName());
        recoveryEnvironmentBean.setRecoveryModuleClassNames(recoveryExtensions);
        recoveryEnvironmentBean.setExpiryScannerClassNames(expiryScanners);
        recoveryEnvironmentBean.setRecoveryActivators(null);
        final RecoveryManagerService recoveryManagerService = new RecoveryManagerService();
        try {
            recoveryManagerService.create();
        } catch (Exception e) {
            throw TransactionLogger.ROOT_LOGGER.managerStartFailure(e, "Recovery");
        }
        recoveryManagerService.start();
        this.recoveryManagerService = recoveryManagerService;
    } else {
        final ORB orb = orbInjector.getValue();
        new PostInitLoader(PostInitLoader.generateORBPropertyName("com.arjuna.orbportability.orb"), orb);
        recoveryExtensions.add(TopLevelTransactionRecoveryModule.class.getName());
        recoveryExtensions.add(ServerTransactionRecoveryModule.class.getName());
        recoveryExtensions.add(JCAServerTransactionRecoveryModule.class.getName());
        recoveryExtensions.add(com.arjuna.ats.internal.jta.recovery.jts.XARecoveryModule.class.getName());
        expiryScanners.add(ExpiredContactScanner.class.getName());
        expiryScanners.add(ExpiredToplevelScanner.class.getName());
        expiryScanners.add(ExpiredServerScanner.class.getName());
        recoveryEnvironmentBean.setRecoveryModuleClassNames(recoveryExtensions);
        recoveryEnvironmentBean.setExpiryScannerClassNames(expiryScanners);
        recoveryEnvironmentBean.setRecoveryActivatorClassNames(Collections.singletonList(com.arjuna.ats.internal.jts.orbspecific.recovery.RecoveryEnablement.class.getName()));
        try {
            final RecoveryManagerService recoveryManagerService = new com.arjuna.ats.jbossatx.jts.RecoveryManagerService(orb);
            recoveryManagerService.create();
            recoveryManagerService.start();
            this.recoveryManagerService = recoveryManagerService;
        } catch (Exception e) {
            throw TransactionLogger.ROOT_LOGGER.managerStartFailure(e, "Recovery");
        }
    }
    recoverySuspendController = new RecoverySuspendController(recoveryManagerService);
    suspendControllerInjector.getValue().registerActivity(recoverySuspendController);
}
Also used : SocketBinding(org.jboss.as.network.SocketBinding) ExpiredContactScanner(com.arjuna.ats.internal.jts.recovery.contact.ExpiredContactScanner) AtomicActionRecoveryModule(com.arjuna.ats.internal.arjuna.recovery.AtomicActionRecoveryModule) ExpiredTransactionStatusManagerScanner(com.arjuna.ats.internal.arjuna.recovery.ExpiredTransactionStatusManagerScanner) ArrayList(java.util.ArrayList) TopLevelTransactionRecoveryModule(com.arjuna.ats.internal.jts.recovery.transactions.TopLevelTransactionRecoveryModule) ManagedBinding(org.jboss.as.network.ManagedBinding) CommitMarkableResourceRecordRecoveryModule(com.arjuna.ats.internal.jta.recovery.arjunacore.CommitMarkableResourceRecordRecoveryModule) RecoveryManagerService(com.arjuna.ats.jbossatx.jta.RecoveryManagerService) PostInitLoader(com.arjuna.orbportability.internal.utils.PostInitLoader) StartException(org.jboss.msc.service.StartException) ExpiredToplevelScanner(com.arjuna.ats.internal.jts.recovery.transactions.ExpiredToplevelScanner) TORecoveryModule(com.arjuna.ats.internal.txoj.recovery.TORecoveryModule) RecoveryEnvironmentBean(com.arjuna.ats.arjuna.common.RecoveryEnvironmentBean) RecoverySuspendController(org.jboss.as.txn.suspend.RecoverySuspendController) JCAServerTransactionRecoveryModule(com.arjuna.ats.internal.jta.recovery.jts.JCAServerTransactionRecoveryModule) ServerTransactionRecoveryModule(com.arjuna.ats.internal.jts.recovery.transactions.ServerTransactionRecoveryModule) JCAServerTransactionRecoveryModule(com.arjuna.ats.internal.jta.recovery.jts.JCAServerTransactionRecoveryModule) ExpiredServerScanner(com.arjuna.ats.internal.jts.recovery.transactions.ExpiredServerScanner) ORB(org.omg.CORBA.ORB)

Aggregations

StartException (org.jboss.msc.service.StartException)43 IOException (java.io.IOException)5 ArrayList (java.util.ArrayList)5 ExecutorService (java.util.concurrent.ExecutorService)4 RejectedExecutionException (java.util.concurrent.RejectedExecutionException)4 ORB (org.omg.CORBA.ORB)4 InetSocketAddress (java.net.InetSocketAddress)3 PrivilegedAction (java.security.PrivilegedAction)3 HashMap (java.util.HashMap)3 PostInitLoader (com.arjuna.orbportability.internal.utils.PostInitLoader)2 HandlerWrapper (io.undertow.server.HandlerWrapper)2 HttpHandler (io.undertow.server.HttpHandler)2 File (java.io.File)2 AccessControlContext (java.security.AccessControlContext)2 Map (java.util.Map)2 TempClassLoaderFactoryImpl (org.jboss.as.jpa.classloader.TempClassLoaderFactoryImpl)2 SocketBinding (org.jboss.as.network.SocketBinding)2 ModuleLoadException (org.jboss.modules.ModuleLoadException)2 Service (org.jboss.msc.service.Service)2 ServiceContainer (org.jboss.msc.service.ServiceContainer)2