void resume(final AbstractTransaction transaction) throws IllegalStateException, SystemException { final State state = stateRef.get(); if (state.transaction != null) throw Log.log.alreadyAssociated(); state.transaction = transaction; if (transaction != null) try { transaction.resume(); } catch (Throwable t) { state.transaction = null; throw t; } }
public void verifyEnlistment() throws RollbackException, SystemException { if (done.compareAndSet(false, true)) { OutflowHandleManager.verifyOne(stateRef); } else { throw Log.log.alreadyEnlisted(); } } };
public void forgetEnlistment() { if (done.compareAndSet(false, true)) { OutflowHandleManager.forgetOne(stateRef); } else { throw Log.log.alreadyForgotten(); } }
/** * {@inheritDoc} */ @Override protected void addResource(XAResource resource, URI uri) throws SystemException { assert fileChannel != null; try { assert fileChannel.isOpen(); fileChannel.write(ByteBuffer.wrap((uri.toString() + System.lineSeparator()).getBytes(StandardCharsets.UTF_8))); fileChannel.force(true); } catch (IOException e) { throw Log.log.appendXAResourceRecoveryFileFailed(uri, filePath, e); } this.resources.add(resource); Log.log.xaResourceAddedToRecoveryRegistry(uri, filePath); }
/** * {@inheritDoc} * The registry file is closed and deleted if there are no more resources left. * * @throws XAException if there is a problem deleting the registry file */ @Override protected void removeResource(XAResource resource) throws XAException { if (resources.remove(resource)) { if (resources.isEmpty()) { // delete file try { if (fileChannel != null) { fileChannel.close(); } Files.delete(filePath); openFilePaths.remove(filePath.toString()); } catch (IOException e) { throw Log.log.deleteXAResourceRecoveryFileFailed(XAException.XAER_RMERR, filePath, resource, e); } Log.log.xaResourceRecoveryFileDeleted(filePath); } // remove resource from in doubt list, in case the resource was in doubt inDoubtResources.remove(resource); } }
/** * Creates a XA recovery registry for a transaction. This method assumes that there is no file already * existing for this transaction, and, furthermore, it is not thread safe (the creation of this object is * already thread protected at the caller). * * @param xid the transaction xid * @throws SystemException if the there was a problem when creating the recovery file in file system */ XAResourceRegistryFile(Xid xid) throws SystemException { xaRecoveryPath.toFile().mkdir(); // create dir if non existent final String xidString = SimpleXid.of(xid).toHexString('_'); this.filePath = xaRecoveryPath.resolve(xidString); openFilePaths.add(xidString); try { fileChannel = FileChannel.open(filePath, StandardOpenOption.APPEND, StandardOpenOption.CREATE_NEW); fileChannel.lock(); Log.log.xaResourceRecoveryFileCreated(filePath); } catch (IOException e) { throw Log.log.createXAResourceRecoveryFileFailed(filePath, e); } }
void commitLocal() throws HeuristicRollbackException, RollbackException, HeuristicMixedException, SystemException { if (transaction instanceof ImportedTransaction) { throw Log.log.commitOnImported(); } transaction.commit(); }
@NotNull public SimpleTransactionControl begin(final int timeout) throws SystemException { // this one is bound to the connection try { final ConnectionPeerIdentity peerIdentity = getPeerIdentity(); return getOperations(peerIdentity.getConnection()).begin(peerIdentity); } catch (IOException e) { throw Log.log.failedToAcquireConnection(e); } } }
JBossLocalTransactionProvider(final ExtendedJBossXATerminator ext, final int staleTransactionTime, final TransactionManager tm, final XAResourceRecoveryRegistry registry, final Path xaRecoveryDirRelativeToPath) { Assert.checkMinimumParameter("setTransactionTimeout", 0, staleTransactionTime); this.staleTransactionTime = staleTransactionTime; this.ext = Assert.checkNotNullParam("ext", ext); this.tm = Assert.checkNotNullParam("tm", tm); try { ext.doRecover(null, null); } catch (Exception e) { // the recover method is called to load transactions from Narayana object store at startup // if it fails we ignore, troubles will be adjusted during runtime Log.log.doRecoverFailureOnIntialization(e); } this.fileSystemXAResourceRegistry = new FileSystemXAResourceRegistry(this, xaRecoveryDirRelativeToPath); registry.addXAResourceRecovery(fileSystemXAResourceRegistry::getInDoubtXAResources); }
throw Log.log.couldNotEnlist();
/** * {@inheritDoc} */ @Override protected void addResource(XAResource resource, URI uri) throws SystemException { assert fileChannel != null; try { assert fileChannel.isOpen(); fileChannel.write(ByteBuffer.wrap((uri.toString() + System.lineSeparator()).getBytes(StandardCharsets.UTF_8))); fileChannel.force(true); } catch (IOException e) { throw Log.log.appendXAResourceRecoveryFileFailed(uri, filePath, e); } this.resources.add(resource); Log.log.xaResourceAddedToRecoveryRegistry(uri, filePath); }
/** * Creates a XA recovery registry for a transaction. This method assumes that there is no file already * existing for this transaction, and, furthermore, it is not thread safe (the creation of this object is * already thread protected at the caller). * * @param xid the transaction xid * @throws SystemException if the there was a problem when creating the recovery file in file system */ XAResourceRegistryFile(Xid xid) throws SystemException { xaRecoveryPath.toFile().mkdir(); // create dir if non existent final String xidString = SimpleXid.of(xid).toHexString('_'); this.filePath = xaRecoveryPath.resolve(xidString); openFilePaths.add(xidString); try { fileChannel = FileChannel.open(filePath, StandardOpenOption.APPEND, StandardOpenOption.CREATE_NEW); fileChannel.lock(); Log.log.xaResourceRecoveryFileCreated(filePath); } catch (IOException e) { throw Log.log.createXAResourceRecoveryFileFailed(filePath, e); } }
/** * {@inheritDoc} * The registry file is closed and deleted if there are no more resources left. * * @throws XAException if there is a problem deleting the registry file */ @Override protected void removeResource(XAResource resource) throws XAException { if (resources.remove(resource)) { if (resources.isEmpty()) { // delete file try { if (fileChannel != null) { fileChannel.close(); } Files.delete(filePath); openFilePaths.remove(filePath.toString()); } catch (IOException e) { throw Log.log.deleteXAResourceRecoveryFileFailed(XAException.XAER_RMERR, filePath, resource, e); } Log.log.xaResourceRecoveryFileDeleted(filePath); } // remove resource from in doubt list, in case the resource was in doubt inDoubtResources.remove(resource); } }
void commitAndDissociate() throws RollbackException, HeuristicMixedException, HeuristicRollbackException, SecurityException, SystemException { if (isImported()) { throw Log.log.commitOnImported(); } notifyAssociationListeners(false); try { owner.getProvider().getTransactionManager().commit(); } catch (RollbackException re) { addRollbackExceptions(re); throw re; } finally { final XAOutflowedResources outflowedResources = RemoteTransactionContext.getOutflowedResources(this); if (outflowedResources == null || outflowedResources.getEnlistedSubordinates() == 0) { // we can drop the mapping, since we are both a master and have no enlisted subordinates owner.getProvider().dropLocal(transaction); } } }
@NotNull public SimpleTransactionControl begin(final int timeout) throws SystemException { // this one is bound to the connection try { final ConnectionPeerIdentity peerIdentity = getPeerIdentity(); return getOperations(peerIdentity.getConnection()).begin(peerIdentity); } catch (IOException e) { throw Log.log.failedToAcquireConnection(e); } } }
JBossLocalTransactionProvider(final ExtendedJBossXATerminator ext, final int staleTransactionTime, final TransactionManager tm, final XAResourceRecoveryRegistry registry, final Path xaRecoveryDirRelativeToPath) { Assert.checkMinimumParameter("setTransactionTimeout", 0, staleTransactionTime); this.staleTransactionTime = staleTransactionTime; this.ext = Assert.checkNotNullParam("ext", ext); this.tm = Assert.checkNotNullParam("tm", tm); try { ext.doRecover(null, null); } catch (Exception e) { // the recover method is called to load transactions from Narayana object store at startup // if it fails we ignore, troubles will be adjusted during runtime Log.log.doRecoverFailureOnIntialization(e); } this.fileSystemXAResourceRegistry = new FileSystemXAResourceRegistry(this, xaRecoveryDirRelativeToPath); registry.addXAResourceRecovery(fileSystemXAResourceRegistry::getInDoubtXAResources); }
throw Log.log.couldNotEnlist();
/** * {@inheritDoc} */ @Override protected void addResource(XAResource resource, URI uri) throws SystemException { assert fileChannel != null; try { assert fileChannel.isOpen(); fileChannel.write(ByteBuffer.wrap((uri.toString() + System.lineSeparator()).getBytes(StandardCharsets.UTF_8))); fileChannel.force(true); } catch (IOException e) { throw Log.log.appendXAResourceRecoveryFileFailed(uri, filePath, e); } this.resources.add(resource); Log.log.xaResourceAddedToRecoveryRegistry(uri, filePath); }
/** * Creates a XA recovery registry for a transaction. This method assumes that there is no file already * existing for this transaction, and, furthermore, it is not thread safe (the creation of this object is * already thread protected at the caller). * * @param xid the transaction xid * @throws SystemException if the there was a problem when creating the recovery file in file system */ XAResourceRegistryFile(Xid xid) throws SystemException { xaRecoveryPath.toFile().mkdir(); // create dir if non existent final String xidString = SimpleXid.of(xid).toHexString('_'); this.filePath = xaRecoveryPath.resolve(xidString); openFilePaths.add(xidString); try { fileChannel = FileChannel.open(filePath, StandardOpenOption.APPEND, StandardOpenOption.CREATE_NEW); fileChannel.lock(); Log.log.xaResourceRecoveryFileCreated(filePath); } catch (IOException e) { throw Log.log.createXAResourceRecoveryFileFailed(filePath, e); } }
/** * {@inheritDoc} * The registry file is closed and deleted if there are no more resources left. * * @throws XAException if there is a problem deleting the registry file */ @Override protected void removeResource(XAResource resource) throws XAException { if (resources.remove(resource)) { if (resources.isEmpty()) { // delete file try { if (fileChannel != null) { fileChannel.close(); } Files.delete(filePath); openFilePaths.remove(filePath.toString()); } catch (IOException e) { throw Log.log.deleteXAResourceRecoveryFileFailed(XAException.XAER_RMERR, filePath, resource, e); } Log.log.xaResourceRecoveryFileDeleted(filePath); } // remove resource from in doubt list, in case the resource was in doubt inDoubtResources.remove(resource); } }