Search in sources :

Example 6 with CommitLogRecord

use of com.swiftmq.impl.store.standard.log.CommitLogRecord in project swiftmq-ce by iitsoftware.

the class PreparedLogQueue method add.

public synchronized long add(PrepareLogRecordImpl logRecord) throws IOException {
    if (ctx.traceSpace.enabled)
        ctx.traceSpace.trace("sys$store", toString() + "/add, logRecord: " + logRecord);
    CacheEntry cacheEntry = new CacheEntry();
    cacheEntry.logRecord = logRecord;
    long address = (long) ArrayListTool.setFirstFreeOrExpand(cache, cacheEntry);
    logRecord.setAddress(address);
    outStream.rewind();
    logRecord.writeContent(outStream);
    try {
        BytesMessageImpl msg = new BytesMessageImpl();
        msg.writeBytes(outStream.getBuffer(), 0, outStream.getCount());
        StoreEntry storeEntry = new StoreEntry();
        storeEntry.message = msg;
        long txId = ctx.transactionManager.createTxId(false);
        List journal = new ArrayList();
        queueIndex.setJournal(journal);
        cacheEntry.indexEntry = queueIndex.add(storeEntry);
        Semaphore sem = new Semaphore();
        ctx.recoveryManager.commit(new CommitLogRecord(txId, sem, journal, this, null));
        sem.waitHere();
        ctx.transactionManager.removeTxId(txId);
    } catch (Exception e) {
        throw new IOException(e.toString());
    }
    return address;
}
Also used : BytesMessageImpl(com.swiftmq.jms.BytesMessageImpl) StoreEntry(com.swiftmq.swiftlet.store.StoreEntry) CommitLogRecord(com.swiftmq.impl.store.standard.log.CommitLogRecord) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) Semaphore(com.swiftmq.tools.concurrent.Semaphore) IOException(java.io.IOException) IOException(java.io.IOException) EOFException(java.io.EOFException)

Example 7 with CommitLogRecord

use of com.swiftmq.impl.store.standard.log.CommitLogRecord in project swiftmq-ce by iitsoftware.

the class RootIndex method deleteQueueIndex.

public synchronized void deleteQueueIndex(String queueName, QueueIndex queueIndex) throws Exception {
    List entries = queueIndex.getEntries();
    Semaphore sem = new Semaphore();
    List journal = new ArrayList();
    queueIndex.setJournal(journal);
    List refs = new ArrayList();
    for (Iterator iter = entries.iterator(); iter.hasNext(); ) {
        MessagePageReference ref = queueIndex.remove((QueueIndexEntry) iter.next());
        if (ref != null)
            refs.add(ref);
        if (journal.size() > 10000) {
            long txId = ctx.transactionManager.createTxId();
            CommitLogRecord logRecord = new CommitLogRecord(txId, sem, journal, new QueueIndexRelease(queueIndex), refs);
            ctx.recoveryManager.commit(logRecord);
            sem.waitHere();
            sem.reset();
            journal.clear();
            refs = new ArrayList();
            ctx.transactionManager.removeTxId(txId);
        }
    }
    IndexPage root = queueIndex.getIndexPage(queueIndex.getRootPageNo());
    byte[] bi = new byte[root.getFirstFreePosition()];
    System.arraycopy(root.getPage().data, 0, bi, 0, bi.length);
    journal.add(new DeleteLogAction(root.getPage().pageNo, bi));
    root.getPage().dirty = true;
    root.getPage().empty = true;
    setJournal(journal);
    remove(queueName);
    long txId = ctx.transactionManager.createTxId();
    CommitLogRecord logRecord = new CommitLogRecord(txId, sem, journal, new QueueRootIndexRelease(this, queueIndex), refs);
    ctx.recoveryManager.commit(logRecord);
    sem.waitHere();
    ctx.transactionManager.removeTxId(txId);
}
Also used : DeleteLogAction(com.swiftmq.impl.store.standard.log.DeleteLogAction) CommitLogRecord(com.swiftmq.impl.store.standard.log.CommitLogRecord) ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) List(java.util.List) ArrayList(java.util.ArrayList) Semaphore(com.swiftmq.tools.concurrent.Semaphore)

Example 8 with CommitLogRecord

use of com.swiftmq.impl.store.standard.log.CommitLogRecord in project swiftmq-ce by iitsoftware.

the class StoreWriteTransactionImpl method abort.

public void abort(XidImpl globalTxId) throws StoreException {
    if (ctx.traceSpace.enabled)
        ctx.traceSpace.trace("sys$store", toString() + "/abort, globalTxId: " + globalTxId);
    txId = ctx.transactionManager.createTxId();
    sem = new Semaphore();
    journal = new ArrayList();
    queueIndex.setJournal(journal);
    try {
        for (int i = 0; i < keys.size(); i++) {
            addMessagePageReference(queueIndex.remove((QueueIndexEntry) keys.get(i)));
        }
        ctx.recoveryManager.commit(new CommitLogRecord(txId, sem, journal, this, messagePageRefs));
        sem.waitHere();
        ctx.transactionManager.removeTxId(txId);
    } catch (Exception e) {
        throw new StoreException(e.toString());
    }
    if (prepareLogRecord != null) {
        try {
            ctx.preparedLog.remove(prepareLogRecord);
        } catch (IOException e) {
            throw new StoreException(e.toString());
        }
        prepareLogRecord = null;
    }
    close();
    if (ctx.traceSpace.enabled)
        ctx.traceSpace.trace("sys$store", toString() + "/abort, globalTxId: " + globalTxId + ", done");
}
Also used : CommitLogRecord(com.swiftmq.impl.store.standard.log.CommitLogRecord) ArrayList(java.util.ArrayList) Semaphore(com.swiftmq.tools.concurrent.Semaphore) IOException(java.io.IOException) QueueIndexEntry(com.swiftmq.impl.store.standard.index.QueueIndexEntry) StoreException(com.swiftmq.swiftlet.store.StoreException) IOException(java.io.IOException) StoreException(com.swiftmq.swiftlet.store.StoreException)

