Search in sources :

Example 16 with Transaction

use of javax.transaction.Transaction in project graphdb by neo4j-attic.

the class IndexConnectionBroker method delistResourcesForTransaction.

void delistResourcesForTransaction() throws NotInTransactionException {
    Transaction tx = this.getCurrentTransaction();
    if (tx == null) {
        throw new NotInTransactionException();
    }
    T con = txConnectionMap.get(tx);
    if (con != null) {
        try {
            tx.delistResource(con.getXaResource(), XAResource.TMSUCCESS);
        } catch (IllegalStateException e) {
            throw new RuntimeException("Unable to delist lucene resource from tx", e);
        } catch (SystemException e) {
            throw new RuntimeException("Unable to delist lucene resource from tx", e);
        }
    }
}
Also used : Transaction(javax.transaction.Transaction) SystemException(javax.transaction.SystemException) NotInTransactionException(org.neo4j.graphdb.NotInTransactionException)

Example 17 with Transaction

use of javax.transaction.Transaction in project graphdb by neo4j-attic.

the class PersistenceManager method delistResourcesForTransaction.

void delistResourcesForTransaction() throws NotInTransactionException {
    Transaction tx = this.getCurrentTransaction();
    if (tx == null) {
        throw new NotInTransactionException();
    }
    ResourceConnection con = txConnectionMap.get(tx);
    if (con != null) {
        try {
            tx.delistResource(con.getXAResource(), XAResource.TMSUCCESS);
        } catch (SystemException e) {
            throw new TransactionFailureException("Failed to delist resource '" + con + "' from current transaction.", e);
        }
    }
}
Also used : TransactionFailureException(org.neo4j.graphdb.TransactionFailureException) Transaction(javax.transaction.Transaction) SystemException(javax.transaction.SystemException) NotInTransactionException(org.neo4j.graphdb.NotInTransactionException)

Example 18 with Transaction

use of javax.transaction.Transaction in project graphdb by neo4j-attic.

the class RWLock method acquireReadLock.

/**
     * Tries to acquire read lock for current transaction. If 
     * <CODE>this.writeCount</CODE> is greater than the currents tx's write 
     * count the transaction has to wait and the {@link RagManager#checkWaitOn} 
     * method is invoked for deadlock detection.
     * <p>
     * If the lock can be acquires the lock count is updated on <CODE>this</CODE>
     * and the transaction lock element (tle).
     * 
     * @throws DeadlockDetectedException
     *             if a deadlock is detected
     */
synchronized void acquireReadLock() throws DeadlockDetectedException {
    Transaction tx = ragManager.getCurrentTransaction();
    if (tx == null) {
        tx = new PlaceboTransaction();
    }
    TxLockElement tle = txLockElementMap.get(tx);
    if (tle == null) {
        tle = new TxLockElement(tx);
    }
    try {
        while (writeCount > tle.writeCount) {
            ragManager.checkWaitOn(this, tx);
            waitingThreadList.addFirst(new WaitElement(tle, LockType.READ, Thread.currentThread()));
            try {
                wait();
            } catch (InterruptedException e) {
                Thread.interrupted();
            }
            ragManager.stopWaitOn(this, tx);
        }
        if (tle.readCount == 0 && tle.writeCount == 0) {
            ragManager.lockAcquired(this, tx);
        }
        readCount++;
        tle.readCount++;
        // TODO: this put could be optimized?
        txLockElementMap.put(tx, tle);
    } finally {
        // if deadlocked, remove marking so lock is removed when empty
        marked--;
    }
}
Also used : Transaction(javax.transaction.Transaction)

Example 19 with Transaction

use of javax.transaction.Transaction in project graphdb by neo4j-attic.

the class RWLock method acquireWriteLock.

