Class BaseRedisQueue<ID,​DATA>

    • Field Detail

      • DEFAULT_PASSWORD

        public static final String DEFAULT_PASSWORD
      • myOwnRedis

        protected boolean myOwnRedis
        Flag to mark if the Redis resource (e.g. Redis client pool) is created and handled by the lock instance.
    • Constructor Detail

      • BaseRedisQueue

        public BaseRedisQueue()
    • Method Detail

      • getJedisConnector

        public com.github.ddth.commons.redis.JedisConnector getJedisConnector()
        Get the current JedisConnector used by this queue.
        Returns:
      • setJedisConnector

        protected BaseRedisQueue<ID,​DATA> setJedisConnector​(com.github.ddth.commons.redis.JedisConnector jedisConnector,
                                                                  boolean setMyOwnRedis)
        Setter for jedisConnector.
        Parameters:
        jedisConnector -
        setMyOwnRedis -
        Returns:
        Since:
        0.7.1
      • setJedisConnector

        public BaseRedisQueue<ID,​DATA> setJedisConnector​(com.github.ddth.commons.redis.JedisConnector jedisConnector)
        Set the external JedisConnector to be used by this queue.
        Parameters:
        jedisConnector -
        Returns:
      • getRedisPassword

        public String getRedisPassword()
        Redis' password.
        Returns:
      • setRedisPassword

        public BaseRedisQueue<ID,​DATA> setRedisPassword​(String redisPassword)
        Redis' password.
        Parameters:
        redisPassword -
        Returns:
      • getRedisHashName

        public String getRedisHashName()
        Name of the Redis hash to store queue messages.
        Returns:
      • getRedisHashNameAsBytes

        public byte[] getRedisHashNameAsBytes()
        Name of the Redis hash to store queue messages.
        Returns:
      • setRedisHashName

        public BaseRedisQueue<ID,​DATA> setRedisHashName​(String redisHashName)
        Name of the Redis hash to store queue messages.
        Parameters:
        redisHashName -
        Returns:
      • getRedisListName

        public String getRedisListName()
        Name of the Redis list to store queue message ids.
        Returns:
      • getRedisListNameAsBytes

        public byte[] getRedisListNameAsBytes()
        Name of the Redis list to store queue message ids.
        Returns:
      • setRedisListName

        public BaseRedisQueue<ID,​DATA> setRedisListName​(String redisListName)
        Name of the Redis list to store queue message ids.
        Parameters:
        redisListName -
        Returns:
      • getRedisSortedSetName

        public String getRedisSortedSetName()
        Name of the Redis sorted-set to store ephemeral message ids.
        Returns:
      • getRedisSortedSetNameAsBytes

        public byte[] getRedisSortedSetNameAsBytes()
        Name of the Redis sorted-set to store ephemeral message ids.
        Returns:
      • setRedisSortedSetName

        public BaseRedisQueue<ID,​DATA> setRedisSortedSetName​(String redisSortedSetName)
        Name of the Redis sorted-set to store ephemeral message ids.
        Parameters:
        redisSortedSetName -
        Returns:
      • getScriptTake

        public String getScriptTake()
        LUA script to take a message out of queue.
        Returns:
      • getScriptTakeAsBytes

        protected byte[] getScriptTakeAsBytes()
        LUA script to take a message out of queue.
        Returns:
        Since:
        1.0.0
      • setScriptTake

        public BaseRedisQueue<ID,​DATA> setScriptTake​(String scriptTake)
        LUA script to take a message out of queue.

        Normally queue implementations will build this script; no need to "set" it from outside.

        Parameters:
        scriptTake -
        Returns:
      • buildJedisConnector

        protected abstract com.github.ddth.commons.redis.JedisConnector buildJedisConnector()
        Build a JedisConnector instance for my own use.
        Returns:
        Since:
        0.6.2.6
      • getBinaryJedisCommands

        protected abstract redis.clients.jedis.BinaryJedisCommands getBinaryJedisCommands()
        Get BinaryJedisCommands instance.
        Returns:
        Since:
        0.6.2.6
      • closeJedisCommands

        protected abstract void closeJedisCommands​(redis.clients.jedis.BinaryJedisCommands jedisCommands)
        Close the unused BinaryJedisCommands.
        Parameters:
        jedisCommands -
        Since:
        0.6.2.6
      • remove

        protected abstract boolean remove​(IQueueMessage<ID,​DATA> msg)
                                   throws QueueException
        Remove a message completely.

        Implementation note:

        • Message should no longer exist after method call regardless of return value (true or false)
        • In case of error, throws QueueException
        Parameters:
        msg -
        Returns:
        true if the message has been removed, false means the message does not exist for completely removal
        Throws:
        QueueException - if error (e.g. IOException while communicating with Redis server)
      • storeNew

        protected abstract 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
        Parameters:
        msg -
        Returns:
      • storeOld

        protected abstract boolean storeOld​(IQueueMessage<ID,​DATA> msg)
        Re-store an old message (called by AbstractQueue.requeue(IQueueMessage) or AbstractQueue.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
        Parameters:
        msg -
        Returns:
      • finish

        public void finish​(IQueueMessage<ID,​DATA> msg)
        Called when finish processing the message to cleanup ephemeral storage.

        Implementation flow:

        • Remove message from ephemeral storage.

        Note: ephemeral storage implementation is optional, depends on implementation.

      • getOrphanMessages

        public Collection<IQueueMessage<ID,​DATA>> getOrphanMessages​(long thresholdTimestampMs)
        Get all orphan messages (messages that were left in ephemeral storage for a long time).
        Parameters:
        thresholdTimestampMs - message is orphan if message's timestampMillis + thresholdTimestampMs < now . Which means getOrphanMessages(10000) will return orphan messages that have stayed in ephemeral storage for more than 10000 milliseconds.
        Returns:
        null or empty collection if there is no orphan message
      • queueSize

        public int queueSize()
        Get number of items currently in queue storage.
        Returns:
        negative number if queue size can not be queried
      • ephemeralSize

        public int ephemeralSize()
        Get number of items currently in ephemeral storage.

        Note: ephemeral storage implementation is optional, depends on implementation.

        Returns:
        negative number if ephemeral size can not be queried