Search in sources :

Example 16 with TransactionSynchronizationRegistry

use of javax.transaction.TransactionSynchronizationRegistry in project wildfly by wildfly.

the class TransactionSubsystemAdd method performBoottime.

@Override
protected void performBoottime(OperationContext context, ModelNode operation, ModelNode model) throws OperationFailedException {
    checkIfNodeIdentifierIsDefault(context, model);
    boolean jts = model.hasDefined(JTS) && model.get(JTS).asBoolean();
    final Resource subsystemResource = context.readResourceFromRoot(PathAddress.pathAddress(TransactionExtension.SUBSYSTEM_PATH));
    final List<ServiceName> deps = new LinkedList<>();
    for (Resource.ResourceEntry re : subsystemResource.getChildren(CM_RESOURCE)) {
        deps.add(TxnServices.JBOSS_TXN_CMR.append(re.getName()));
    }
    //recovery environment
    performRecoveryEnvBoottime(context, model, jts, deps);
    //core environment
    performCoreEnvironmentBootTime(context, model);
    //coordinator environment
    performCoordinatorEnvBoottime(context, model, jts);
    //object store
    performObjectStoreBoottime(context, model);
    //always propagate the transaction context
    //TODO: need a better way to do this, but this value gets cached in a static
    //so we need to make sure we set it before anything tries to read it
    jtsPropertyManager.getJTSEnvironmentBean().setAlwaysPropagateContext(true);
    context.addStep(new AbstractDeploymentChainStep() {

        protected void execute(final DeploymentProcessorTarget processorTarget) {
            processorTarget.addDeploymentProcessor(TransactionExtension.SUBSYSTEM_NAME, Phase.PARSE, Phase.PARSE_TRANSACTION_ROLLBACK_ACTION, new TransactionLeakRollbackProcessor());
            processorTarget.addDeploymentProcessor(TransactionExtension.SUBSYSTEM_NAME, Phase.POST_MODULE, Phase.POST_MODULE_TRANSACTIONS_EE_CONCURRENCY, new EEConcurrencyContextHandleFactoryProcessor());
            processorTarget.addDeploymentProcessor(TransactionExtension.SUBSYSTEM_NAME, Phase.INSTALL, Phase.INSTALL_TRANSACTION_BINDINGS, new TransactionJndiBindingProcessor());
            processorTarget.addDeploymentProcessor(TransactionExtension.SUBSYSTEM_NAME, Phase.DEPENDENCIES, Phase.DEPENDENCIES_TRANSACTIONS, new TransactionDependenciesProcessor());
            processorTarget.addDeploymentProcessor(TransactionExtension.SUBSYSTEM_NAME, Phase.DEPENDENCIES, Phase.DEPENDENCIES_TRANSACTIONS, new CompensationsDependenciesDeploymentProcessor());
        }
    }, OperationContext.Stage.RUNTIME);
    //bind the TransactionManger and the TSR into JNDI
    final BinderService tmBinderService = new BinderService("TransactionManager");
    final ServiceBuilder<ManagedReferenceFactory> tmBuilder = context.getServiceTarget().addService(ContextNames.JBOSS_CONTEXT_SERVICE_NAME.append("TransactionManager"), tmBinderService);
    tmBuilder.addDependency(ContextNames.JBOSS_CONTEXT_SERVICE_NAME, ServiceBasedNamingStore.class, tmBinderService.getNamingStoreInjector());
    tmBuilder.addDependency(TransactionManagerService.SERVICE_NAME, javax.transaction.TransactionManager.class, new Injector<javax.transaction.TransactionManager>() {

        @Override
        public void inject(final javax.transaction.TransactionManager value) throws InjectionException {
            tmBinderService.getManagedObjectInjector().inject(new ValueManagedReferenceFactory(new ImmediateValue<Object>(value)));
        }

        @Override
        public void uninject() {
            tmBinderService.getManagedObjectInjector().uninject();
        }
    });
    tmBuilder.install();
    final BinderService tmLegacyBinderService = new BinderService("TransactionManager");
    final ServiceBuilder<ManagedReferenceFactory> tmLegacyBuilder = context.getServiceTarget().addService(ContextNames.JAVA_CONTEXT_SERVICE_NAME.append("TransactionManager"), tmLegacyBinderService);
    tmLegacyBuilder.addDependency(ContextNames.JAVA_CONTEXT_SERVICE_NAME, ServiceBasedNamingStore.class, tmLegacyBinderService.getNamingStoreInjector());
    tmLegacyBuilder.addDependency(TransactionManagerService.SERVICE_NAME, javax.transaction.TransactionManager.class, new Injector<javax.transaction.TransactionManager>() {

        @Override
        public void inject(final javax.transaction.TransactionManager value) throws InjectionException {
            tmLegacyBinderService.getManagedObjectInjector().inject(new ValueManagedReferenceFactory(new ImmediateValue<Object>(value)));
        }

        @Override
        public void uninject() {
            tmLegacyBinderService.getManagedObjectInjector().uninject();
        }
    });
    tmLegacyBuilder.install();
    final BinderService tsrBinderService = new BinderService("TransactionSynchronizationRegistry");
    final ServiceBuilder<ManagedReferenceFactory> tsrBuilder = context.getServiceTarget().addService(ContextNames.JBOSS_CONTEXT_SERVICE_NAME.append("TransactionSynchronizationRegistry"), tsrBinderService);
    tsrBuilder.addDependency(ContextNames.JBOSS_CONTEXT_SERVICE_NAME, ServiceBasedNamingStore.class, tsrBinderService.getNamingStoreInjector());
    tsrBuilder.addDependency(TransactionSynchronizationRegistryService.SERVICE_NAME, TransactionSynchronizationRegistry.class, new Injector<TransactionSynchronizationRegistry>() {

        @Override
        public void inject(final TransactionSynchronizationRegistry value) throws InjectionException {
            tsrBinderService.getManagedObjectInjector().inject(new ValueManagedReferenceFactory(new ImmediateValue<Object>(value)));
        }

        @Override
        public void uninject() {
            tsrBinderService.getManagedObjectInjector().uninject();
        }
    });
    tsrBuilder.install();
    // Install the UserTransactionAccessControlService
    final UserTransactionAccessControlService lookupControlService = new UserTransactionAccessControlService();
    context.getServiceTarget().addService(UserTransactionAccessControlService.SERVICE_NAME, lookupControlService).install();
    // Bind the UserTransaction into JNDI
    final UserTransactionBindingService userTransactionBindingService = new UserTransactionBindingService("UserTransaction");
    final ServiceBuilder<ManagedReferenceFactory> utBuilder = context.getServiceTarget().addService(ContextNames.JBOSS_CONTEXT_SERVICE_NAME.append("UserTransaction"), userTransactionBindingService);
    utBuilder.addDependency(ContextNames.JBOSS_CONTEXT_SERVICE_NAME, ServiceBasedNamingStore.class, userTransactionBindingService.getNamingStoreInjector()).addDependency(UserTransactionAccessControlService.SERVICE_NAME, UserTransactionAccessControlService.class, userTransactionBindingService.getUserTransactionAccessControlServiceInjector()).addDependency(UserTransactionService.SERVICE_NAME, UserTransaction.class, new ManagedReferenceInjector<UserTransaction>(userTransactionBindingService.getManagedObjectInjector()));
    utBuilder.install();
    // install the EE Concurrency transaction setup provider's service
    final TransactionSetupProviderService transactionSetupProviderService = new TransactionSetupProviderService();
    context.getServiceTarget().addService(ConcurrentServiceNames.TRANSACTION_SETUP_PROVIDER_SERVICE_NAME, transactionSetupProviderService).addDependency(TransactionManagerService.SERVICE_NAME, TransactionManager.class, transactionSetupProviderService.getTransactionManagerInjectedValue()).install();
}
Also used : TransactionLeakRollbackProcessor(org.jboss.as.txn.deployment.TransactionLeakRollbackProcessor) EEConcurrencyContextHandleFactoryProcessor(org.jboss.as.txn.ee.concurrency.EEConcurrencyContextHandleFactoryProcessor) TransactionDependenciesProcessor(org.jboss.as.txn.deployment.TransactionDependenciesProcessor) BinderService(org.jboss.as.naming.service.BinderService) InjectionException(org.jboss.msc.inject.InjectionException) ManagedReferenceFactory(org.jboss.as.naming.ManagedReferenceFactory) ValueManagedReferenceFactory(org.jboss.as.naming.ValueManagedReferenceFactory) UserTransaction(javax.transaction.UserTransaction) Resource(org.jboss.as.controller.registry.Resource) UserTransactionBindingService(org.jboss.as.txn.service.UserTransactionBindingService) LinkedList(java.util.LinkedList) TransactionSetupProviderService(org.jboss.as.txn.ee.concurrency.TransactionSetupProviderService) DeploymentProcessorTarget(org.jboss.as.server.DeploymentProcessorTarget) ServiceName(org.jboss.msc.service.ServiceName) ValueManagedReferenceFactory(org.jboss.as.naming.ValueManagedReferenceFactory) ContextTransactionManager(org.wildfly.transaction.client.ContextTransactionManager) TransactionManager(javax.transaction.TransactionManager) TransactionSynchronizationRegistry(javax.transaction.TransactionSynchronizationRegistry) AbstractDeploymentChainStep(org.jboss.as.server.AbstractDeploymentChainStep) UserTransactionAccessControlService(org.jboss.as.txn.service.UserTransactionAccessControlService) TransactionManager(javax.transaction.TransactionManager) TransactionJndiBindingProcessor(org.jboss.as.txn.deployment.TransactionJndiBindingProcessor)

