Example usage for com.rabbitmq.client ShutdownSignalException getReason

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

Introduction

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

Prototype

public Method getReason() 

Source Link

Usage

From source file:net.lshift.accent.ExceptionUtils.java

License:Apache License

/**
 * Attempts to extract a reply code from the given ShutdownSignalException. If a reply code is available, it is
 * returned - otherwise, the method returns 0.
 * @param s the signal to inspect./*from  www . java 2 s .c om*/
 * @return the reply code if available, or 0.
 */
public static int getReplyCode(ShutdownSignalException s) {
    if (s.getReason() instanceof AMQImpl.Connection.Close) {
        return ((AMQImpl.Connection.Close) s.getReason()).getReplyCode();
    } else {
        return 0;
    }
}

From source file:net.lshift.camdisplay.Main.java

License:Open Source License

public Main(String host, String exch, String nickname, final String mixerSpec) throws IOException {
    frame = new JFrame("RabbitCam: " + host + "/" + exch);
    panel = new JPanel();
    componentMap = new HashMap();

    setupWindowDressing(exch, nickname, frame, panel);
    frame.pack();//  w w  w  . j a va  2 s.co m
    frame.show();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    textInput.requestFocusInWindow();

    ConnectionFactory cf = new ConnectionFactory();
    cf.setHost(host);
    cf.setRequestedHeartbeat(0);
    conn = cf.newConnection();

    ch = conn.createChannel();

    ch.exchangeDeclare(exch, "fanout");

    String queueName = ch.queueDeclare().getQueue();
    ch.queueBind(queueName, exch, "");
    ch.basicConsume(queueName, true, new DefaultConsumer(ch) {
        public void handleShutdownSignal(String consumerTag, ShutdownSignalException s) {
            if (s.getReason() instanceof java.io.EOFException) {
                JOptionPane.showMessageDialog(frame, "AMQP server disconnected.", "Connection closed",
                        JOptionPane.ERROR_MESSAGE);
            } else {
                SwingUtil.complain("Connection closed", null, s);
            }
            System.exit(1);
        }

        public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties,
                byte[] body) throws IOException {
            String routingKey = envelope.getRoutingKey();
            String contentType = properties.getContentType();

            if (contentType.equals("text/plain")) {
                handleText(routingKey, new String(body));
                return;
            }

            CamstreamComponent comp;
            if (!componentMap.containsKey(routingKey)) {
                comp = new CamstreamComponent(mixerSpec);
                addComponent(routingKey, comp);
                frame.pack();
            } else {
                comp = (CamstreamComponent) componentMap.get(routingKey);
            }
            if (comp.handleDelivery(contentType, body)) {
                frame.pack();
            }
        }
    });
}

From source file:org.smartdeveloperhub.curator.connector.FailureAnalyzerTest.java

License:Apache License

@Test
public void testIsExchangeDeclarationRecoverable$noReason(@Mocked final ShutdownSignalException cause)
        throws Exception {
    new Expectations() {
        {/*from   w  w  w  .  j  a va 2  s.c o m*/
            cause.getReason();
            this.result = null;
        }
    };
    assertThat(FailureAnalyzer.isExchangeDeclarationRecoverable(new IOException(cause)), equalTo(false));
}

From source file:org.smartdeveloperhub.curator.connector.FailureAnalyzerTest.java

License:Apache License

@Test
public void testIsExchangeDeclarationRecoverable$invalidReplyCode(@Mocked final ShutdownSignalException cause,
        @Mocked final Close reason) throws Exception {
    new Expectations() {
        {/*from w w  w .j  av a2s.  c  o  m*/
            cause.getReason();
            this.result = reason;
            reason.getReplyCode();
            this.result = 400;
        }
    };
    assertThat(FailureAnalyzer.isExchangeDeclarationRecoverable(new IOException(cause)), equalTo(false));
}

From source file:org.smartdeveloperhub.curator.connector.FailureAnalyzerTest.java

License:Apache License

@Test
public void testIsExchangeDeclarationRecoverable$invalidMethodId(@Mocked final ShutdownSignalException cause,
        @Mocked final Close reason) throws Exception {
    new Expectations() {
        {/*from w ww  .  j ava  2  s  .c  o  m*/
            cause.getReason();
            this.result = reason;
            reason.getReplyCode();
            this.result = 406;
            reason.getMethodId();
            this.result = 4;
        }
    };
    assertThat(FailureAnalyzer.isExchangeDeclarationRecoverable(new IOException(cause)), equalTo(false));
}

