
artoria.message.delay.support.RedissonDelayMessageHandler Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of artoria-extend Show documentation
Show all versions of artoria-extend Show documentation
Artoria is a java technology framework based on the facade pattern.
The newest version!
package artoria.message.delay.support;
import artoria.data.tuple.Pair;
import artoria.exception.ExceptionUtils;
import artoria.message.MessageListener;
import artoria.message.delay.DelayMessage;
import artoria.message.handler.AbstractClassicMessageHandler;
import artoria.time.DateUtils;
import artoria.util.Assert;
import artoria.util.ThreadUtils;
import org.redisson.api.RBlockingDeque;
import org.redisson.api.RDelayedQueue;
import org.redisson.api.RedissonClient;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.lang.reflect.Type;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.RejectedExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.function.Consumer;
/**
* The redisson delay message handler.
* @author Kahle
*/
public class RedissonDelayMessageHandler extends AbstractClassicMessageHandler {
protected static Logger log = LoggerFactory.getLogger(RedissonDelayMessageHandler.class);
protected static final Long DEFAULT_SLEEP_TIME = 500L;
protected final Boolean ignoreException;
protected final Long sleepTimeWhenRejected;
protected Map delayedQueues;
protected ExecutorService executorService;
protected RedissonClient redissonClient;
public RedissonDelayMessageHandler(RedissonClient redissonClient,
ExecutorService executorService) {
this(redissonClient, executorService, null, null);
}
public RedissonDelayMessageHandler(RedissonClient redissonClient,
ExecutorService executorService,
Long sleepTimeWhenRejected,
Boolean ignoreException) {
this(redissonClient, executorService, sleepTimeWhenRejected
, ignoreException, new ConcurrentHashMap());
}
protected RedissonDelayMessageHandler(RedissonClient redissonClient,
ExecutorService executorService,
Long sleepTimeWhenRejected,
Boolean ignoreException,
Map delayedQueues) {
Assert.notNull(executorService, "Parameter \"executorService\" must not null. ");
Assert.notNull(redissonClient, "Parameter \"redissonClient\" must not null. ");
Assert.notNull(delayedQueues, "Parameter \"delayedQueues\" must not null. ");
if (ignoreException == null) { ignoreException = false; }
if (sleepTimeWhenRejected == null) { sleepTimeWhenRejected = DEFAULT_SLEEP_TIME; }
sleepTimeWhenRejected = sleepTimeWhenRejected > 4000 ? 4000 : sleepTimeWhenRejected;
sleepTimeWhenRejected = sleepTimeWhenRejected < 100 ? 100 : sleepTimeWhenRejected;
this.sleepTimeWhenRejected = sleepTimeWhenRejected;
this.ignoreException = ignoreException;
this.executorService = executorService;
this.redissonClient = redissonClient;
this.delayedQueues = delayedQueues;
}
protected QueuePair getQueuePair(String topic) {
Assert.notBlank(topic, "Parameter \"topic\" must not blank. ");
QueuePair pair = delayedQueues.get(topic);
if (pair != null) { return pair; }
synchronized (topic.intern()) {
if ((pair = delayedQueues.get(topic)) != null) { return pair; }
RBlockingDeque
© 2015 - 2025 Weber Informatics LLC | Privacy Policy