Example 17 with TransactionSynchronizationRegistry

use of javax.transaction.TransactionSynchronizationRegistry in project wildfly by wildfly.

the class TransactionJndiBindingProcessor method bindServices.

/**
     * Binds the java:comp/UserTransaction service and the java:comp/TransactionSynchronizationRegistry
     *
     * @param deploymentUnit The deployment unit
     * @param serviceTarget The service target
     * @param contextServiceName The service name of the context to bind to
     */
private void bindServices(DeploymentUnit deploymentUnit, ServiceTarget serviceTarget, ServiceName contextServiceName) {
    final ServiceName userTransactionServiceName = contextServiceName.append("UserTransaction");
    final UserTransactionBindingService userTransactionBindingService = new UserTransactionBindingService("UserTransaction");
    serviceTarget.addService(userTransactionServiceName, userTransactionBindingService).addDependency(UserTransactionAccessControlService.SERVICE_NAME, UserTransactionAccessControlService.class, userTransactionBindingService.getUserTransactionAccessControlServiceInjector()).addDependency(UserTransactionService.SERVICE_NAME, UserTransaction.class, new ManagedReferenceInjector<UserTransaction>(userTransactionBindingService.getManagedObjectInjector())).addDependency(contextServiceName, ServiceBasedNamingStore.class, userTransactionBindingService.getNamingStoreInjector()).install();
    deploymentUnit.addToAttachmentList(org.jboss.as.server.deployment.Attachments.JNDI_DEPENDENCIES, userTransactionServiceName);
    final ServiceName transactionSynchronizationRegistryName = contextServiceName.append("TransactionSynchronizationRegistry");
    BinderService transactionSyncBinderService = new BinderService("TransactionSynchronizationRegistry");
    serviceTarget.addService(transactionSynchronizationRegistryName, transactionSyncBinderService).addDependency(TransactionSynchronizationRegistryService.SERVICE_NAME, TransactionSynchronizationRegistry.class, new ManagedReferenceInjector<TransactionSynchronizationRegistry>(transactionSyncBinderService.getManagedObjectInjector())).addDependency(contextServiceName, ServiceBasedNamingStore.class, transactionSyncBinderService.getNamingStoreInjector()).install();
    deploymentUnit.addToAttachmentList(org.jboss.as.server.deployment.Attachments.JNDI_DEPENDENCIES, transactionSynchronizationRegistryName);
}
Also used : UserTransaction(javax.transaction.UserTransaction) BinderService(org.jboss.as.naming.service.BinderService) ServiceName(org.jboss.msc.service.ServiceName) ServiceBasedNamingStore(org.jboss.as.naming.ServiceBasedNamingStore) TransactionSynchronizationRegistry(javax.transaction.TransactionSynchronizationRegistry) UserTransactionAccessControlService(org.jboss.as.txn.service.UserTransactionAccessControlService) UserTransactionBindingService(org.jboss.as.txn.service.UserTransactionBindingService)