/**
     * Tries to acquire write lock for current transaction. If 
     * <CODE>this.writeCount</CODE> is greater than the currents tx's write 
     * count or the read count is greater than the currents tx's read count the 
     * transaction has to wait and the {@link RagManager#checkWaitOn} method is 
     * invoked for deadlock detection.
     * <p>
     * If the lock can be acquires the lock count is updated on <CODE>this</CODE>
     * and the transaction lock element (tle).
     * 
     * @throws DeadlockDetectedException
     *             if a deadlock is detected
     */
synchronized void acquireWriteLock() throws DeadlockDetectedException {
    Transaction tx = ragManager.getCurrentTransaction();
    if (tx == null) {
        tx = new PlaceboTransaction();
    }
    TxLockElement tle = txLockElementMap.get(tx);
    if (tle == null) {
        tle = new TxLockElement(tx);
    }
    try {
        while (writeCount > tle.writeCount || readCount > tle.readCount) {
            ragManager.checkWaitOn(this, tx);
            waitingThreadList.addFirst(new WaitElement(tle, LockType.WRITE, Thread.currentThread()));
            try {
                wait();
            } catch (InterruptedException e) {
                Thread.interrupted();
            }
            ragManager.stopWaitOn(this, tx);
        }
        if (tle.readCount == 0 && tle.writeCount == 0) {
            ragManager.lockAcquired(this, tx);
        }
        writeCount++;
        tle.writeCount++;
        // TODO optimize this put?
        txLockElementMap.put(tx, tle);
    } finally {
        // if deadlocked, remove marking so lock is removed when empty
        marked--;
    }
}
Also used : Transaction(javax.transaction.Transaction)

Example 20 with Transaction

use of javax.transaction.Transaction in project graphdb by neo4j-attic.

the class RagManager method dumpStack.

synchronized void dumpStack() {
    System.out.print("Waiting list: ");
    Iterator<Transaction> transactions = waitingTxMap.keySet().iterator();
    if (!transactions.hasNext()) {
        System.out.println("No transactions waiting on resources");
    } else {
        System.out.println();
    }
    while (transactions.hasNext()) {
        Transaction tx = transactions.next();
        System.out.println("" + tx + "->" + waitingTxMap.get(tx));
    }
    System.out.print("Resource lock list: ");
    Iterator<?> resources = resourceMap.keySet().iterator();
    if (!resources.hasNext()) {
        System.out.println("No locked resources found");
    } else {
        System.out.println();
    }
    while (resources.hasNext()) {
        Object resource = resources.next();
        System.out.print("" + resource + "->");
        Iterator<Transaction> itr = resourceMap.get(resource).iterator();
        if (!itr.hasNext()) {
            System.out.println(" Error empty list found");
        }
        while (itr.hasNext()) {
            System.out.print("" + itr.next());
            if (itr.hasNext()) {
                System.out.print(",");
            } else {
                System.out.println();
            }
        }
    }
}
Also used : Transaction(javax.transaction.Transaction)

Aggregations

Transaction (javax.transaction.Transaction)160 SystemException (javax.transaction.SystemException)55 Test (org.junit.Test)42 RollbackException (javax.transaction.RollbackException)26 TransactionManager (javax.transaction.TransactionManager)24 UserTransaction (javax.transaction.UserTransaction)19 NotInTransactionException (org.neo4j.graphdb.NotInTransactionException)14 NotSupportedException (javax.transaction.NotSupportedException)13 Synchronization (javax.transaction.Synchronization)10 XAResource (javax.transaction.xa.XAResource)10 IntegrationTest (org.apache.geode.test.junit.categories.IntegrationTest)10 HazelcastXAResource (com.hazelcast.transaction.HazelcastXAResource)8 InvalidTransactionException (javax.transaction.InvalidTransactionException)7 TransactionContext (com.hazelcast.transaction.TransactionContext)6 RemoteException (java.rmi.RemoteException)6 ResourceException (javax.resource.ResourceException)6 ManagedConnection (javax.resource.spi.ManagedConnection)6 SQLException (java.sql.SQLException)5 HeuristicMixedException (javax.transaction.HeuristicMixedException)5 HeuristicRollbackException (javax.transaction.HeuristicRollbackException)5