Package org.deltafi.common.queue.jedis
Class JedisKeyedBlockingQueue
java.lang.Object
org.deltafi.common.queue.jedis.JedisKeyedBlockingQueue
A keyed blocking queue based on the Jedis client library for Redis.
-
Constructor Summary
ConstructorsConstructorDescriptionJedisKeyedBlockingQueue(String url, String password, int maxIdle, int maxTotal) Constructs a JedisKeyedBlockingQueue. -
Method Summary
Modifier and TypeMethodDescriptionvoidDrop all queues in key list.voidPuts an object into the queue.voidPuts multiple objects into the queue.voidsetHeartbeat(String key) Publish a heartbeat in the form of a timestamp<T> TTakes an object out of the queue.
-
Constructor Details
-
JedisKeyedBlockingQueue
public JedisKeyedBlockingQueue(String url, String password, int maxIdle, int maxTotal) throws URISyntaxException Constructs a JedisKeyedBlockingQueue.- Parameters:
url- the url of the redis serverpassword- the password for the redis servermaxIdle- the maximum number of idle pooled connections to the redis servermaxTotal- the maximum number of pooled connections to the redis server. This should be set higher than the expected number of keys in the queue.- Throws:
URISyntaxException- if the provided url is not valid
-
-
Method Details
-
put
public void put(String key, Object object) throws com.fasterxml.jackson.core.JsonProcessingException Puts an object into the queue.- Parameters:
key- the key for the objectobject- the object- Throws:
com.fasterxml.jackson.core.JsonProcessingException- if the object cannot be converted to a JSON string
-
drop
Drop all queues in key list.- Parameters:
keys- list of keys
-
put
public void put(List<org.apache.commons.lang3.tuple.Pair<String, Object>> items) throws com.fasterxml.jackson.core.JsonProcessingException, redis.clients.jedis.exceptions.JedisConnectionExceptionPuts multiple objects into the queue.- Parameters:
items- a list of key/object pairss to put into the queue- Throws:
com.fasterxml.jackson.core.JsonProcessingException- if any object in the map cannot be converted to a JSON string. Objects retrieved from objectMap before the exception occurred will be placed in the queue, all others will notredis.clients.jedis.exceptions.JedisConnectionException
-
setHeartbeat
Publish a heartbeat in the form of a timestamp- Parameters:
key- the name of the component publishing the heartbeat
-
take
public <T> T take(String key, Class<T> objectClass) throws com.fasterxml.jackson.core.JsonProcessingException, redis.clients.jedis.exceptions.JedisConnectionException Takes an object out of the queue.This method will block until an object for the provided key is available. When multiple objects are available for the provided key, the earliest one put into the queue is retrieved.
- Type Parameters:
T- the type of the class of the object- Parameters:
key- the key for the objectobjectClass- the class of the object- Returns:
- the object
- Throws:
com.fasterxml.jackson.core.JsonProcessingException- if the JSON string retrieved from the queue cannot be converted to the provided typeredis.clients.jedis.exceptions.JedisConnectionException
-