Example 18 with TransactionSynchronizationRegistry

use of javax.transaction.TransactionSynchronizationRegistry in project tomee by apache.

the class BaseEjbProxyHandler method getLiveHandleRegistry.

public ConcurrentMap getLiveHandleRegistry() {
    final BeanContext beanContext = getBeanContext();
    final ThreadContext tc = ThreadContext.getThreadContext();
    if (tc != null && tc.getBeanContext() != beanContext && /* parent bean */
    tc.getCurrentOperation() == Operation.BUSINESS) {
        ProxyRegistry registry = tc.get(ProxyRegistry.class);
        if (registry == null) {
            registry = new ProxyRegistry();
            tc.set(ProxyRegistry.class, registry);
        }
        return registry.liveHandleRegistry;
    } else {
        // use the tx if there
        final SystemInstance systemInstance = SystemInstance.get();
        final TransactionManager txMgr = systemInstance.getComponent(TransactionManager.class);
        try {
            final Transaction tx = txMgr.getTransaction();
            if (tx != null && tx.getStatus() == Status.STATUS_ACTIVE) {
                final TransactionSynchronizationRegistry registry = systemInstance.getComponent(TransactionSynchronizationRegistry.class);
                final String resourceKey = ProxyRegistry.class.getName();
                ConcurrentMap map = ConcurrentMap.class.cast(registry.getResource(resourceKey));
                if (map == null) {
                    map = new ConcurrentHashMap();
                    registry.putResource(resourceKey, map);
                    try {
                        final ConcurrentMap tmp = map;
                        tx.registerSynchronization(new Synchronization() {

                            @Override
                            public void beforeCompletion() {
                            // no-op
                            }

                            @Override
                            public void afterCompletion(final int status) {
                                tmp.clear();
                            }
                        });
                    } catch (final RollbackException e) {
                    // not really possible since we check the status
                    // let it go to default
                    }
                }
                return map;
            }
        } catch (final SystemException e) {
        // let it go to default
        }
        // back to default but it doesnt release the memory
        ProxyRegistry proxyRegistry = beanContext.get(ProxyRegistry.class);
        if (proxyRegistry == null) {
            proxyRegistry = new ProxyRegistry();
            beanContext.set(ProxyRegistry.class, proxyRegistry);
        }
        return proxyRegistry.liveHandleRegistry;
    }
}
Also used : ThreadContext(org.apache.openejb.core.ThreadContext) ConcurrentMap(java.util.concurrent.ConcurrentMap) Synchronization(javax.transaction.Synchronization) RollbackException(javax.transaction.RollbackException) BeanContext(org.apache.openejb.BeanContext) Transaction(javax.transaction.Transaction) SystemException(javax.transaction.SystemException) SystemInstance(org.apache.openejb.loader.SystemInstance) TransactionManager(javax.transaction.TransactionManager) TransactionSynchronizationRegistry(javax.transaction.TransactionSynchronizationRegistry) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap)

