Example usage for com.rabbitmq.client Command getMethod

List of usage examples for com.rabbitmq.client Command getMethod

Introduction

In this page you can find the example usage for com.rabbitmq.client Command getMethod.

Prototype

Method getMethod();

Source Link

Document

Retrieves the Method held within this Command.

Usage

From source file:de.htwk_leipzig.bis.connection.handshake.clientRewrite.Copyright.java

License:Mozilla Public License

/**
 * Handles incoming control commands on channel zero.
 * //from  w w  w .ja  v  a2s .c o  m
 * @see ChannelN#processAsync
 */
@SuppressWarnings("unused")
public boolean processControlCommand(Command c) throws IOException {
    // Similar trick to ChannelN.processAsync used here, except
    // we're interested in whole-connection quiescing.

    // See the detailed comments in ChannelN.processAsync.

    Method method = c.getMethod();

    if (isOpen()) {
        if (method instanceof AMQP.Connection.Close) {
            handleConnectionClose(c);
            return true;
        } else if (method instanceof AMQP.Connection.Blocked) {
            AMQP.Connection.Blocked blocked = (AMQP.Connection.Blocked) method;
            try {
                for (BlockedListener l : this.blockedListeners) {
                    l.handleBlocked(blocked.getReason());
                }
            } catch (Throwable ex) {
                getExceptionHandler().handleBlockedListenerException(this, ex);
            }
            return true;
        } else if (method instanceof AMQP.Connection.Unblocked) {
            try {
                for (BlockedListener l : this.blockedListeners) {
                    l.handleUnblocked();
                }
            } catch (Throwable ex) {
                getExceptionHandler().handleBlockedListenerException(this, ex);
            }
            return true;
        } else {
            return false;
        }
    } else {
        if (method instanceof AMQP.Connection.Close) {
            // Already shutting down, so just send back a CloseOk.
            try {
                _channel0.quiescingTransmit(new AMQP.Connection.CloseOk.Builder().build());
            } catch (IOException _e) {
            } // ignore
            return true;
        } else if (method instanceof AMQP.Connection.CloseOk) {
            // It's our final "RPC". Time to shut down.
            _running = false;
            // If Close was sent from within the MainLoop we
            // will not have a continuation to return to, so
            // we treat this as processed in that case.
            return !_channel0.isOutstandingRpc();
        } else { // Ignore all others.
            return true;
        }
    }
}

From source file:de.htwk_leipzig.bis.connection.handshake.clientRewrite.Copyright.java

License:Mozilla Public License

@SuppressWarnings("unused")
public void handleConnectionClose(Command closeCommand) {
    ShutdownSignalException sse = shutdown(closeCommand.getMethod(), false, null, _inConnectionNegotiation);
    try {//from  w w w .  ja  v a2s  .  c  o  m
        _channel0.quiescingTransmit(new AMQP.Connection.CloseOk.Builder().build());
    } catch (IOException _e) {
    } // ignore
    _brokerInitiatedShutdown = true;
    SocketCloseWait scw = new SocketCloseWait(sse);
    final String name = "AMQP Connection Closing Monitor " + getHostAddress() + ":" + getPort();
    Thread waiter = Environment.newThread(threadFactory, scw, name);
    waiter.start();
}

From source file:org.teksme.server.common.messaging.AMQPBrokerManager.java

License:Apache License

public void shutdownCompleted(ShutdownSignalException sse) {

    Connection conn = (Connection) sse.getReference();
    Command closeCommand = (Command) sse.getReason();
    if (sse.isHardError()) {
        if (!sse.isInitiatedByApplication()) {
            AMQP.Connection.Close closeMethod = (AMQP.Connection.Close) closeCommand.getMethod();
            logger.log(Level.SEVERE, "Connection host [" + conn.getHost() + "] closed. Shutdown reason: "
                    + closeMethod.getReplyCode());
        }/* w  ww .  j ava 2  s  . c o m*/
    } else {
        Channel ch = (Channel) sse.getReference();
        logger.info("Connection host [" + conn.getHost() + "] closed. Shutdown reason: " + ch.getCloseReason());
    }

    logger.info("RabbitMQ AMQP broker shutdown completed!");

}