use of org.sirix.exception.SirixUsageException 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.SirixUsageException 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