public abstract class JdbcQueue extends com.github.ddth.dao.jdbc.BaseJdbcDao implements IQueue
IQueue.
Implementation:
| Modifier and Type | Field and Description |
|---|---|
static int |
DEFAULT_MAX_RETRIES |
| Constructor and Description |
|---|
JdbcQueue() |
| Modifier and Type | Method and Description |
|---|---|
protected void |
_finishWithRetries(Connection conn,
IQueueMessage msg,
int numRetries,
int maxRetries)
Performs "finish" action, retry if deadlock.
|
protected Collection<IQueueMessage> |
_getOrphanMessagesWithRetries(long thresholdTimestampMs,
Connection conn,
int numRetries,
int maxRetries)
Gets all orphan messages (messages that were left in ephemeral storage
for a long time), retry if deadlock.
|
protected boolean |
_moveFromEphemeralToQueueStorageWithRetries(IQueueMessage msg,
Connection conn,
int numRetries,
int maxRetries)
Moves a message from ephemeral back to queue storage, retry if deadlock.
|
protected boolean |
_queueWithRetries(Connection conn,
IQueueMessage msg,
int numRetries,
int maxRetries)
Queues a message, retry if deadlock.
|
protected boolean |
_requeueSilentWithRetries(Connection conn,
IQueueMessage msg,
int numRetries,
int maxRetries)
Re-queues a message silently, retry if deadlock.
|
protected boolean |
_requeueWithRetries(Connection conn,
IQueueMessage msg,
int numRetries,
int maxRetries)
Re-queues a message, retry if deadlock.
|
protected IQueueMessage |
_takeWithRetries(Connection conn,
int numRetries,
int maxRetries)
Takes a message from queue, retry if deadlock.
|
void |
destroy() |
int |
ephemeralSize()
Gets ephemeral-storage's number of items.
|
void |
finish(IQueueMessage msg)
Called when finish processing the message to cleanup ephemeral storage.
|
int |
getMaxRetries() |
protected abstract Collection<IQueueMessage> |
getOrphanFromEphemeralStorage(org.springframework.jdbc.core.JdbcTemplate jdbcTemplate,
long thresholdTimestampMs)
Gets all orphan messages (messages that were left in ephemeral storage
for a long time).
|
Collection<IQueueMessage> |
getOrphanMessages(long thresholdTimestampMs)
Gets all orphan messages (messages that were left in ephemeral storage
for a long time).
|
String |
getTableName() |
String |
getTableNameEphemeral() |
int |
getTransactionIsolationLevel() |
JdbcQueue |
init() |
boolean |
moveFromEphemeralToQueueStorage(IQueueMessage msg)
Moves a message from ephemeral back to queue storage.
|
protected abstract boolean |
putToEphemeralStorage(org.springframework.jdbc.core.JdbcTemplate jdbcTemplate,
IQueueMessage msg)
Puts a message to the ephemeral storage.
|
protected abstract boolean |
putToQueueStorage(org.springframework.jdbc.core.JdbcTemplate jdbcTemplate,
IQueueMessage msg)
Puts a message to tail of the queue storage.
|
boolean |
queue(IQueueMessage msg)
Queues a message.
|
int |
queueSize()
Gets queue's number of items.
|
protected abstract IQueueMessage |
readFromEphemeralStorage(org.springframework.jdbc.core.JdbcTemplate jdbcTemplate,
IQueueMessage msg)
Reads a message from the ephemeral storage.
|
protected abstract IQueueMessage |
readFromQueueStorage(org.springframework.jdbc.core.JdbcTemplate jdbcTemplate)
Reads a message from head of queue storage.
|
protected abstract boolean |
removeFromEphemeralStorage(org.springframework.jdbc.core.JdbcTemplate jdbcTemplate,
IQueueMessage msg)
Removes a message from the ephemeral storage.
|
protected abstract boolean |
removeFromQueueStorage(org.springframework.jdbc.core.JdbcTemplate jdbcTemplate,
IQueueMessage msg)
Removes a message from the queue storage.
|
boolean |
requeue(IQueueMessage msg)
Re-queues a message.
|
boolean |
requeueSilent(IQueueMessage msg)
Silently re-queues a message.
|
JdbcQueue |
setMaxRetries(int maxRetries) |
JdbcQueue |
setTableName(String tableName) |
JdbcQueue |
setTableNameEphemeral(String tableNameEphemeral) |
JdbcQueue |
setTransactionIsolationLevel(int transactionIsolationLevel) |
IQueueMessage |
take()
Takes a message out of queue.
|
commitTransaction, connection, connection, execute, execute, execute, executeSelect, executeSelect, executeSelect, executeSelect, executeSelect, executeSelect, getDataSource, jdbcTemplate, jdbcTemplate, returnConnection, rollbackTransaction, setDataSource, startTransactionaddProfiling, clearProfiling, getCache, getCacheFactory, getFromCache, getFromCache, getProfiling, isCacheEnabled, isCacheItemsExpireAfterWrite, putToCache, putToCache, putToCache, removeFromCache, setCacheFactory, setCacheItemsExpireAfterWrite, startProfilingpublic String getTableName()
public String getTableNameEphemeral()
public JdbcQueue setTransactionIsolationLevel(int transactionIsolationLevel)
public int getTransactionIsolationLevel()
public JdbcQueue setMaxRetries(int maxRetries)
public int getMaxRetries()
public JdbcQueue init()
init in class com.github.ddth.dao.jdbc.BaseJdbcDaopublic void destroy()
destroy in class com.github.ddth.dao.jdbc.BaseJdbcDaoprotected abstract IQueueMessage readFromQueueStorage(org.springframework.jdbc.core.JdbcTemplate jdbcTemplate)
jdbcTemplate - protected abstract IQueueMessage readFromEphemeralStorage(org.springframework.jdbc.core.JdbcTemplate jdbcTemplate, IQueueMessage msg)
jdbcTemplate - msg - protected abstract Collection<IQueueMessage> getOrphanFromEphemeralStorage(org.springframework.jdbc.core.JdbcTemplate jdbcTemplate, long thresholdTimestampMs)
jdbcTemplate - thresholdTimestampMs - get all orphan messages that were queued
before this timestampprotected abstract boolean putToQueueStorage(org.springframework.jdbc.core.JdbcTemplate jdbcTemplate,
IQueueMessage msg)
jdbcTemplate - msg - protected abstract boolean putToEphemeralStorage(org.springframework.jdbc.core.JdbcTemplate jdbcTemplate,
IQueueMessage msg)
jdbcTemplate - msg - protected abstract boolean removeFromQueueStorage(org.springframework.jdbc.core.JdbcTemplate jdbcTemplate,
IQueueMessage msg)
jdbcTemplate - msg - protected abstract boolean removeFromEphemeralStorage(org.springframework.jdbc.core.JdbcTemplate jdbcTemplate,
IQueueMessage msg)
jdbcTemplate - msg - protected boolean _queueWithRetries(Connection conn, IQueueMessage msg, int numRetries, int maxRetries) throws SQLException
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.
conn - msg - numRetries - maxRetries - SQLExceptionpublic boolean queue(IQueueMessage msg)
Implementation flow:
protected boolean _requeueWithRetries(Connection conn, IQueueMessage msg, int numRetries, int maxRetries) throws SQLException
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.
conn - msg - numRetries - maxRetries - SQLExceptionpublic boolean requeue(IQueueMessage msg)
Implementation flow:
Note: ephemeral storage implementation is optional, depends on implementation.
protected boolean _requeueSilentWithRetries(Connection conn, IQueueMessage msg, int numRetries, int maxRetries) throws SQLException
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.
conn - msg - numRetries - maxRetries - SQLExceptionpublic boolean requeueSilent(IQueueMessage msg)
Implementation flow:
Note: ephemeral storage implementation is optional, depends on implementation.
requeueSilent in interface IQueueprotected void _finishWithRetries(Connection conn, IQueueMessage msg, int numRetries, int maxRetries) throws SQLException
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.
conn - msg - numRetries - maxRetries - SQLExceptionpublic void finish(IQueueMessage msg)
Implementation flow:
Note: ephemeral storage implementation is optional, depends on implementation.
protected IQueueMessage _takeWithRetries(Connection conn, int numRetries, int maxRetries) throws SQLException
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.
conn - numRetries - maxRetries - SQLExceptionpublic IQueueMessage take()
Implementation flow:
Note: ephemeral storage implementation is optional, depends on implementation.
protected Collection<IQueueMessage> _getOrphanMessagesWithRetries(long thresholdTimestampMs, Connection conn, int numRetries, int maxRetries) throws SQLException
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.
thresholdTimestampMs - conn - numRetries - maxRetries - SQLExceptionpublic Collection<IQueueMessage> getOrphanMessages(long thresholdTimestampMs)
getOrphanMessages in interface IQueuethresholdTimestampMs - get all orphan messages that were queued
before this timestampprotected boolean _moveFromEphemeralToQueueStorageWithRetries(IQueueMessage msg, Connection conn, int numRetries, int maxRetries) throws SQLException
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.
msg - conn - numRetries - maxRetries - SQLExceptionpublic boolean moveFromEphemeralToQueueStorage(IQueueMessage msg)
Implementation flow:
moveFromEphemeralToQueueStorage in interface IQueuetrue if a move has been made, false otherwise
(e.g. the message didn't exist in ephemeral storage)public int queueSize()
public int ephemeralSize()
Note: ephemeral storage implementation is optional, depends on implementation.
ephemeralSize in interface IQueueCopyright © 2015 DDTH. All Rights Reserved.