Example 9 with CommitLogRecord

use of com.swiftmq.impl.store.standard.log.CommitLogRecord in project swiftmq-ce by iitsoftware.

the class StoreWriteTransactionImpl method prepare.

public void prepare(XidImpl globalTxId) throws StoreException {
    if (ctx.traceSpace.enabled)
        ctx.traceSpace.trace("sys$store", toString() + "/prepare, globalTxId=" + globalTxId);
    try {
        prepareLogRecord = new PrepareLogRecordImpl(PrepareLogRecordImpl.WRITE_TRANSACTION, queueName, globalTxId, keys);
        ctx.preparedLog.add(prepareLogRecord);
        ctx.recoveryManager.commit(new CommitLogRecord(txId, sem, journal, this, null));
        sem.waitHere();
        ctx.transactionManager.removeTxId(txId);
    } catch (Exception e) {
        throw new StoreException(e.getMessage());
    }
    if (ctx.traceSpace.enabled)
        ctx.traceSpace.trace("sys$store", toString() + "/prepare, globalTxId=" + globalTxId + ", done");
}
Also used : CommitLogRecord(com.swiftmq.impl.store.standard.log.CommitLogRecord) PrepareLogRecordImpl(com.swiftmq.impl.store.standard.xa.PrepareLogRecordImpl) StoreException(com.swiftmq.swiftlet.store.StoreException) IOException(java.io.IOException) StoreException(com.swiftmq.swiftlet.store.StoreException)

Example 10 with CommitLogRecord

use of com.swiftmq.impl.store.standard.log.CommitLogRecord in project swiftmq-ce by iitsoftware.

the class RootIndex method getQueueIndex.

public synchronized QueueIndex getQueueIndex(String queueName) throws Exception {
    IndexEntry entry = find(queueName);
    if (entry == null) {
        Semaphore sem = new Semaphore();
        List journal = new ArrayList();
        setJournal(journal);
        QueueIndexPage indexPage = new QueueIndexPage(ctx, -1);
        journal.add(new InsertLogAction(indexPage.getPage().pageNo));
        indexPage.setJournal(journal);
        indexPage.setPrevPage(-1);
        indexPage.setNextPage(-1);
        entry = new RootIndexEntry();
        entry.setKey(queueName);
        entry.setRootPageNo(indexPage.getPage().pageNo);
        add(entry);
        long txId = ctx.transactionManager.createTxId();
        CommitLogRecord logRecord = new CommitLogRecord(txId, sem, journal, new IndexPageRelease(this, indexPage), null);
        ctx.recoveryManager.commit(logRecord);
        sem.waitHere();
        ctx.transactionManager.removeTxId(txId);
    } else
        unloadPages();
    return new QueueIndex(ctx, entry.getRootPageNo());
}
Also used : CommitLogRecord(com.swiftmq.impl.store.standard.log.CommitLogRecord) ArrayList(java.util.ArrayList) InsertLogAction(com.swiftmq.impl.store.standard.log.InsertLogAction) List(java.util.List) ArrayList(java.util.ArrayList) Semaphore(com.swiftmq.tools.concurrent.Semaphore)

Aggregations

CommitLogRecord (com.swiftmq.impl.store.standard.log.CommitLogRecord)12 StoreException (com.swiftmq.swiftlet.store.StoreException)8 ArrayList (java.util.ArrayList)8 List (java.util.List)6 Semaphore (com.swiftmq.tools.concurrent.Semaphore)5 IOException (java.io.IOException)5 AsyncCompletionCallback (com.swiftmq.tools.concurrent.AsyncCompletionCallback)3 MessagePageReference (com.swiftmq.impl.store.standard.index.MessagePageReference)2 QueueIndexEntry (com.swiftmq.impl.store.standard.index.QueueIndexEntry)2 AbortLogRecord (com.swiftmq.impl.store.standard.log.AbortLogRecord)2 EOFException (java.io.EOFException)2 DeleteLogAction (com.swiftmq.impl.store.standard.log.DeleteLogAction)1 InsertLogAction (com.swiftmq.impl.store.standard.log.InsertLogAction)1 PrepareLogRecordImpl (com.swiftmq.impl.store.standard.xa.PrepareLogRecordImpl)1 BytesMessageImpl (com.swiftmq.jms.BytesMessageImpl)1 StoreEntry (com.swiftmq.swiftlet.store.StoreEntry)1 Iterator (java.util.Iterator)1