Class BaseLessLockingUniversalJdbcQueue<T extends BaseUniversalQueueMessage<ID>,​ID>

    • Field Detail

      • COL_EPHEMERAL_ID

        public static final String COL_EPHEMERAL_ID
        Table's column name to store ephemeral id
        See Also:
        Constant Field Values
      • COL_ORG_TIMESTAMP

        public static final String COL_ORG_TIMESTAMP
        Table's column name to store message's original timestamp
        See Also:
        Constant Field Values
      • COL_TIMESTAMP

        public static final String COL_TIMESTAMP
        Table's column name to store message's timestamp
        See Also:
        Constant Field Values
      • COL_NUM_REQUEUES

        public static final String COL_NUM_REQUEUES
        Table's column name to store message's number of requeues
        See Also:
        Constant Field Values
    • Constructor Detail

      • BaseLessLockingUniversalJdbcQueue

        public BaseLessLockingUniversalJdbcQueue()
    • Method Detail

      • getTableNameEphemeral

        public String getTableNameEphemeral()
        Name of database table to store ephemeral messages.
        Overrides:
        getTableNameEphemeral in class JdbcQueue<ID,​byte[]>
        Returns:
      • queueSize

        protected int queueSize​(Connection conn)
        Get number of items currently in queue storage.
        Overrides:
        queueSize in class JdbcQueue<ID,​byte[]>
        Returns:
      • ephemeralSize

        protected int ephemeralSize​(Connection conn)
        Get number of items currently in ephemeral storage.
        Overrides:
        ephemeralSize in class JdbcQueue<ID,​byte[]>
        Returns:
      • peekFromQueueStorage

        protected T peekFromQueueStorage​(Connection conn)
        Primitive operation: Read (but not removed) message from head of queue storage.
        Specified by:
        peekFromQueueStorage in class JdbcQueue<ID,​byte[]>
        Returns:
      • readFromEphemeralStorage

        protected T readFromEphemeralStorage​(Connection conn,
                                             ID id)
        Primitive operation: Read (but not removed) a message from the ephemeral storage.
        Specified by:
        readFromEphemeralStorage in class JdbcQueue<ID,​byte[]>
        Returns:
      • getOrphanMessagesFromEphemeralStorage

        protected Collection<T> getOrphanMessagesFromEphemeralStorage​(Connection conn,
                                                                      long thresholdTimestampMs)
        Primitive operation: Get all orphan messages (messages that were left in ephemeral storage for a long time).
        Specified by:
        getOrphanMessagesFromEphemeralStorage in class JdbcQueue<ID,​byte[]>
        thresholdTimestampMs - get all orphan messages that were queued before this timestamp
        Returns:
      • _finishWithRetries

        protected void _finishWithRetries​(Connection conn,
                                          IQueueMessage<ID,​byte[]> msg,
                                          int numRetries,
                                          int maxRetries)
        Perform "finish" action, retry if deadlock.

        Note: http://dev.mysql.com/doc/refman/5.0/en/innodb-deadlocks.html

        InnoDB uses automatic row-level locking. You can get deadlocks even in the case of transactions that just insert or delete a single row. That is because these operations are not really "atomic"; they automatically set locks on the (possibly several) index records of the row inserted or deleted.

        Note: the supplied queue message is mutable.

        Implementation: remove message completely from storage.

        Overrides:
        _finishWithRetries in class JdbcQueue<ID,​byte[]>
      • _requeueWithRetries

        protected boolean _requeueWithRetries​(Connection conn,
                                              IQueueMessage<ID,​byte[]> msg,
                                              int numRetries,
                                              int maxRetries)
        Re-queue a message, retry if deadlock.

        Note: http://dev.mysql.com/doc/refman/5.0/en/innodb-deadlocks.html

        InnoDB uses automatic row-level locking. You can get deadlocks even in the case of transactions that just insert or delete a single row. That is because these operations are not really "atomic"; they automatically set locks on the (possibly several) index records of the row inserted or deleted.

        Implementation:

        Overrides:
        _requeueWithRetries in class JdbcQueue<ID,​byte[]>
        Returns:
      • _requeueSilentWithRetries

        protected boolean _requeueSilentWithRetries​(Connection conn,
                                                    IQueueMessage<ID,​byte[]> msg,
                                                    int numRetries,
                                                    int maxRetries)
        Re-queue (silentlt) a message, retry if deadlock.

        Note: http://dev.mysql.com/doc/refman/5.0/en/innodb-deadlocks.html

        InnoDB uses automatic row-level locking. You can get deadlocks even in the case of transactions that just insert or delete a single row. That is because these operations are not really "atomic"; they automatically set locks on the (possibly several) index records of the row inserted or deleted.

        Implementation:

        Overrides:
        _requeueSilentWithRetries in class JdbcQueue<ID,​byte[]>
        Returns:
      • _takeWithRetries

        protected T _takeWithRetries​(Connection conn,
                                     int numRetries,
                                     int maxRetries)
        Take a message from queue, retry if deadlock.

        Note: http://dev.mysql.com/doc/refman/5.0/en/innodb-deadlocks.html

        InnoDB uses automatic row-level locking. You can get deadlocks even in the case of transactions that just insert or delete a single row. That is because these operations are not really "atomic"; they automatically set locks on the (possibly several) index records of the row inserted or deleted.

        Implementation:

        • Get the first available queue message.
        • Generate a unique-id and assign to the message's COL_EPHEMERAL_ID.
        • Return the message object.
        Overrides:
        _takeWithRetries in class JdbcQueue<ID,​byte[]>
        Returns: