Search in sources :

Example 1 with GoMessage

use of com.thoughtworks.go.server.messaging.GoMessage in project gocd by gocd.

the class JMSMessageListenerAdapterTest method shouldNotKillTheThreadWhenThereIsAnException.

@Test
public void shouldNotKillTheThreadWhenThereIsAnException() throws Exception {
    MessageConsumer consumer = mock(MessageConsumer.class);
    when(consumer.receive()).thenThrow(new RuntimeException("should swallow me"));
    GoMessageListener mockListener = new GoMessageListener() {

        public void onMessage(GoMessage message) {
            throw new UnsupportedOperationException("not implemented yet");
        }

        @Override
        public String toString() {
            return "test-listener";
        }
    };
    JMSMessageListenerAdapter listenerAdapter = JMSMessageListenerAdapter.startListening(consumer, mockListener, mock(DaemonThreadStatsCollector.class));
    try {
        listenerAdapter.runImpl();
    } catch (Exception e) {
        e.printStackTrace();
        fail("expected no exception get: " + e);
    }
}
Also used : MessageConsumer(javax.jms.MessageConsumer) DaemonThreadStatsCollector(com.thoughtworks.go.server.service.support.DaemonThreadStatsCollector) GoMessageListener(com.thoughtworks.go.server.messaging.GoMessageListener) GoMessage(com.thoughtworks.go.server.messaging.GoMessage) Test(org.junit.Test)

Example 2 with GoMessage

use of com.thoughtworks.go.server.messaging.GoMessage in project gocd by gocd.

the class JMSMessageListenerAdapter method runImpl.

protected boolean runImpl() {
    try {
        Message message = consumer.receive();
        if (message == null) {
            LOG.debug("Message consumer was closed.");
            return true;
        }
        ObjectMessage omessage = (ObjectMessage) message;
        daemonThreadStatsCollector.captureStats(thread.getId());
        listener.onMessage((GoMessage) omessage.getObject());
    } catch (JMSException e) {
        LOG.warn("Error receiving message. Message receiving will continue despite this error.", e);
    } catch (Exception e) {
        LOG.error("Exception thrown in message handling by listener " + listener, e);
    } finally {
        daemonThreadStatsCollector.clearStats(thread.getId());
    }
    return false;
}
Also used : ObjectMessage(javax.jms.ObjectMessage) GoMessage(com.thoughtworks.go.server.messaging.GoMessage) Message(javax.jms.Message) ObjectMessage(javax.jms.ObjectMessage) JMSException(javax.jms.JMSException) JMSException(javax.jms.JMSException)

Aggregations

GoMessage (com.thoughtworks.go.server.messaging.GoMessage)2 GoMessageListener (com.thoughtworks.go.server.messaging.GoMessageListener)1 DaemonThreadStatsCollector (com.thoughtworks.go.server.service.support.DaemonThreadStatsCollector)1 JMSException (javax.jms.JMSException)1 Message (javax.jms.Message)1 MessageConsumer (javax.jms.MessageConsumer)1 ObjectMessage (javax.jms.ObjectMessage)1 Test (org.junit.Test)1