Search in sources :

Example 1 with SirixThreadedException

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;
}
Also used : SirixThreadedException(org.sirix.exception.SirixThreadedException) PageReadTrx(org.sirix.api.PageReadTrx)

Example 2 with SirixThreadedException

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;
}
Also used : SirixThreadedException(org.sirix.exception.SirixThreadedException) AtomicLong(java.util.concurrent.atomic.AtomicLong) Record(org.sirix.node.interfaces.Record) UnorderedKeyValuePage(org.sirix.page.UnorderedKeyValuePage) SirixUsageException(org.sirix.exception.SirixUsageException)

Example 3 with SirixThreadedException

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();
    }
}
Also used : SirixThreadedException(org.sirix.exception.SirixThreadedException) SirixUsageException(org.sirix.exception.SirixUsageException)

Example 4 with SirixThreadedException

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;
}
Also used : SirixThreadedException(org.sirix.exception.SirixThreadedException) XdmNodeReadTrx(org.sirix.api.XdmNodeReadTrx) Node(org.sirix.node.interfaces.Node) SirixUsageException(org.sirix.exception.SirixUsageException) PageReadTrx(org.sirix.api.PageReadTrx)

Example 5 with SirixThreadedException

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;
}
Also used : XdmNodeWriteTrx(org.sirix.api.XdmNodeWriteTrx) SirixThreadedException(org.sirix.exception.SirixThreadedException) Node(org.sirix.node.interfaces.Node) AtomicLong(java.util.concurrent.atomic.AtomicLong) Record(org.sirix.node.interfaces.Record) UnorderedKeyValuePage(org.sirix.page.UnorderedKeyValuePage) SirixUsageException(org.sirix.exception.SirixUsageException)

Aggregations

SirixThreadedException (org.sirix.exception.SirixThreadedException)5 SirixUsageException (org.sirix.exception.SirixUsageException)4 AtomicLong (java.util.concurrent.atomic.AtomicLong)2 PageReadTrx (org.sirix.api.PageReadTrx)2 Node (org.sirix.node.interfaces.Node)2 Record (org.sirix.node.interfaces.Record)2 UnorderedKeyValuePage (org.sirix.page.UnorderedKeyValuePage)2 XdmNodeReadTrx (org.sirix.api.XdmNodeReadTrx)1 XdmNodeWriteTrx (org.sirix.api.XdmNodeWriteTrx)1