From source file:org.smartdeveloperhub.curator.connector.FailureAnalyzerTest.java

License:Apache License

@Test
public void testIsExchangeDeclarationRecoverable$invalidReplyText(@Mocked final ShutdownSignalException cause,
        @Mocked final Close reason) throws Exception {
    new Expectations() {
        {//from  www  . j  av a 2 s. c o m
            cause.getReason();
            this.result = reason;
            reason.getReplyCode();
            this.result = 406;
            reason.getMethodId();
            this.result = 10;
            reason.getReplyText();
            this.result = "ERROR";
        }
    };
    assertThat(FailureAnalyzer.isExchangeDeclarationRecoverable(new IOException(cause)), equalTo(false));
}

From source file:org.smartdeveloperhub.curator.connector.FailureAnalyzerTest.java

License:Apache License

@Test
public void testIsExchangeDeclarationRecoverable$exchangeTypeMismatch(
        @Mocked final ShutdownSignalException cause, @Mocked final Close reason) throws Exception {
    new Expectations() {
        {/*ww  w  . j a va2  s .  co  m*/
            cause.getReason();
            this.result = reason;
            reason.getReplyCode();
            this.result = 406;
            reason.getMethodId();
            this.result = 10;
            reason.getReplyText();
            this.result = "PRECONDITION_FAILED - inequivalent arg 'type' for exchange 'sdh' in vhost '/': received 'topic' but current is 'fanout'";
        }
    };
    assertThat(FailureAnalyzer.isExchangeDeclarationRecoverable(new IOException(cause)), equalTo(false));
}

From source file:org.smartdeveloperhub.curator.connector.FailureAnalyzerTest.java

License:Apache License

@Test
public void testIsExchangeDeclarationRecoverable$durabilityMismatch(@Mocked final ShutdownSignalException cause,
        @Mocked final Close reason) throws Exception {
    new Expectations() {
        {//w  ww.  ja  va  2  s .co  m
            cause.getReason();
            this.result = reason;
            reason.getReplyCode();
            this.result = 406;
            reason.getMethodId();
            this.result = 10;
            reason.getReplyText();
            this.result = "PRECONDITION_FAILED - inequivalent arg 'durable' for exchange 'sdh' in vhost '/': received 'true' but current is 'false'";
        }
    };
    assertThat(FailureAnalyzer.isExchangeDeclarationRecoverable(new IOException(cause)), equalTo(true));
}

From source file:org.smartdeveloperhub.curator.connector.FailureAnalyzerTest.java

License:Apache License

@Test
public void testIsExchangeDeclarationRecoverable$autoDeleteMismatch(@Mocked final ShutdownSignalException cause,
        @Mocked final Close reason) throws Exception {
    new Expectations() {
        {/* ww  w .  j  a va 2 s  .c o  m*/
            cause.getReason();
            this.result = reason;
            reason.getReplyCode();
            this.result = 406;
            reason.getMethodId();
            this.result = 10;
            reason.getReplyText();
            this.result = "PRECONDITION_FAILED - inequivalent arg 'auto_delete' for exchange 'sdh' in vhost '/': received 'true' but current is 'false'";
        }
    };
    assertThat(FailureAnalyzer.isExchangeDeclarationRecoverable(new IOException(cause)), equalTo(true));
}

From source file:org.smartdeveloperhub.curator.connector.FailureAnalyzerTest.java

License:Apache License

@Test
public void testIsExchangeDeclarationRecoverable$internalMismatch(@Mocked final ShutdownSignalException cause,
        @Mocked final Close reason) throws Exception {
    new Expectations() {
        {// w w w. j  a v  a 2s . com
            cause.getReason();
            this.result = reason;
            reason.getReplyCode();
            this.result = 406;
            reason.getMethodId();
            this.result = 10;
            reason.getReplyText();
            this.result = "PRECONDITION_FAILED - inequivalent arg 'internal' for exchange 'sdh' in vhost '/': received 'false' but current is 'true'";
        }
    };
    assertThat(FailureAnalyzer.isExchangeDeclarationRecoverable(new IOException(cause)), equalTo(false));
}