Search in sources :

Example 1 with TimeTracker

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

the class MessageListenerConsumer method stop.

@Override
public void stop() {
    String cT = this.getConsTag();
    logger.trace("consumerTag='{}'", cT);
    TimeTracker tt = new TimeTracker(this.terminationTimeout, TimeUnit.NANOSECONDS);
    try {
        if (!this.completion.isComplete()) {
            logger.debug("consumerTag='{}' basicCancel:", cT);
            this.channel.basicCancel(cT);
            this.completion.waitUntilComplete(tt);
            this.clearConsTag();
        }
    } catch (TimeoutException te) {
        Thread.currentThread().interrupt();
    } catch (ShutdownSignalException sse) {
        // TODO check if basicCancel really necessary in this case.
        if (!sse.isInitiatedByApplication()) {
            logger.error("basicCancel (consumerTag='{}') threw exception", cT, sse);
            throw sse;
        }
    } catch (InterruptedException e) {
        Thread.currentThread().interrupt();
    } catch (IOException e) {
        if (!e.getMessage().equals("Unknown consumerTag")) {
            logger.error("basicCancel (consumerTag='{}') threw unexpected exception", cT, e);
        }
    }
}
Also used : ShutdownSignalException(com.rabbitmq.client.ShutdownSignalException) TimeTracker(com.rabbitmq.jms.util.TimeTracker) IOException(java.io.IOException) TimeoutException(java.util.concurrent.TimeoutException)

Example 2 with TimeTracker

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

the class DelayedReceiver method get.

/**
 * Get a message; if there isn't one, try again at intervals not exceeding the total time available. Aborts if closed while polling.
 * @param tt - keeps track of the time available
 * @return message gotten, or <code>null</code> if timeout or connection closed.
 */
public GetResponse get(TimeTracker tt) {
    try {
        synchronized (this.responseLock) {
            GetResponse resp = this.rmqMessageConsumer.getFromRabbitQueue();
            if (resp != null)
                return resp;
            while (!this.aborted && !tt.timedOut()) {
                resp = this.rmqMessageConsumer.getFromRabbitQueue();
                if (resp != null)
                    break;
                new TimeTracker(POLLING_INTERVAL).timedWait(this.responseLock);
            }
            return resp;
        }
    } catch (InterruptedException e) {
        logger.warn("Get interrupted while buffer.poll-ing.", e);
        Thread.currentThread().interrupt();
        return null;
    }
}
Also used : TimeTracker(com.rabbitmq.jms.util.TimeTracker) GetResponse(com.rabbitmq.client.GetResponse)

Example 3 with TimeTracker

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

the class SqlProductionTest method slow_expression.

@Test
public void slow_expression() throws Exception {
    TimeTracker tt = new TimeTracker(500, TimeUnit.MILLISECONDS);
    assertParse(SqlProduction.expression, "(((-1)))", "PREFIXUNARYOP: -", "    LEAF: integer: 1");
    assertFalse(tt.timedOut(), "Took too long");
}
Also used : TimeTracker(com.rabbitmq.jms.util.TimeTracker) Test(org.junit.jupiter.api.Test)

Example 4 with TimeTracker

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

the class RMQMessageConsumer method pause.

/**
 * Stops this consumer from receiving messages. This is called by the session indirectly when
 * {@link javax.jms.Connection#stop()} is invoked. In this implementation, any async consumers will be cancelled,
 * only to be re-subscribed when <code>resume()</code>d.
 *
 * @throws InterruptedException if the thread is interrupted
 */
void pause() throws Exception {
    this.receiveManager.closeGate();
    this.receiveManager.waitToClear(new TimeTracker(STOP_TIMEOUT_MS, TimeUnit.MILLISECONDS));
    this.abortables.stop();
}
Also used : TimeTracker(com.rabbitmq.jms.util.TimeTracker)

Aggregations

TimeTracker (com.rabbitmq.jms.util.TimeTracker)4 GetResponse (com.rabbitmq.client.GetResponse)1 ShutdownSignalException (com.rabbitmq.client.ShutdownSignalException)1 IOException (java.io.IOException)1 TimeoutException (java.util.concurrent.TimeoutException)1 Test (org.junit.jupiter.api.Test)1