Search in sources :

Example 1 with AbortedException

use of com.rabbitmq.jms.util.AbortedException in project rabbitmq-jms-client by rabbitmq.

the class RMQMessageConsumer method receive.

private RMQMessage receive(TimeTracker tt) throws JMSException {
    /* Pseudocode:
     *  get (synchronous read)
     *  if something return it;
     *  if nothing, then poll (intervals up to time limit given)
     *  if still nothing return nothing.
     */
    if (!this.session.syncAllowed()) {
        throw new IllegalStateException("A session may not receive() when a MessageListener is set. (See JMS 1.1 ยง4.4.6.)");
    }
    this.numberOfReceives.incrementAndGet();
    try {
        if (// stopped?
        !this.receiveManager.enter(tt))
            // timed out while stopped
            return null;
        /* Try to receive a message, there's some time left! */
        try {
            GetResponse resp = this.delayedReceiver.get(tt);
            // nothing received in time or aborted
            if (resp == null)
                return null;
            this.dealWithAcknowledgements(this.isAutoAck(), resp.getEnvelope().getDeliveryTag());
            return RMQMessage.convertMessage(this.session, this.destination, resp);
        } finally {
            this.receiveManager.exit();
        }
    } catch (AbortedException e) {
        /* If we were aborted (closed) we return null, too. */
        return null;
    } catch (InterruptedException e) {
        /* Someone interrupted us -- we ought to terminate */
        // reset interrupt status
        Thread.currentThread().interrupt();
        return null;
    } finally {
        this.numberOfReceives.decrementAndGet();
    }
}
Also used : IllegalStateException(javax.jms.IllegalStateException) AbortedException(com.rabbitmq.jms.util.AbortedException) GetResponse(com.rabbitmq.client.GetResponse)

Aggregations

GetResponse (com.rabbitmq.client.GetResponse)1 AbortedException (com.rabbitmq.jms.util.AbortedException)1 IllegalStateException (javax.jms.IllegalStateException)1