Search in sources :

Example 1 with CommitLogRecord

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

the class StoreReadTransactionImpl method commit.

public void commit(AsyncCompletionCallback callback) {
    if (ctx.traceSpace.enabled)
        ctx.traceSpace.trace("sys$store", toString() + "/commit...");
    AsyncCompletionCallback localCallback = createLocalCallback(callback);
    if (checkClosedAsync(localCallback))
        return;
    txId = ctx.transactionManager.createTxId();
    journal = new ArrayList();
    queueIndex.setJournal(journal);
    try {
        for (int i = 0; i < keys.size(); i++) {
            addMessagePageReference(queueIndex.remove((QueueIndexEntry) keys.get(i)));
        }
    } catch (Exception e) {
        e.printStackTrace();
        localCallback.setException(e);
        localCallback.notifyCallbackStack(false);
        return;
    }
    keys.clear();
    if (journal != null && journal.size() > 0) {
        try {
            ctx.recoveryManager.commit(new CommitLogRecord(txId, null, journal, this, localCallback, messagePageRefs));
        } catch (Exception e) {
            localCallback.setException(new StoreException(e.toString()));
            localCallback.notifyCallbackStack(false);
        }
    } else
        localCallback.notifyCallbackStack(true);
    if (ctx.traceSpace.enabled)
        ctx.traceSpace.trace("sys$store", toString() + "/commit...done.");
}
Also used : AsyncCompletionCallback(com.swiftmq.tools.concurrent.AsyncCompletionCallback) CommitLogRecord(com.swiftmq.impl.store.standard.log.CommitLogRecord) ArrayList(java.util.ArrayList) 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 2 with CommitLogRecord

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

the class StoreTransactionImpl method commit.

public void commit() throws StoreException {
    if (ctx.traceSpace.enabled)
        ctx.traceSpace.trace("sys$store", toString() + "/commit...");
    if (closed)
        throw new StoreException("Transaction is closed");
    try {
        if (journal != null && journal.size() > 0) {
            ctx.recoveryManager.commit(new CommitLogRecord(txId, sem, journal, this, null, messagePageRefs));
            sem.waitHere();
        }
        ctx.transactionManager.removeTxId(txId);
        close();
    } catch (Exception e) {
        throw new StoreException(e.toString());
    }
    if (ctx.traceSpace.enabled)
        ctx.traceSpace.trace("sys$store", toString() + "/commit...done.");
}
Also used : CommitLogRecord(com.swiftmq.impl.store.standard.log.CommitLogRecord) StoreException(com.swiftmq.swiftlet.store.StoreException) StoreException(com.swiftmq.swiftlet.store.StoreException)

Example 3 with CommitLogRecord

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

the class CompositeStoreTransactionImpl method abortTransaction.

public void abortTransaction(AsyncCompletionCallback callback) {
    AsyncCompletionCallback localCallback = createLocalCallback(callback);
    checkClosedAsync(localCallback);
    if (localCallback.isNotified())
        return;
    boolean doNotify = true;
    if (journal != null && journal.size() > 0) {
        try {
            doNotify = false;
            if (keysRemoved != null && markRedelivered)
                ctx.recoveryManager.abort(new AbortLogRecord(txId, null, journal, this, null));
            else
                ctx.recoveryManager.abort(new AbortLogRecord(txId, null, journal, this, localCallback));
        } catch (Exception e) {
            localCallback.setException(new StoreException(e.toString()));
            localCallback.notifyCallbackStack(false);
            removeTxId();
            return;
        }
    }
    if (keysRemoved != null && markRedelivered) {
        List newJournal = new ArrayList();
        try {
            for (int i = 0; i < keysRemoved.size(); i++) {
                RemovedKeyEntry entry = keysRemoved.get(i);
                entry.queueIndex.setJournal(newJournal);
                entry.queueIndex.incDeliveryCount(entry.key);
            }
            doNotify = false;
            // don't wonder, we are committing the redelivered settings
            ctx.recoveryManager.commit(new CommitLogRecord(txId, null, newJournal, this, localCallback, null));
        } catch (Exception e) {
            localCallback.setException(new StoreException(e.toString()));
            localCallback.notifyCallbackStack(false);
            removeTxId();
            return;
        }
    }
    if (doNotify)
        callback.notifyCallbackStack(true);
}
Also used : AsyncCompletionCallback(com.swiftmq.tools.concurrent.AsyncCompletionCallback) CommitLogRecord(com.swiftmq.impl.store.standard.log.CommitLogRecord) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) AbortLogRecord(com.swiftmq.impl.store.standard.log.AbortLogRecord) StoreException(com.swiftmq.swiftlet.store.StoreException) StoreException(com.swiftmq.swiftlet.store.StoreException)

Example 4 with CommitLogRecord

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

the class CompositeStoreTransactionImpl method abortTransaction.

public void abortTransaction() throws StoreException {
    if (ctx.traceSpace.enabled)
        ctx.traceSpace.trace("sys$store", toString() + "/abortTransaction...");
    if (closed)
        throw new StoreException("Transaction is closed");
    try {
        if (journal != null && journal.size() > 0) {
            if (keysRemoved != null && markRedelivered)
                ctx.recoveryManager.abort(new AbortLogRecord(txId, null, journal, null));
            else {
                ctx.recoveryManager.abort(new AbortLogRecord(txId, sem, journal, this));
                sem.waitHere();
            }
        }
        if (keysRemoved != null && markRedelivered) {
            List newJournal = new ArrayList();
            for (int i = 0; i < keysRemoved.size(); i++) {
                RemovedKeyEntry entry = keysRemoved.get(i);
                entry.queueIndex.setJournal(newJournal);
                entry.queueIndex.incDeliveryCount(entry.key);
            }
            // don't wonder, we are committing the redelivered settings
            ctx.recoveryManager.commit(new CommitLogRecord(txId, sem, newJournal, this, null));
            sem.waitHere();
        }
        removeTxId();
        close();
    } catch (Exception e) {
        throw new StoreException(e.getMessage());
    }
    if (ctx.traceSpace.enabled)
        ctx.traceSpace.trace("sys$store", toString() + "/abortTransaction...done.");
}
Also used : CommitLogRecord(com.swiftmq.impl.store.standard.log.CommitLogRecord) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) AbortLogRecord(com.swiftmq.impl.store.standard.log.AbortLogRecord) StoreException(com.swiftmq.swiftlet.store.StoreException) StoreException(com.swiftmq.swiftlet.store.StoreException)

Example 5 with CommitLogRecord

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

the class CompositeStoreTransactionImpl method commitTransaction.

public void commitTransaction(AsyncCompletionCallback callback) {
    if (ctx.traceSpace.enabled)
        ctx.traceSpace.trace("sys$store", toString() + "/commit (callback) ...");
    AsyncCompletionCallback localCallback = createLocalCallback(callback);
    checkClosedAsync(localCallback);
    if (localCallback.isNotified())
        return;
    try {
        List<MessagePageReference> messagePageRefs = processRemovedKeys();
        if (journal != null && journal.size() > 0)
            ctx.recoveryManager.commit(new CommitLogRecord(txId, null, journal, this, localCallback, messagePageRefs));
        else {
            localCallback.notifyCallbackStack(true);
            removeTxId();
        }
    } catch (Exception e) {
        localCallback.setException(new StoreException(e.toString()));
        localCallback.notifyCallbackStack(false);
        removeTxId();
    }
    if (ctx.traceSpace.enabled)
        ctx.traceSpace.trace("sys$store", toString() + "/commit (callback) ... done.");
}
Also used : MessagePageReference(com.swiftmq.impl.store.standard.index.MessagePageReference) AsyncCompletionCallback(com.swiftmq.tools.concurrent.AsyncCompletionCallback) CommitLogRecord(com.swiftmq.impl.store.standard.log.CommitLogRecord) StoreException(com.swiftmq.swiftlet.store.StoreException) StoreException(com.swiftmq.swiftlet.store.StoreException)

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