Search in sources :

Example 81 with Semaphore

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

the class Connection method close.

protected void close(String condition, String description) {
    if (closed)
        return;
    if (condition == null) {
        Semaphore sem = new Semaphore();
        POSendClose po = new POSendClose(sem, condition == null ? null : new AMQPSymbol(condition), description == null ? null : new AMQPString(description));
        connectionDispatcher.dispatch(po);
        sem.waitHere();
    } else {
        POSendClose po = new POSendClose(null, condition == null ? null : new AMQPSymbol(condition), description == null ? null : new AMQPString(description));
        connectionDispatcher.dispatch(po);
    }
    cancel();
    if (exceptionListener != null && condition != null && description != null)
        exceptionListener.onException(new ConnectionClosedException(condition + " / " + description));
}
Also used : AMQPSymbol(com.swiftmq.amqp.v100.types.AMQPSymbol) Semaphore(com.swiftmq.tools.concurrent.Semaphore) AMQPString(com.swiftmq.amqp.v100.types.AMQPString) POSendClose(com.swiftmq.amqp.v100.client.po.POSendClose)

Example 82 with Semaphore

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

the class ConnectionDispatcher method close.

public void close() {
    if (pTracer.isEnabled())
        pTracer.trace(toString(), ", close ...");
    try {
        closeLock.lock();
        if (closeInProgress) {
            if (pTracer.isEnabled())
                pTracer.trace(toString(), ", close in progress, return");
            return;
        }
        closeInProgress = true;
        if (heartBeatSender != null) {
            TimerRegistry.Singleton().removeTimerListener(heartBeatDelay, heartBeatSender);
            heartBeatSender = null;
        }
        if (idleTimeoutChecker != null) {
            TimerRegistry.Singleton().removeTimerListener(idleTimeoutDelay, idleTimeoutChecker);
            idleTimeoutChecker = null;
        }
    } finally {
        closeLock.unlock();
    }
    Semaphore sem = new Semaphore();
    dispatch(new POConnectionClose(sem));
    sem.waitHere();
    if (pTracer.isEnabled())
        pTracer.trace(toString(), ", close done");
}
Also used : Semaphore(com.swiftmq.tools.concurrent.Semaphore)

Example 83 with Semaphore

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

the class AMQPSwiftlet method shutdown.

protected void shutdown() throws SwiftletException {
    // true when shutdown while standby
    if (ctx == null)
        return;
    if (ctx.traceSpace.enabled)
        ctx.traceSpace.trace(getName(), "shutdown ...");
    try {
        listenerAdapter.close();
        if (ctx.traceSpace.enabled)
            ctx.traceSpace.trace(getName(), "shutdown: shutdown all AMQP connections");
        Semaphore sem = getShutdownSemaphore();
        ConnectionManager connectionManager = ctx.networkSwiftlet.getConnectionManager();
        Connection[] c = (Connection[]) connections.toArray(new Connection[connections.size()]);
        connections.clear();
        for (int i = 0; i < c.length; i++) {
            connectionManager.removeConnection(c[i]);
        }
        if (sem != null) {
            System.out.println("+++ waiting for connection shutdown ...");
            sem.waitHere();
            try {
                Thread.sleep(5000);
            } catch (Exception ignored) {
            }
        }
        ctx.mgmtSwiftlet.removeMgmtListener(this);
        Security.removeProvider(SASLProvider.PROVIDER_NAME);
    } catch (Exception e) {
        e.printStackTrace();
    }
    if (ctx.traceSpace.enabled)
        ctx.traceSpace.trace(getName(), "shutdown done.");
    ctx = null;
}
Also used : ConnectionManager(com.swiftmq.swiftlet.net.ConnectionManager) Connection(com.swiftmq.swiftlet.net.Connection) Semaphore(com.swiftmq.tools.concurrent.Semaphore) SwiftletException(com.swiftmq.swiftlet.SwiftletException) ConnectionVetoException(com.swiftmq.swiftlet.net.ConnectionVetoException)

Example 84 with Semaphore

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

the class AMQPHandler method visit.

public void visit(POConnectionFrameReceived po) {
    if (ctx.traceSpace.enabled)
        ctx.traceSpace.trace(ctx.amqpSwiftlet.getName(), toString() + ", visit, po=" + po + " ...");
    po.getFrame().accept(connectionVisitorAdapter);
    Semaphore sem = po.getSemaphore();
    if (sem != null)
        sem.notifySingleWaiter();
    if (ctx.traceSpace.enabled)
        ctx.traceSpace.trace(ctx.amqpSwiftlet.getName(), toString() + ", visit, po=" + po + " done");
}
Also used : Semaphore(com.swiftmq.tools.concurrent.Semaphore)

Example 85 with Semaphore

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

the class ChannelHandler method close.

public void close() {
    if (ctx.traceSpace.enabled)
        ctx.traceSpace.trace(ctx.amqpSwiftlet.getName(), toString() + ", close ...");
    closeLock.lock();
    if (closeInProgress) {
        if (ctx.traceSpace.enabled)
            ctx.traceSpace.trace(ctx.amqpSwiftlet.getName(), toString() + ", close in progress, return");
        return;
    }
    closeInProgress = true;
    closeLock.unlock();
    channelDisabled = false;
    Semaphore sem = new Semaphore();
    dispatch(new POCloseChannel(sem));
    sem.waitHere();
    if (ctx.traceSpace.enabled)
        ctx.traceSpace.trace(ctx.amqpSwiftlet.getName(), toString() + ", close done");
}
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