Search in sources :

Example 1 with AssociationListener

use of org.wildfly.transaction.client.AssociationListener in project wildfly by wildfly.

the class TransactionManagerService method start.

public void start(final StartContext context) throws StartException {
    final UserTransactionRegistry registry = registryInjector.getValue();
    LocalTransactionContext.getCurrent().registerCreationListener((txn, createdBy) -> {
        if (createdBy == CreationListener.CreatedBy.USER_TRANSACTION) {
            if (WildFlySecurityManager.isChecking()) {
                AccessController.doPrivileged((PrivilegedAction<Void>) () -> {
                    txn.registerAssociationListener(new AssociationListener() {

                        private final AtomicBoolean first = new AtomicBoolean();

                        public void associationChanged(final AbstractTransaction t, final boolean a) {
                            if (a && first.compareAndSet(false, true))
                                registry.userTransactionStarted();
                        }
                    });
                    return null;
                });
            } else {
                txn.registerAssociationListener(new AssociationListener() {

                    private final AtomicBoolean first = new AtomicBoolean();

                    public void associationChanged(final AbstractTransaction t, final boolean a) {
                        if (a && first.compareAndSet(false, true))
                            registry.userTransactionStarted();
                    }
                });
            }
        }
    });
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) UserTransactionRegistry(org.jboss.tm.usertx.UserTransactionRegistry) AssociationListener(org.wildfly.transaction.client.AssociationListener) AbstractTransaction(org.wildfly.transaction.client.AbstractTransaction)

Aggregations

AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 UserTransactionRegistry (org.jboss.tm.usertx.UserTransactionRegistry)1 AbstractTransaction (org.wildfly.transaction.client.AbstractTransaction)1 AssociationListener (org.wildfly.transaction.client.AssociationListener)1