Search in sources :

Example 1 with StaleSequenceException

use of com.hazelcast.ringbuffer.StaleSequenceException in project hazelcast by hazelcast.

the class ReliableMessageListenerRunner method onFailure.

// This method is called from the provided executor.
@Override
public void onFailure(Throwable t) {
    if (cancelled) {
        return;
    }
    if (t instanceof StaleSequenceException) {
        StaleSequenceException staleSequenceException = (StaleSequenceException) t;
        if (listener.isLossTolerant()) {
            if (logger.isFinestEnabled()) {
                logger.finest("MessageListener " + listener + " on topic: " + topicName + " ran into a stale sequence. " + "Jumping from oldSequence: " + sequence + " to sequence: " + staleSequenceException.getHeadSeq());
            }
            sequence = staleSequenceException.getHeadSeq();
            next();
            return;
        }
        logger.warning("Terminating MessageListener:" + listener + " on topic: " + topicName + ". " + "Reason: The listener was too slow or the retention period of the message has been violated. " + "head: " + staleSequenceException.getHeadSeq() + " sequence:" + sequence);
    } else if (t instanceof HazelcastInstanceNotActiveException) {
        if (logger.isFinestEnabled()) {
            logger.finest("Terminating MessageListener " + listener + " on topic: " + topicName + ". " + " Reason: HazelcastInstance is shutting down");
        }
    } else if (t instanceof DistributedObjectDestroyedException) {
        if (logger.isFinestEnabled()) {
            logger.finest("Terminating MessageListener " + listener + " on topic: " + topicName + ". " + "Reason: Topic is destroyed");
        }
    } else {
        logger.warning("Terminating MessageListener " + listener + " on topic: " + topicName + ". " + "Reason: Unhandled exception, message: " + t.getMessage(), t);
    }
    cancel();
}
Also used : HazelcastInstanceNotActiveException(com.hazelcast.core.HazelcastInstanceNotActiveException) DistributedObjectDestroyedException(com.hazelcast.spi.exception.DistributedObjectDestroyedException) StaleSequenceException(com.hazelcast.ringbuffer.StaleSequenceException)

Example 2 with StaleSequenceException

use of com.hazelcast.ringbuffer.StaleSequenceException in project hazelcast by hazelcast.

the class RingbufferAbstractTest method readOne_whenBeforeHead_thenStaleSequenceException.

@Test
public void readOne_whenBeforeHead_thenStaleSequenceException() throws Exception {
    RingbufferConfig ringbufferConfig = config.getRingbufferConfig(ringbuffer.getName());
    for (int k = 0; k < ringbufferConfig.getCapacity() * 2; k++) {
        ringbuffer.add("foo");
    }
    long headSeq = ringbuffer.headSequence();
    try {
        ringbuffer.readOne(headSeq - 1);
        fail();
    } catch (StaleSequenceException expected) {
        assertEquals(headSeq, expected.getHeadSeq());
    }
}
Also used : StaleSequenceException(com.hazelcast.ringbuffer.StaleSequenceException) RingbufferConfig(com.hazelcast.config.RingbufferConfig) Test(org.junit.Test)

Aggregations

StaleSequenceException (com.hazelcast.ringbuffer.StaleSequenceException)2 RingbufferConfig (com.hazelcast.config.RingbufferConfig)1 HazelcastInstanceNotActiveException (com.hazelcast.core.HazelcastInstanceNotActiveException)1 DistributedObjectDestroyedException (com.hazelcast.spi.exception.DistributedObjectDestroyedException)1 Test (org.junit.Test)1