Package com.github.ddth.queue.impl
Class RedisQueue<ID,DATA>
- java.lang.Object
-
- com.github.ddth.queue.impl.AbstractQueue<ID,DATA>
-
- com.github.ddth.queue.impl.AbstractEphemeralSupportQueue<ID,DATA>
-
- com.github.ddth.queue.impl.BaseRedisQueue<ID,DATA>
-
- com.github.ddth.queue.impl.RedisQueue<ID,DATA>
-
- All Implemented Interfaces:
IQueue<ID,DATA>,AutoCloseable
- Direct Known Subclasses:
BaseUniversalRedisQueue
public abstract class RedisQueue<ID,DATA> extends BaseRedisQueue<ID,DATA>
Redis implementation ofIQueue.Implementation:
- A hash to store message, format {queue_id => message}. See
BaseRedisQueue.setRedisHashName(String). - A list to act as a queue of message's queue_id. See
BaseRedisQueue.setRedisListName(String). - A sorted set to act as ephemeral storage of message's queue_id, score is
message's timestamp. See
BaseRedisQueue.setRedisSortedSetName(String).
Features:
- Queue-size support: yes
- Ephemeral storage support: yes
- Ephemeral-size support: yes
- Since:
- 0.3.1
- Author:
- Thanh Ba Nguyen
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class com.github.ddth.queue.impl.AbstractQueue
AbstractQueue.PutToQueueCase
-
-
Field Summary
Fields Modifier and Type Field Description static StringDEFAULT_HOST_AND_PORT-
Fields inherited from class com.github.ddth.queue.impl.BaseRedisQueue
DEFAULT_HASH_NAME, DEFAULT_LIST_NAME, DEFAULT_PASSWORD, DEFAULT_SORTED_SET_NAME, myOwnRedis
-
Fields inherited from interface com.github.ddth.queue.IQueue
SIZE_NOT_SUPPORTED
-
-
Constructor Summary
Constructors Constructor Description RedisQueue()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected com.github.ddth.commons.redis.JedisConnectorbuildJedisConnector()Build aJedisConnectorinstance for my own use.protected voidcloseJedisCommands(redis.clients.jedis.BinaryJedisCommands jedisCommands)Close the unusedBinaryJedisCommands.protected redis.clients.jedis.BinaryJedisCommandsgetBinaryJedisCommands()GetBinaryJedisCommandsinstance.StringgetRedisHostAndPort()Redis host and port scheme (formathost:port).protected booleanremove(IQueueMessage<ID,DATA> msg)Remove a message completely.RedisQueue<ID,DATA>setRedisHostAndPort(String redisHostAndPort)Redis host and port scheme (formathost:port).protected booleanstoreNew(IQueueMessage<ID,DATA> msg)Store a new message.protected booleanstoreOld(IQueueMessage<ID,DATA> msg)Re-store an old message (called byAbstractQueue.requeue(IQueueMessage)orAbstractQueue.requeueSilent(IQueueMessage).IQueueMessage<ID,DATA>take()Take a message out of queue.-
Methods inherited from class com.github.ddth.queue.impl.BaseRedisQueue
destroy, doPutToQueue, ephemeralSize, finish, getJedisConnector, getOrphanMessages, getRedisHashName, getRedisHashNameAsBytes, getRedisListName, getRedisListNameAsBytes, getRedisPassword, getRedisSortedSetName, getRedisSortedSetNameAsBytes, getScriptTake, getScriptTakeAsBytes, init, queueSize, setJedisConnector, setJedisConnector, setRedisHashName, setRedisListName, setRedisPassword, setRedisSortedSetName, setScriptTake
-
Methods inherited from class com.github.ddth.queue.impl.AbstractEphemeralSupportQueue
getEphemeralDisabled, getEphemeralMaxSize, isEphemeralDisabled, setEphemeralDisabled, setEphemeralMaxSize
-
Methods inherited from class com.github.ddth.queue.impl.AbstractQueue
close, createMessage, createMessage, createMessage, deserialize, deserialize, getMessageFactory, getQueueName, getSerDeser, queue, requeue, requeueSilent, serialize, setMessageFactory, setQueueName, setSerDeser
-
-
-
-
Field Detail
-
DEFAULT_HOST_AND_PORT
public static final String DEFAULT_HOST_AND_PORT
- See Also:
- Constant Field Values
-
-
Method Detail
-
getRedisHostAndPort
public String getRedisHostAndPort()
Redis host and port scheme (formathost:port).- Returns:
-
setRedisHostAndPort
public RedisQueue<ID,DATA> setRedisHostAndPort(String redisHostAndPort)
Redis host and port scheme (formathost:port).- Parameters:
redisHostAndPort-- Returns:
-
buildJedisConnector
protected com.github.ddth.commons.redis.JedisConnector buildJedisConnector()
Build aJedisConnectorinstance for my own use.- Specified by:
buildJedisConnectorin classBaseRedisQueue<ID,DATA>- Returns:
-
getBinaryJedisCommands
protected redis.clients.jedis.BinaryJedisCommands getBinaryJedisCommands()
GetBinaryJedisCommandsinstance.- Specified by:
getBinaryJedisCommandsin classBaseRedisQueue<ID,DATA>- Returns:
-
closeJedisCommands
protected void closeJedisCommands(redis.clients.jedis.BinaryJedisCommands jedisCommands)
Close the unusedBinaryJedisCommands.- Specified by:
closeJedisCommandsin classBaseRedisQueue<ID,DATA>
-
remove
protected boolean remove(IQueueMessage<ID,DATA> msg)
Remove a message completely.Implementation note:
- Message should no longer exist after method call regardless of return value (
trueorfalse) - In case of error, throws
QueueException
- Specified by:
removein classBaseRedisQueue<ID,DATA>- Returns:
trueif the message has been removed,falsemeans the message does not exist for completely removal
- Message should no longer exist after method call regardless of return value (
-
storeNew
protected boolean storeNew(IQueueMessage<ID,DATA> msg)
Store a new message.Implementation note:
- Message's ID must be successfully pushed into the "queue-list" so that the method call is considered successful.
If message's id has not pushed to the "queue-list", this method must return
false. - Caller can retry if method returns
false. Implementation's responsibility to ensure message is not duplicated in storage. - In case of error, throws
QueueException
- Specified by:
storeNewin classBaseRedisQueue<ID,DATA>- Returns:
- Message's ID must be successfully pushed into the "queue-list" so that the method call is considered successful.
If message's id has not pushed to the "queue-list", this method must return
-
storeOld
protected boolean storeOld(IQueueMessage<ID,DATA> msg)
Re-store an old message (called byAbstractQueue.requeue(IQueueMessage)orAbstractQueue.requeueSilent(IQueueMessage).Implementation note:
- Message's ID must be successfully pushed into the "queue-list" so that the method call is considered successful.
If message's id has not pushed to the "queue-list", this method must return
false. - Caller can retry if method returns
false. Implementation's responsibility to ensure message is not duplicated in storage. - In case of error, throws
QueueException
- Specified by:
storeOldin classBaseRedisQueue<ID,DATA>- Returns:
- Message's ID must be successfully pushed into the "queue-list" so that the method call is considered successful.
If message's id has not pushed to the "queue-list", this method must return
-
take
public IQueueMessage<ID,DATA> take() throws QueueException.EphemeralIsFull
Take a message out of queue.Implementation flow:
- Read message from head of queue storage.
- Write message to ephemeral storage.
- Remove message from queue storage.
Note: ephemeral storage implementation is optional, depends on implementation.
- Returns:
- Throws:
QueueException.EphemeralIsFull- if the ephemeral storage is full
-
-