Example usage for com.rabbitmq.client ShutdownSignalException isInitiatedByApplication

List of usage examples for com.rabbitmq.client ShutdownSignalException isInitiatedByApplication

Introduction

In this page you can find the example usage for com.rabbitmq.client ShutdownSignalException isInitiatedByApplication.

Prototype

public boolean isInitiatedByApplication() 

Source Link

Usage

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());
        }//from  w ww.  j  a  v  a2 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!");

}

From source file:org.wso2.carbon.event.adapter.rabbitmq.internal.util.RabbitMQInputEventAdapterListener.java

License:Open Source License

/**
 * Initialize the Adapter//from   w w  w.  j a  va  2 s .  c o  m
 */
@Override
public void run() {
    while (!connectionSucceeded) {
        try {
            workerState = STATE_STARTED;
            initListener();
            while (workerState == STATE_STARTED) {
                try {
                    startListener();
                } catch (ShutdownSignalException sse) {
                    if (!sse.isInitiatedByApplication()) {
                        log.error("RabbitMQ Listener of the receiver" + adapterName + "was disconnected", sse);
                        waitForConnection();
                    }
                }
            }
            connectionSucceeded = true;
            if (log.isDebugEnabled()) {
                log.debug("RabbitMQ Connection successful in " + adapterName);
            }
        } finally {
            stopListener(adapterName);
            workerState = STATE_STOPPED;
        }
    }
}

From source file:org.wso2.carbon.extension.analytics.receiver.rabbitmq.internal.util.RabbitMQAdapterListener.java

License:Open Source License

@Override
public void run() {
    while (!connectionSucceeded) {
        try {//w  ww .j av  a 2  s. c om
            workerState = STATE_STARTED;
            initListener();
            while (workerState == STATE_STARTED) {
                try {
                    startListener();
                } catch (ShutdownSignalException sse) {
                    if (!sse.isInitiatedByApplication()) {
                        log.error("RabbitMQ Listener of the receiver" + adapterName + "was disconnected", sse);
                        waitForConnection();
                    }
                }
            }
            connectionSucceeded = true;
            log.debug("RabbitMQ Connection successful in " + adapterName);
        } catch (IOException e) {
            handleException("Error initializing consumer for receiver" + adapterName, e);
        } finally {
            stopListener(adapterName);
            workerState = STATE_STOPPED;
        }
    }
}

From source file:org.wso2.carbon.inbound.endpoint.protocol.rabbitmq.RabbitMQConnectionConsumer.java

License:Open Source License

public void execute() {

    try {//  ww w  .  ja v  a 2  s .co  m
        workerState = STATE_STARTED;
        initConsumer();

        while (workerState == STATE_STARTED) {
            try {
                startConsumer();
            } catch (ShutdownSignalException sse) {
                if (!sse.isInitiatedByApplication()) {
                    log.error("RabbitMQ Listener of the inbound " + inboundName + " was disconnected", sse);
                    waitForConnection();
                }
            } catch (OMException e) {
                log.error("Invalid Message Format while consuming the message", e);
            } catch (IOException e) {
                log.error("RabbitMQ Listener of the inbound " + inboundName + " was disconnected", e);
                waitForConnection();
            }
        }
    } catch (IOException e) {
        handleException("Error initializing consumer for inbound " + inboundName, e);
    } finally {
        closeConnection();
        workerState = STATE_STOPPED;
    }
}

From source file:ss.udapi.sdk.services.RabbitMqConsumer.java

License:Apache License

@Override
public void handleShutdownSignal(String cTag, ShutdownSignalException signal) {

    if (connectShutDownLogged == false) {
        connectShutDownLogged = true; // so we don't end up logging it for
        // each cTag

        String hardError = "";
        String applInit = "";
        String reason = "";

        if (signal.isHardError()) {
            hardError = "connection";
        } else {/*  w w  w  .j a  v a2s . co m*/
            hardError = "channel";
        }

        if (signal.isInitiatedByApplication()) {
            applInit = "application";
        } else {
            applInit = "broker";
        }

        reason = signal.getReason().toString();
        logger.error("Connectivity to MQ has failed.  It was caused by " + applInit + " at the " + hardError
                + " level.  Reason received " + reason);
    }
    String resourceId = CtagResourceMap.getResource(cTag);
    ResourceImpl resource = (ResourceImpl) ResourceWorkerMap.getResourceImpl(resourceId);
    resource.mqDisconnectEvent();
    MQListener.removeMapping(cTag);
}

From source file:uk.trainwatch.rabbitmq.RabbitRPCClient.java

License:Apache License

private byte[] primitiveCall(AMQP.BasicProperties props, byte[] message)
        throws IOException, ShutdownSignalException, TimeoutException {
    checkConsumer();/*from ww  w  . j a  va2s . c o  m*/
    BlockingCell<Object> k = new BlockingCell<>();

    String replyId = RabbitMQ.newCorrelationId();
    props = ((props == null) ? new AMQP.BasicProperties.Builder() : props.builder()).correlationId(replyId)
            .replyTo(replyQueue).build();
    continuationMap.put(replyId, k);

    publish(props, message);

    Object reply = k.uninterruptibleGet(timeout);
    if (reply instanceof ShutdownSignalException) {
        ShutdownSignalException sig = (ShutdownSignalException) reply;
        ShutdownSignalException wrapper = new ShutdownSignalException(sig.isHardError(),
                sig.isInitiatedByApplication(), sig.getReason(), sig.getReference());
        wrapper.initCause(sig);
        throw wrapper;
    } else {
        return (byte[]) reply;
    }
}