public Transaction getCurrentTransaction() { final LocalTransactionContext current = LocalTransactionContext.getCurrent(); try { current.importProviderTransaction(); } catch (SystemException e) { throw new RuntimeException("InboundTransactionCurrentImpl unable to determine inbound transaction context", e); } try { return ContextTransactionManager.getInstance().suspend(); } catch (SystemException e) { throw new RuntimeException("InboundTransactionCurrentImpl unable to suspend inbound transaction context", e); } } }
/** * Attempt to import a transaction, which subsequently may be controlled by its XID or by the returned handle. * * @param xid the XID of the transaction to import (must not be {@code null}) * @param timeout the transaction timeout to use, if new * @return the transaction import result (not {@code null}) * @throws XAException if a problem occurred while importing the transaction */ @NotNull public ImportResult<LocalTransaction> findOrImportTransaction(Xid xid, int timeout) throws XAException { return Assert.assertNotNull(findOrImportTransaction(xid, timeout, false)); }
public void stop(final StopContext context) { this.context = null; // TODO: replace this with per-CL settings for embedded use and to support remote UserTransaction doPrivileged((PrivilegedAction<Void>) () -> { LocalTransactionContext.getContextManager().setGlobalDefault(null); return null; }); }
void begin(CreationListener.CreatedBy createdBy) throws NotSupportedException, SystemException { final State state = stateRef.get(); if (state.transaction != null) { throw Log.log.nestedNotSupported(); } resume(LocalTransactionContext.getCurrent().beginTransaction(state.getTimeout(), false, createdBy)); }
boolean importBacking() throws SystemException { final ContextTransactionManager.State state = ContextTransactionManager.INSTANCE.getStateRef().get(); final Transaction transaction = owner.getProvider().getTransactionManager().getTransaction(); if (transaction == null) { return false; } final LocalTransaction localTransaction = owner.getOrAttach(transaction, CreationListener.CreatedBy.MERGE); if (state.transaction == null) { state.transaction = localTransaction; return true; } else { localTransaction.verifyAssociation(); return false; } }
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(); } }); } } }); }
public RemotingTransactionService build() { Endpoint endpoint = this.endpoint; if (endpoint == null) endpoint = Endpoint.getCurrent(); LocalTransactionContext transactionContext = this.transactionContext; if (transactionContext == null) transactionContext = LocalTransactionContext.getCurrent(); return new RemotingTransactionService(endpoint, transactionContext); } }
public Xid[] recover(final int flag) throws XAException { return transactionContext.getRecoveryInterface().recover(flag); }
LocalTransactionProvider getProvider() { return owner.getProvider(); }
public void start(final StartContext context) throws StartException { JBossLocalTransactionProvider.Builder builder = JBossLocalTransactionProvider.builder(); builder.setExtendedJBossXATerminator(extendedJBossXATerminatorInjector.getValue()); builder.setTransactionManager(transactionManagerInjector.getValue().getTransactionManager()); builder.setTransactionSynchronizationRegistry(transactionManagerInjector.getValue().getTransactionSynchronizationRegistry()); builder.setXATerminator(transactionManagerInjector.getValue().getJbossXATerminator()); builder.setXAResourceRecoveryRegistry(xaResourceRecoveryRegistryInjector.getValue()); builder.setXARecoveryLogDirRelativeToPath(serverEnvironmentInjector.getValue().getServerDataDir().toPath()); final LocalTransactionContext transactionContext = this.context = new LocalTransactionContext(builder.build()); // TODO: replace this with per-CL settings for embedded use and to support remote UserTransaction doPrivileged((PrivilegedAction<Void>) () -> { LocalTransactionContext.getContextManager().setGlobalDefault(transactionContext); return null; }); // Install the void service required by capability org.wildfly.transactions.global-default-local-provider // so other capabilities that require it can start their services after this capability // has completed its work. context.getChildTarget().addService(LOCAL_PROVIDER_CAPABILITY.getCapabilityServiceName()) .setInstance(Service.NULL) .install(); }
/** * Begin a new, local transaction on behalf of a local peer. * * @param timeout the transaction timeout to use for this transaction * @return the local transaction (not {@code null}) * @throws SystemException if the transaction creation failed for some reason, one of the possible reasons being * suspended server * @throws SecurityException if the caller is not authorized to create a local transaction in this context */ @NotNull public LocalTransaction beginTransaction(final int timeout) throws SystemException, SecurityException { return beginTransaction(timeout, false); }
/** * Attempt to import a provider's current transaction as a local transaction. * * @return {@code true} if the transaction was associated, {@code false} if the provider had no current transaction * @throws SystemException if an error occurred acquiring the current transaction from the provider * @throws IllegalStateException if the thread is associated with a transaction that isn't equal to the provider's transaction */ public boolean importProviderTransaction() throws SystemException { final ContextTransactionManager.State state = ContextTransactionManager.INSTANCE.getStateRef().get(); final Transaction transaction = provider.getTransactionManager().getTransaction(); if (transaction == null) { return false; } final LocalTransaction localTransaction = getOrAttach(transaction, CreationListener.CreatedBy.MERGE); if (state.transaction == null) { state.transaction = localTransaction; } else { localTransaction.verifyAssociation(); } return true; }
LocalTransaction getOrAttach(Transaction transaction, CreationListener.CreatedBy createdBy) { LocalTransaction txn = (LocalTransaction) provider.getResource(transaction, LOCAL_TXN_KEY); boolean isNew = false; if (txn == null) { // use LOCAL_TXN_KEY so we can be reasonably assured that there will be no deadlock synchronized (LOCAL_TXN_KEY) { txn = (LocalTransaction) provider.getResource(transaction, LOCAL_TXN_KEY); if (txn == null) { provider.putResource(transaction, LOCAL_TXN_KEY, txn = new LocalTransaction(this, transaction)); isNew = true; } } } if (isNew) { notifyCreationListeners(txn, createdBy); } return txn; }
/** * Starts the service. Registers server activity, sets transaction listener on local transaction context, and creates and * installs deployment controller service. * * @param context start context */ public void start(StartContext context) { final SuspendController suspendController = suspendControllerInjectedValue.getValue(); suspendController.registerActivity(this); final LocalTransactionContext localTransactionContext = localTransactionContextInjectedValue.getValue(); localTransactionContext.registerCreationListener(this); }
void begin(CreationListener.CreatedBy createdBy) throws NotSupportedException, SystemException { final State state = stateRef.get(); if (state.transaction != null) { throw Log.log.nestedNotSupported(); } resume(LocalTransactionContext.getCurrent().beginTransaction(state.getTimeout(), false, createdBy)); }
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(); } }); } } }); }
public RemotingTransactionService build() { Endpoint endpoint = this.endpoint; if (endpoint == null) endpoint = Endpoint.getCurrent(); LocalTransactionContext transactionContext = this.transactionContext; if (transactionContext == null) transactionContext = LocalTransactionContext.getCurrent(); return new RemotingTransactionService(endpoint, transactionContext); } }
final Xid[] recoveryList = transactionContext.getRecoveryInterface().recover(flags, parentName); final ByteArrayOutputStream out = new ByteArrayOutputStream(); Marshaller marshaller = MARSHALLER_FACTORY.createMarshaller(createMarshallingConf());
/** * Get the XID of the local transaction. * * @return the transaction XID (not {@code null}) */ public Xid getXid() { return owner.getProvider().getXid(transaction); }
public void start(final StartContext context) throws StartException { JBossLocalTransactionProvider.Builder builder = JBossLocalTransactionProvider.builder(); builder.setExtendedJBossXATerminator(extendedJBossXATerminatorInjector.getValue()); builder.setTransactionManager(transactionManagerInjector.getValue().getTransactionManager()); builder.setTransactionSynchronizationRegistry(transactionManagerInjector.getValue().getTransactionSynchronizationRegistry()); builder.setXATerminator(transactionManagerInjector.getValue().getJbossXATerminator()); builder.setXAResourceRecoveryRegistry(xaResourceRecoveryRegistryInjector.getValue()); builder.setXARecoveryLogDirRelativeToPath(serverEnvironmentInjector.getValue().getServerDataDir().toPath()); final LocalTransactionContext transactionContext = this.context = new LocalTransactionContext(builder.build()); // TODO: replace this with per-CL settings for embedded use and to support remote UserTransaction doPrivileged((PrivilegedAction<Void>) () -> { LocalTransactionContext.getContextManager().setGlobalDefault(transactionContext); return null; }); }