Search in sources :

Example 51 with Semaphore

use of com.swiftmq.tools.concurrent.Semaphore in project swiftmq-ce by iitsoftware.

the class ShrinkJob method start.

public synchronized void start(Properties properties, JobTerminationListener jobTerminationListener) throws JobException {
    if (ctx.traceSpace.enabled)
        ctx.traceSpace.trace(ctx.storeSwiftlet.getName(), toString() + "/start, properties=" + properties + " ...");
    this.jobTerminationListener = jobTerminationListener;
    this.properties = properties;
    Semaphore sem = new Semaphore();
    StartShrink po = new StartShrink(sem);
    ctx.shrinkProcessor.enqueue(po);
    sem.waitHere();
    if (po.isSuccess())
        jobTerminationListener.jobTerminated();
    else
        jobTerminationListener.jobTerminated(new JobException(po.getException(), new Exception(po.getException()), false));
    if (ctx.traceSpace.enabled)
        ctx.traceSpace.trace(ctx.storeSwiftlet.getName(), toString() + "/start, properties=" + properties + " ...");
}
Also used : JobException(com.swiftmq.swiftlet.scheduler.JobException) Semaphore(com.swiftmq.tools.concurrent.Semaphore) StartShrink(com.swiftmq.impl.store.standard.cache.po.StartShrink) JobException(com.swiftmq.swiftlet.scheduler.JobException)

Example 52 with Semaphore

use of com.swiftmq.tools.concurrent.Semaphore 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 53 with Semaphore

use of com.swiftmq.tools.concurrent.Semaphore in project swiftmq-client by iitsoftware.

the class JSSESocketFactory method createSocket.

public Socket createSocket(String host, int port, boolean useTcpNoDelay) throws UnknownHostException, IOException {
    SSLSocket sslSocket = null;
    if (HttpTunnelProperties.getInstance().isProxy() && HttpTunnelProperties.getInstance().isHostViaProxy(host)) {
        Socket socket = new Socket(HttpTunnelProperties.getInstance().getProxyHost(), HttpTunnelProperties.getInstance().getProxyPort());
        HttpTunnelProperties.getInstance().setupHttpProxy(host, port, socket.getInputStream(), socket.getOutputStream());
        sslSocket = (SSLSocket) getSocketFactory().createSocket(socket, host, port, true);
    } else
        sslSocket = (SSLSocket) getSocketFactory().createSocket(host, port);
    if (SO_TIMEOUT > 0) {
        try {
            sslSocket.setSoTimeout(SO_TIMEOUT);
        } catch (SocketException e) {
            System.err.println("JSSESocketFactory: Unable to perform 'socket.setSoTimeout(" + SO_TIMEOUT + ")', exception: " + e);
        }
    }
    sslSocket.setTcpNoDelay(useTcpNoDelay);
    Semaphore sem = new Semaphore();
    sslSocket.addHandshakeCompletedListener(new CompletionListener(sem));
    sslSocket.startHandshake();
    sem.waitHere();
    return sslSocket;
}
Also used : Semaphore(com.swiftmq.tools.concurrent.Semaphore)

Example 54 with Semaphore

use of com.swiftmq.tools.concurrent.Semaphore in project swiftmq-ce by iitsoftware.

the class Forwarder method forward.

public void forward() {
    sem = new Semaphore();
    sem.waitHere();
    if (exception != null)
        failFast("failed: " + exception);
    try {
        verifier.verify();
    } catch (Exception e) {
        failFast("failed: " + e);
    }
}
Also used : Semaphore(com.swiftmq.tools.concurrent.Semaphore)

Example 55 with Semaphore

use of com.swiftmq.tools.concurrent.Semaphore in project swiftmq-ce by iitsoftware.

the class Consumer method consume.

public void consume() {
    sem = new Semaphore();
    sem.waitHere();
    if (exception != null)
        failFast("failed: " + exception);
    try {
        verifier.verify();
    } catch (Exception e) {
        failFast("failed: " + e);
    }
}
Also used : Semaphore(com.swiftmq.tools.concurrent.Semaphore)

Aggregations

Semaphore (com.swiftmq.tools.concurrent.Semaphore)149 MsgNoVerifier (jms.base.MsgNoVerifier)18 IOException (java.io.IOException)8 SwiftletException (com.swiftmq.swiftlet.SwiftletException)6 ArrayList (java.util.ArrayList)6 CommitLogRecord (com.swiftmq.impl.store.standard.log.CommitLogRecord)5 DataStreamOutputStream (com.swiftmq.tools.util.DataStreamOutputStream)5 List (java.util.List)5 StartBackup (com.swiftmq.impl.store.standard.backup.po.StartBackup)2 StartShrink (com.swiftmq.impl.store.standard.cache.po.StartShrink)2 UnknownHostException (java.net.UnknownHostException)2 POAttachDurableConsumer (com.swiftmq.amqp.v100.client.po.POAttachDurableConsumer)1 POAuthenticate (com.swiftmq.amqp.v100.client.po.POAuthenticate)1 POCloseLink (com.swiftmq.amqp.v100.client.po.POCloseLink)1 POOpen (com.swiftmq.amqp.v100.client.po.POOpen)1 POProtocolRequest (com.swiftmq.amqp.v100.client.po.POProtocolRequest)1 POSendClose (com.swiftmq.amqp.v100.client.po.POSendClose)1 POSendMessage (com.swiftmq.amqp.v100.client.po.POSendMessage)1 AddressString (com.swiftmq.amqp.v100.generated.messaging.message_format.AddressString)1 Header (com.swiftmq.amqp.v100.generated.messaging.message_format.Header)1