Example 19 with TransactionSynchronizationRegistry

use of javax.transaction.TransactionSynchronizationRegistry in project tomee by apache.

the class Assembler method createTransactionManager.

public void createTransactionManager(final TransactionServiceInfo serviceInfo) throws OpenEJBException {
    Object service = SystemInstance.get().getComponent(TransactionManager.class);
    if (service == null) {
        final ObjectRecipe serviceRecipe = createRecipe(Collections.<ServiceInfo>emptyList(), serviceInfo);
        service = serviceRecipe.create();
        logUnusedProperties(serviceRecipe, serviceInfo);
    } else {
        logger.info("Reusing provided TransactionManager " + service);
    }
    final Class interfce = serviceInterfaces.get(serviceInfo.service);
    checkImplementation(interfce, service.getClass(), serviceInfo.service, serviceInfo.id);
    try {
        this.containerSystem.getJNDIContext().bind(JAVA_OPENEJB_NAMING_CONTEXT + serviceInfo.service, service);
        this.containerSystem.getJNDIContext().bind("comp/UserTransaction", new CoreUserTransaction((TransactionManager) service));
        this.containerSystem.getJNDIContext().bind("comp/TransactionManager", service);
    } catch (final NamingException e) {
        throw new OpenEJBException("Cannot bind " + serviceInfo.service + " with id " + serviceInfo.id, e);
    }
    setSystemInstanceComponent(interfce, service);
    getContext().put(interfce.getName(), service);
    props.put(interfce.getName(), service);
    props.put(serviceInfo.service, service);
    props.put(serviceInfo.id, service);
    this.transactionManager = (TransactionManager) service;
    // Update the config tree
    config.facilities.transactionService = serviceInfo;
    // todo find a better place for this
    // TransactionSynchronizationRegistry
    final TransactionSynchronizationRegistry synchronizationRegistry;
    if (transactionManager instanceof TransactionSynchronizationRegistry) {
        synchronizationRegistry = (TransactionSynchronizationRegistry) transactionManager;
    } else {
        // todo this should be built
        synchronizationRegistry = new SimpleTransactionSynchronizationRegistry(transactionManager);
    }
    Assembler.getContext().put(TransactionSynchronizationRegistry.class.getName(), synchronizationRegistry);
    SystemInstance.get().setComponent(TransactionSynchronizationRegistry.class, synchronizationRegistry);
    try {
        this.containerSystem.getJNDIContext().bind("comp/TransactionSynchronizationRegistry", new TransactionSynchronizationRegistryWrapper());
    } catch (final NamingException e) {
        throw new OpenEJBException("Cannot bind java:comp/TransactionSynchronizationRegistry", e);
    }
    // JtaEntityManagerRegistry
    // todo this should be built
    final JtaEntityManagerRegistry jtaEntityManagerRegistry = new JtaEntityManagerRegistry(synchronizationRegistry);
    Assembler.getContext().put(JtaEntityManagerRegistry.class.getName(), jtaEntityManagerRegistry);
    SystemInstance.get().setComponent(JtaEntityManagerRegistry.class, jtaEntityManagerRegistry);
    logger.getChildLogger("service").debug("createService.success", serviceInfo.service, serviceInfo.id, serviceInfo.className);
}
Also used : OpenEJBException(org.apache.openejb.OpenEJBException) JtaEntityManagerRegistry(org.apache.openejb.persistence.JtaEntityManagerRegistry) ObjectRecipe(org.apache.xbean.recipe.ObjectRecipe) GeronimoTransactionManager(org.apache.geronimo.transaction.manager.GeronimoTransactionManager) TransactionManager(javax.transaction.TransactionManager) SimpleTransactionSynchronizationRegistry(org.apache.openejb.core.SimpleTransactionSynchronizationRegistry) TransactionSynchronizationRegistry(javax.transaction.TransactionSynchronizationRegistry) CoreUserTransaction(org.apache.openejb.core.CoreUserTransaction) NamingException(javax.naming.NamingException) SimpleTransactionSynchronizationRegistry(org.apache.openejb.core.SimpleTransactionSynchronizationRegistry) TransactionSynchronizationRegistryWrapper(org.apache.openejb.core.TransactionSynchronizationRegistryWrapper)

