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);
}
}
}
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);
}
}
}
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--;
}
}
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--;
}
}
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();
}
}
}
}
Aggregations