Search in sources :

Example 1 with MessagePageReference

use of com.swiftmq.impl.store.standard.index.MessagePageReference in project swiftmq-ce by iitsoftware.

the class CompositeStoreTransactionImpl method processRemovedKeys.

private List<MessagePageReference> processRemovedKeys() throws Exception {
    List<MessagePageReference> messagePageRefs = null;
    if (keysRemoved != null) {
        for (int i = 0; i < keysRemoved.size(); i++) {
            RemovedKeyEntry entry = keysRemoved.get(i);
            entry.queueIndex.setJournal(journal);
            MessagePageReference ref = entry.queueIndex.remove(entry.key);
            if (ref != null) {
                if (messagePageRefs == null)
                    messagePageRefs = new ArrayList<MessagePageReference>();
                messagePageRefs.add(ref);
            }
        }
    }
    return messagePageRefs;
}
Also used : MessagePageReference(com.swiftmq.impl.store.standard.index.MessagePageReference) ArrayList(java.util.ArrayList)

Example 2 with MessagePageReference

use of com.swiftmq.impl.store.standard.index.MessagePageReference 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)

Example 3 with MessagePageReference

use of com.swiftmq.impl.store.standard.index.MessagePageReference in project swiftmq-ce by iitsoftware.

the class LogManager method process.

protected void process(Object[] bulk, int n) {
    if (closed && !checkPointPending)
        return;
    if (ctx.traceSpace.enabled)
        ctx.traceSpace.trace("sys$store", toString() + "/process,length=" + n);
    try {
        if (logManagerListener != null)
            logManagerListener.startProcessing();
        boolean checkPointNow = false;
        for (int i = 0; i < n; i++) {
            LogOperation oper = (LogOperation) bulk[i];
            if (ctx.traceSpace.enabled)
                ctx.traceSpace.trace("sys$store", toString() + "/process, operation=" + oper);
            switch(oper.getOperationType()) {
                case LogOperation.OPER_LOG_REC:
                    LogRecord lr = (LogRecord) oper;
                    logFile.write(lr);
                    Semaphore s = lr.getSemaphore();
                    if (s != null)
                        semList.add(s);
                    CacheReleaseListener crl = lr.getCacheReleaseListener();
                    if (crl != null)
                        releaseList.add(crl);
                    AsyncCompletionCallback cb = lr.getCallback();
                    if (cb != null)
                        callbackList.add(cb);
                    // Releasing locks on shared message pages
                    List messagePageRefs = lr.getMessagePageRefs();
                    if (messagePageRefs != null) {
                        for (int j = 0; j < messagePageRefs.size(); j++) {
                            ((MessagePageReference) messagePageRefs.get(j)).unMarkActive();
                        }
                    }
                    break;
                case LogOperation.OPER_CLOSE_LOG:
                    closeSem = ((CloseLogOperation) oper).getSemaphore();
                    closed = true;
                    break;
                case LogOperation.OPER_INITIATE_SYNC:
                    checkPointInitiated = true;
                    break;
                case LogOperation.OPER_SYNC_LOG:
                    checkPointNow = true;
                    break;
            }
        }
        // write the log to the log file
        if (logFile.getFlushSize() > 0)
            logFile.flush(forceSync);
        if (ctx.traceSpace.enabled)
            ctx.traceSpace.trace("sys$store", toString() + "/process, processed log objects=" + n);
        if (checkPointNow) {
            if (checkPointVerbose)
                System.out.println("+++ CHECKPOINT ... ");
            long start = System.currentTimeMillis();
            // Trigger CP Handler to flush the cache.
            checkPointHandler.performCheckPoint();
            // Start new log file
            logFile.reset(forceSync);
            // continue normal operation
            checkPointHandler.checkPointDone();
            checkPointPending = false;
            if (checkPointVerbose)
                System.out.println("+++ CHECKPOINT DONE in " + (System.currentTimeMillis() - start) + " milliseconds");
            if (closed) {
                if (logManagerListener != null)
                    logManagerListener.stopProcessing();
                closeSem.notifySingleWaiter();
                return;
            }
        }
        if (ctx.traceSpace.enabled)
            ctx.traceSpace.trace("sys$store", toString() + "/process, releaseList.size=" + releaseList.size() + ", semList.size=" + semList.size() + ", callbackList.size=" + callbackList.size());
        // call back cache release listeners
        if (releaseList.size() > 0) {
            for (int i = 0; i < releaseList.size(); i++) {
                CacheReleaseListener crl = (CacheReleaseListener) releaseList.get(i);
                crl.releaseCache();
            }
            if (ctx.traceSpace.enabled)
                ctx.traceSpace.trace("sys$store", toString() + "/process, " + releaseList.size() + " CacheReleaseListeners called");
            releaseList.clear();
        }
        if (logManagerListener != null)
            logManagerListener.stopProcessing();
        // notify Semaphores
        if (semList.size() > 0) {
            for (int i = 0; i < semList.size(); i++) {
                Semaphore ls = (Semaphore) semList.get(i);
                ls.notifySingleWaiter();
            }
            if (ctx.traceSpace.enabled)
                ctx.traceSpace.trace("sys$store", toString() + "/process, " + semList.size() + " semaphores notified");
            semList.clear();
        }
        // notify callbacks
        if (callbackList.size() > 0) {
            for (int i = 0; i < callbackList.size(); i++) {
                AsyncCompletionCallback cb = (AsyncCompletionCallback) callbackList.get(i);
                cb.notifyCallbackStack(true);
            }
            if (ctx.traceSpace.enabled)
                ctx.traceSpace.trace("sys$store", toString() + "/process, " + callbackList.size() + " AsyncCompletionCallbacks called");
            callbackList.clear();
        }
        if (ctx.traceSpace.enabled)
            ctx.traceSpace.trace("sys$store", toString() + "/process, logFile.length=" + logFile.getPosition());
        // SyncLogOperation into the queue.
        if (!checkPointPending && (closed || checkPointInitiated || logFile.getPosition() >= maxLogSize)) {
            if (ctx.traceSpace.enabled)
                ctx.traceSpace.trace("sys$store", toString() + "/process, checkPointHandler.lockForCheckPoint()");
            checkPointHandler.lockForCheckPoint();
            checkPointPending = true;
            checkPointInitiated = false;
        }
    } catch (Exception e) {
        // PANIC
        if (ctx.traceSpace.enabled)
            ctx.traceSpace.trace("sys$store", toString() + "/process, exception occurred=" + e);
        ctx.logSwiftlet.logError("sys$store", toString() + "/process, PANIC! EXITING! Exception occurred=" + e);
        e.printStackTrace();
        SwiftletManager.getInstance().disableShutdownHook();
        System.exit(-1);
    }
}
Also used : MessagePageReference(com.swiftmq.impl.store.standard.index.MessagePageReference) AsyncCompletionCallback(com.swiftmq.tools.concurrent.AsyncCompletionCallback) ArrayList(java.util.ArrayList) List(java.util.List) Semaphore(com.swiftmq.tools.concurrent.Semaphore) CacheReleaseListener(com.swiftmq.impl.store.standard.cache.CacheReleaseListener)

Example 4 with MessagePageReference

use of com.swiftmq.impl.store.standard.index.MessagePageReference in project swiftmq-ce by iitsoftware.

the class CompositeStoreTransactionImpl method commitTransaction.

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

Aggregations

MessagePageReference (com.swiftmq.impl.store.standard.index.MessagePageReference)4 CommitLogRecord (com.swiftmq.impl.store.standard.log.CommitLogRecord)2 StoreException (com.swiftmq.swiftlet.store.StoreException)2 AsyncCompletionCallback (com.swiftmq.tools.concurrent.AsyncCompletionCallback)2 ArrayList (java.util.ArrayList)2 CacheReleaseListener (com.swiftmq.impl.store.standard.cache.CacheReleaseListener)1 Semaphore (com.swiftmq.tools.concurrent.Semaphore)1 List (java.util.List)1