Example 20 with TransactionSynchronizationRegistry

use of javax.transaction.TransactionSynchronizationRegistry in project tomee by apache.

the class TransactionSynchronizationRegistryWrapper method getRegistry.

public TransactionSynchronizationRegistry getRegistry() {
    final SystemInstance system = SystemInstance.get();
    if (system != this.system) {
        this.registry = system.getComponent(TransactionSynchronizationRegistry.class);
        this.system = system;
    }
    return registry;
}
Also used : SystemInstance(org.apache.openejb.loader.SystemInstance) TransactionSynchronizationRegistry(javax.transaction.TransactionSynchronizationRegistry)

Aggregations

TransactionSynchronizationRegistry (javax.transaction.TransactionSynchronizationRegistry)23 TransactionManager (javax.transaction.TransactionManager)14 InitialContext (javax.naming.InitialContext)6 Synchronization (javax.transaction.Synchronization)4 UserTransaction (javax.transaction.UserTransaction)4 ServiceName (org.jboss.msc.service.ServiceName)4 Test (org.junit.Test)4 HashMap (java.util.HashMap)3 BeanManager (javax.enterprise.inject.spi.BeanManager)3 Context (javax.naming.Context)3 ValidatorFactory (javax.validation.ValidatorFactory)3 XATerminator (com.arjuna.ats.internal.jbossatx.jta.jca.XATerminator)2 TransactionManagerImple (com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionManagerImple)2 TransactionSynchronizationRegistryImple (com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionSynchronizationRegistryImple)2 JTAEnvironmentBean (com.arjuna.ats.jta.common.JTAEnvironmentBean)2 LinkedList (java.util.LinkedList)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 NamingException (javax.naming.NamingException)2 BeanContext (org.apache.openejb.BeanContext)2 OpenEJBException (org.apache.openejb.OpenEJBException)2