Search in sources :

Example 1 with POSendClose

use of com.swiftmq.amqp.v100.client.po.POSendClose in project swiftmq-ce by iitsoftware.

the class AMQPHandler method visit.

public void visit(POSendClose po) {
    if (ctx.traceSpace.enabled)
        ctx.traceSpace.trace(ctx.amqpSwiftlet.getName(), toString() + ", visit, po=" + po + " ...");
    CloseFrame frame = new CloseFrame(0);
    if (po.getErrorCondition() != null) {
        com.swiftmq.amqp.v100.generated.transport.definitions.Error error = new Error();
        error.setCondition(po.getErrorCondition());
        if (po.getDescription() != null)
            error.setDescription(po.getDescription());
        frame.setError(error);
        connectionDisabled = true;
    }
    frame.setCallback(new AsyncCompletionCallback() {

        public void done(boolean b) {
            ctx.networkSwiftlet.getConnectionManager().removeConnection(versionedConnection.getConnection());
        }
    });
    versionedConnection.send(frame);
    closeFrameSent = true;
    if (ctx.traceSpace.enabled)
        ctx.traceSpace.trace(ctx.amqpSwiftlet.getName(), toString() + ", visit, po=" + po + " done");
}
Also used : Error(com.swiftmq.amqp.v100.generated.transport.definitions.Error) AsyncCompletionCallback(com.swiftmq.tools.concurrent.AsyncCompletionCallback) ConnectionError(com.swiftmq.amqp.v100.generated.transport.definitions.ConnectionError) Error(com.swiftmq.amqp.v100.generated.transport.definitions.Error) AmqpError(com.swiftmq.amqp.v100.generated.transport.definitions.AmqpError)

Example 2 with POSendClose

use of com.swiftmq.amqp.v100.client.po.POSendClose 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 3 with POSendClose

use of com.swiftmq.amqp.v100.client.po.POSendClose in project swiftmq-client by iitsoftware.

the class ConnectionDispatcher method visit.

public void visit(POSendClose po) {
    if (pTracer.isEnabled())
        pTracer.trace(toString(), ", visit, po=" + po + " ...");
    if (po.getSemaphore() != null)
        closePO = po;
    try {
        CloseFrame closeFrame = new CloseFrame(0);
        if (po.getCondition() != null) {
            com.swiftmq.amqp.v100.generated.transport.definitions.Error error = new com.swiftmq.amqp.v100.generated.transport.definitions.Error();
            error.setCondition(ErrorConditionFactory.create(po.getCondition()));
            if (po.getDescription() != null)
                error.setDescription(po.getDescription());
            closeFrame.setError(error);
        }
        Semaphore sem = new Semaphore();
        closeFrame.setSemaphore(sem);
        outboundHandler.send(closeFrame);
        sem.waitHere();
    } catch (Exception e) {
        if (po.getSemaphore() != null) {
            po.setException(e.toString());
            po.setSuccess(false);
            po.getSemaphore().notifySingleWaiter();
        }
    }
    if (pTracer.isEnabled())
        pTracer.trace(toString(), ", visit, po=" + po + " done");
}
Also used : ConnectionError(com.swiftmq.amqp.v100.generated.transport.definitions.ConnectionError) Semaphore(com.swiftmq.tools.concurrent.Semaphore) SaslException(javax.security.sasl.SaslException) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException)

Aggregations

ConnectionError (com.swiftmq.amqp.v100.generated.transport.definitions.ConnectionError)2 Semaphore (com.swiftmq.tools.concurrent.Semaphore)2 POSendClose (com.swiftmq.amqp.v100.client.po.POSendClose)1 AmqpError (com.swiftmq.amqp.v100.generated.transport.definitions.AmqpError)1 Error (com.swiftmq.amqp.v100.generated.transport.definitions.Error)1 AMQPString (com.swiftmq.amqp.v100.types.AMQPString)1 AMQPSymbol (com.swiftmq.amqp.v100.types.AMQPSymbol)1 AsyncCompletionCallback (com.swiftmq.tools.concurrent.AsyncCompletionCallback)1 IOException (java.io.IOException)1 UnknownHostException (java.net.UnknownHostException)1 SaslException (javax.security.sasl.SaslException)1