use of org.sirix.exception.SirixThreadedException in project sirix by sirixdb.
the class XdmResourceManager method beginPageReadTrx.
@Override
public synchronized PageReadTrx beginPageReadTrx(@Nonnegative final int revision) {
assertAccess(revision);
final long currentPageTrxID = mPageTrxIDCounter.incrementAndGet();
final PageReadTrx pageReadTrx = new PageReadTrxImpl(currentPageTrxID, this, mLastCommittedUberPage.get(), revision, mFac.createReader(), null, null, mBufferManager);
// Remember page transaction for debugging and safe close.
if (mPageTrxMap.put(currentPageTrxID, pageReadTrx) != null) {
throw new SirixThreadedException("ID generation is bogus because of duplicate ID.");
}
return pageReadTrx;
}
use of org.sirix.exception.SirixThreadedException in project sirix by sirixdb.
the class XdmResourceManager method beginPageWriteTrx.
@Override
public synchronized PageWriteTrx<Long, Record, UnorderedKeyValuePage> beginPageWriteTrx(@Nonnegative final int revision) throws SirixException {
assertAccess(revision);
// Make sure not to exceed available number of write transactions.
try {
if (!mWriteSemaphore.tryAcquire(20, TimeUnit.SECONDS)) {
throw new SirixUsageException("No write transaction available, please close the write transaction first.");
}
} catch (final InterruptedException e) {
throw new SirixThreadedException(e);
}
final long currentPageTrxID = mPageTrxIDCounter.incrementAndGet();
final int lastRev = mLastCommittedUberPage.get().getRevisionNumber();
final PageWriteTrx<Long, Record, UnorderedKeyValuePage> pageWtx = createPageWriteTransaction(currentPageTrxID, lastRev, lastRev, Abort.NO);
// Remember page transaction for debugging and safe close.
if (mPageTrxMap.put(currentPageTrxID, pageWtx) != null) {
throw new SirixThreadedException("ID generation is bogus because of duplicate ID.");
}
return pageWtx;
}
use of org.sirix.exception.SirixThreadedException in project sirix by sirixdb.
the class XdmNodeWriterTrxImpl method close.
@Override
public void close() {
acquireLock();
try {
if (!isClosed()) {
// Make sure to commit all dirty data.
if (mModificationCount > 0) {
throw new SirixUsageException("Must commit/rollback transaction first!");
}
// Release all state immediately.
mNodeReader.mResourceManager.closeWriteTransaction(getId());
mNodeReader.close();
removeCommitFile();
mPathSummaryWriter = null;
mNodeFactory = null;
// Shutdown pool.
mPool.shutdown();
try {
mPool.awaitTermination(2, TimeUnit.SECONDS);
} catch (final InterruptedException e) {
throw new SirixThreadedException(e);
}
}
} finally {
unLock();
}
}
use of org.sirix.exception.SirixThreadedException in project sirix by sirixdb.
the class XdmResourceManager method beginNodeReadTrx.
@Override
public synchronized XdmNodeReadTrx beginNodeReadTrx(@Nonnegative final int revisionKey) {
assertAccess(revisionKey);
// Make sure not to exceed available number of read transactions.
try {
if (!mReadSemaphore.tryAcquire(20, TimeUnit.SECONDS)) {
throw new SirixUsageException("No read transactions available, please close at least one read transaction at first!");
}
} catch (final InterruptedException e) {
throw new SirixThreadedException(e);
}
final PageReadTrx pageReadTrx = beginPageReadTrx(revisionKey);
final Node documentNode = getDocumentNode(pageReadTrx);
// Create new reader.
final XdmNodeReadTrx reader = new XdmNodeReadTrxImpl(this, mNodeTrxIDCounter.incrementAndGet(), pageReadTrx, documentNode);
// Remember reader for debugging and safe close.
if (mNodeReaderMap.put(reader.getId(), reader) != null) {
throw new SirixUsageException("ID generation is bogus because of duplicate ID.");
}
return reader;
}
use of org.sirix.exception.SirixThreadedException in project sirix by sirixdb.
the class XdmResourceManager method beginNodeWriteTrx.
@Override
public synchronized XdmNodeWriteTrx beginNodeWriteTrx(@Nonnegative final int maxNodeCount, @Nonnull final TimeUnit timeUnit, @Nonnegative final int maxTime) {
// Checks.
assertAccess(mLastCommittedUberPage.get().getRevision());
if (maxNodeCount < 0 || maxTime < 0) {
throw new SirixUsageException("maxNodeCount may not be < 0!");
}
checkNotNull(timeUnit);
// Make sure not to exceed available number of write transactions.
try {
if (!mWriteSemaphore.tryAcquire(20, TimeUnit.SECONDS)) {
throw new SirixUsageException("No write transaction available, please close the write transaction first.");
}
} catch (final InterruptedException e) {
throw new SirixThreadedException(e);
}
// Create new page write transaction (shares the same ID with the node write trx).
final long currentTrxID = mNodeTrxIDCounter.incrementAndGet();
final int lastRev = mLastCommittedUberPage.get().getRevisionNumber();
final PageWriteTrx<Long, Record, UnorderedKeyValuePage> pageWtx = createPageWriteTransaction(currentTrxID, lastRev, lastRev, Abort.NO);
final Node documentNode = getDocumentNode(pageWtx);
// Create new node write transaction.
final XdmNodeWriteTrx wtx = new XdmNodeWriterTrxImpl(currentTrxID, this, pageWtx, maxNodeCount, timeUnit, maxTime, documentNode);
// Remember node transaction for debugging and safe close.
if (mNodeReaderMap.put(currentTrxID, wtx) != null || mNodePageTrxMap.put(currentTrxID, pageWtx) != null) {
throw new SirixThreadedException("ID generation is bogus because of duplicate ID.");
}
return wtx;
}
Aggregations