public class JDBCPersistenceAdapter extends DataSourceServiceSupport implements PersistenceAdapter
PersistenceAdapter
implementation using JDBC for persistence
storage.
This persistence adapter will correctly remember prepared XA transactions,
but it will not keep track of local transaction commits so that operations
performed against the Message store are done as a single uow.Modifier and Type | Field and Description |
---|---|
protected ActiveMQMessageAudit |
audit |
protected int |
auditRecoveryDepth |
static long |
DEFAULT_LOCK_KEEP_ALIVE_PERIOD |
protected boolean |
enableAudit |
protected int |
maxAuditDepth |
protected int |
maxProducersToAudit |
protected int |
maxRows |
protected LongSequenceGenerator |
sequenceGenerator |
brokerService, clockDaemon
Constructor and Description |
---|
JDBCPersistenceAdapter() |
JDBCPersistenceAdapter(DataSource ds,
WireFormat wireFormat) |
Modifier and Type | Method and Description |
---|---|
void |
allowIOResumption() |
void |
beginTransaction(ConnectionContext context)
This method starts a transaction on the persistent storage - which is
nothing to do with JMS or XA transactions - its purely a mechanism to
perform multiple writes to a persistent store in 1 transaction as a
performance optimization.
|
void |
checkpoint(boolean sync)
checkpoint any
|
void |
cleanup() |
void |
commitAdd(ConnectionContext context,
MessageId messageId,
long preparedSequenceId) |
void |
commitLastAck(ConnectionContext context,
long xidLastAck,
long priority,
ActiveMQDestination destination,
String subName,
String clientId) |
void |
commitRemove(ConnectionContext context,
MessageAck ack) |
void |
commitTransaction(ConnectionContext context)
Commit a persistence transaction
|
protected JDBCAdapter |
createAdapter() |
Locker |
createDefaultLocker()
Create a default locker
|
JobSchedulerStore |
createJobSchedulerStore()
Creates and returns a new Job Scheduler store instance.
|
protected void |
createMessageAudit() |
MessageStore |
createQueueMessageStore(ActiveMQQueue destination)
Factory method to create a new queue message store with the given
destination name
|
TopicMessageStore |
createTopicMessageStore(ActiveMQTopic destination)
Factory method to create a new topic message store with the given
destination name
|
TransactionStore |
createTransactionStore()
Factory method to create a new persistent prepared transaction store for
XA recovery
|
void |
deleteAllMessages()
Delete's all the messages in the persistent store.
|
void |
doStart() |
void |
doStop(ServiceStopper stopper) |
JDBCAdapter |
getAdapter() |
int |
getAuditRecoveryDepth() |
BrokerService |
getBrokerService() |
int |
getCleanupPeriod() |
Locker |
getDatabaseLocker()
Deprecated.
as of 5.7.0, replaced by
LockableServiceSupport.getLocker() |
Set<ActiveMQDestination> |
getDestinations()
Returns a set of all the
ActiveMQDestination objects that the
persistence store is aware exist. |
File |
getDirectory() |
long |
getLastMessageBrokerSequenceId() |
long |
getLastProducerSequenceId(ProducerId id)
return the last stored producer sequenceId for this producer Id used to
suppress duplicate sends on failover reconnect at the transport when a
reconnect occurs
|
DataSource |
getLockDataSource() |
int |
getMaxAuditDepth() |
int |
getMaxProducersToAudit() |
int |
getMaxRows() |
long |
getNextSequenceId() |
ScheduledThreadPoolExecutor |
getScheduledThreadPoolExecutor() |
Statements |
getStatements() |
TransactionContext |
getTransactionContext() |
TransactionContext |
getTransactionContext(ConnectionContext context) |
WireFormat |
getWireFormat() |
void |
init()
Initialize resources before locking
|
void |
initSequenceIdGenerator() |
boolean |
isChangeAutoCommitAllowed() |
boolean |
isCreateTablesOnStartup() |
boolean |
isEnableAudit() |
boolean |
isUseExternalMessageReferences() |
static void |
log(String msg,
SQLException e) |
void |
recover(JdbcMemoryTransactionStore jdbcMemoryTransactionStore) |
void |
removeQueueMessageStore(ActiveMQQueue destination)
Cleanup method to remove any state associated with the given destination
|
void |
removeTopicMessageStore(ActiveMQTopic destination)
Cleanup method to remove any state associated with the given destination
No state retained....
|
void |
rollbackLastAck(ConnectionContext context,
byte priority,
ActiveMQDestination destination,
String subName,
String clientId) |
void |
rollbackLastAck(ConnectionContext context,
JDBCTopicMessageStore store,
MessageAck ack,
String subName,
String clientId) |
void |
rollbackTransaction(ConnectionContext context)
Rollback a persistence transaction
|
void |
setAdapter(JDBCAdapter adapter) |
void |
setAuditRecoveryDepth(int auditRecoveryDepth) |
void |
setBrokerName(String brokerName)
Set the name of the broker using the adapter
|
void |
setChangeAutoCommitAllowed(boolean changeAutoCommitAllowed)
Whether the JDBC driver allows to set the auto commit.
|
void |
setCleanupPeriod(int cleanupPeriod)
Sets the number of milliseconds until the database is attempted to be
cleaned up for durable topics
|
void |
setCreateTablesOnStartup(boolean createTablesOnStartup)
Sets whether or not tables are created on startup
|
void |
setDatabaseLocker(Locker locker)
Deprecated.
as of 5.7.0, replaced by
LockableServiceSupport.setLocker(org.apache.activemq.broker.Locker) |
void |
setDirectory(File dir)
Set the directory where any data files should be created
|
void |
setEnableAudit(boolean enableAudit) |
void |
setLockAcquireSleepInterval(long lockAcquireSleepInterval)
Deprecated.
use
Locker.setLockAcquireSleepInterval(long) instead
millisecond interval between lock acquire attempts, applied to newly created DefaultDatabaseLocker
not applied if DataBaseLocker is injected. |
void |
setLockDataSource(DataSource dataSource) |
void |
setMaxAuditDepth(int maxAuditDepth) |
void |
setMaxProducersToAudit(int maxProducersToAudit) |
void |
setMaxRows(int maxRows) |
void |
setStatements(Statements statements) |
void |
setTransactionIsolation(int transactionIsolation)
set the Transaction isolation level to something other that TRANSACTION_READ_UNCOMMITTED
This allowable dirty isolation level may not be achievable in clustered DB environments
so a more restrictive and expensive option may be needed like TRANSACTION_REPEATABLE_READ
see isolation level constants in
Connection |
void |
setUsageManager(SystemUsage usageManager) |
void |
setUseDatabaseLock(boolean useDatabaseLock)
Deprecated.
use
LockableServiceSupport.setUseLock(boolean) instead
Sets whether or not an exclusive database lock should be used to enable
JDBC Master/Slave. Enabled by default. |
void |
setUseExternalMessageReferences(boolean useExternalMessageReferences) |
void |
setWireFormat(WireFormat wireFormat) |
long |
size()
A hint to return the size of the store on disk
|
String |
toString() |
closeDataSource, createDataSource, createDataSource, getDataDirectory, getDataDirectoryFile, getDataSource, setDataDirectory, setDataDirectoryFile, setDataSource, shutdownDefaultDataSource
getLocker, getLockKeepAlivePeriod, isUseLock, keepLockAlive, postStop, preStart, setBrokerService, setLocker, setLockKeepAlivePeriod, setScheduledThreadPoolExecutor, setUseLock, stopBroker
addServiceListener, dispose, isStarted, isStopped, isStopping, removeServiceListener, start, stop
public static final long DEFAULT_LOCK_KEEP_ALIVE_PERIOD
protected int maxProducersToAudit
protected int maxAuditDepth
protected boolean enableAudit
protected int auditRecoveryDepth
protected ActiveMQMessageAudit audit
protected LongSequenceGenerator sequenceGenerator
protected int maxRows
public JDBCPersistenceAdapter()
public JDBCPersistenceAdapter(DataSource ds, WireFormat wireFormat)
public Set<ActiveMQDestination> getDestinations()
PersistenceAdapter
ActiveMQDestination
objects that the
persistence store is aware exist.getDestinations
in interface PersistenceAdapter
protected void createMessageAudit()
public void initSequenceIdGenerator()
public MessageStore createQueueMessageStore(ActiveMQQueue destination) throws IOException
PersistenceAdapter
createQueueMessageStore
in interface PersistenceAdapter
IOException
public TopicMessageStore createTopicMessageStore(ActiveMQTopic destination) throws IOException
PersistenceAdapter
createTopicMessageStore
in interface PersistenceAdapter
IOException
public void removeQueueMessageStore(ActiveMQQueue destination)
removeQueueMessageStore
in interface PersistenceAdapter
destination
- Destination to forgetpublic void removeTopicMessageStore(ActiveMQTopic destination)
removeTopicMessageStore
in interface PersistenceAdapter
destination
- Destination to forgetpublic TransactionStore createTransactionStore() throws IOException
PersistenceAdapter
createTransactionStore
in interface PersistenceAdapter
IOException
public long getLastMessageBrokerSequenceId() throws IOException
getLastMessageBrokerSequenceId
in interface PersistenceAdapter
IOException
public long getLastProducerSequenceId(ProducerId id) throws IOException
PersistenceAdapter
getLastProducerSequenceId
in interface PersistenceAdapter
id
- the producerId to find a sequenceId forIOException
public void allowIOResumption()
allowIOResumption
in interface PersistenceAdapter
public void init() throws Exception
LockableServiceSupport
init
in class LockableServiceSupport
Exception
public void doStart() throws Exception
doStart
in class ServiceSupport
Exception
public void doStop(ServiceStopper stopper) throws Exception
doStop
in class ServiceSupport
Exception
public void cleanup()
public ScheduledThreadPoolExecutor getScheduledThreadPoolExecutor()
getScheduledThreadPoolExecutor
in class LockableServiceSupport
public JDBCAdapter getAdapter() throws IOException
IOException
@Deprecated public Locker getDatabaseLocker() throws IOException
LockableServiceSupport.getLocker()
IOException
@Deprecated public void setDatabaseLocker(Locker locker) throws IOException
LockableServiceSupport.setLocker(org.apache.activemq.broker.Locker)
IOException
public DataSource getLockDataSource() throws IOException
IOException
public void setLockDataSource(DataSource dataSource)
public BrokerService getBrokerService()
getBrokerService
in class LockableServiceSupport
protected JDBCAdapter createAdapter() throws IOException
IOException
public void setAdapter(JDBCAdapter adapter)
public WireFormat getWireFormat()
public void setWireFormat(WireFormat wireFormat)
public TransactionContext getTransactionContext(ConnectionContext context) throws IOException
IOException
public TransactionContext getTransactionContext() throws IOException
IOException
public void beginTransaction(ConnectionContext context) throws IOException
PersistenceAdapter
beginTransaction
in interface PersistenceAdapter
IOException
public void commitTransaction(ConnectionContext context) throws IOException
PersistenceAdapter
commitTransaction
in interface PersistenceAdapter
IOException
PersistenceAdapter.beginTransaction(ConnectionContext context)
public void rollbackTransaction(ConnectionContext context) throws IOException
PersistenceAdapter
rollbackTransaction
in interface PersistenceAdapter
IOException
PersistenceAdapter.beginTransaction(ConnectionContext context)
public int getCleanupPeriod()
public void setCleanupPeriod(int cleanupPeriod)
public boolean isChangeAutoCommitAllowed()
public void setChangeAutoCommitAllowed(boolean changeAutoCommitAllowed)
changeAutoCommitAllowed
- true to change, false to not change.public void deleteAllMessages() throws IOException
PersistenceAdapter
deleteAllMessages
in interface PersistenceAdapter
IOException
public boolean isUseExternalMessageReferences()
public void setUseExternalMessageReferences(boolean useExternalMessageReferences)
public boolean isCreateTablesOnStartup()
public void setCreateTablesOnStartup(boolean createTablesOnStartup)
@Deprecated public void setUseDatabaseLock(boolean useDatabaseLock)
LockableServiceSupport.setUseLock(boolean)
instead
Sets whether or not an exclusive database lock should be used to enable
JDBC Master/Slave. Enabled by default.public static void log(String msg, SQLException e)
public Statements getStatements()
public void setStatements(Statements statements)
public void setUsageManager(SystemUsage usageManager)
setUsageManager
in interface PersistenceAdapter
usageManager
- The UsageManager that is controlling the
destination's memory usage.public Locker createDefaultLocker() throws IOException
Lockable
createDefaultLocker
in interface Lockable
IOException
public void setBrokerName(String brokerName)
PersistenceAdapter
setBrokerName
in interface PersistenceAdapter
public String toString()
toString
in class DataSourceServiceSupport
public void setDirectory(File dir)
PersistenceAdapter
setDirectory
in interface PersistenceAdapter
public File getDirectory()
getDirectory
in interface PersistenceAdapter
public void checkpoint(boolean sync) throws IOException
PersistenceAdapter
checkpoint
in interface PersistenceAdapter
IOException
public long size()
PersistenceAdapter
size
in interface PersistenceAdapter
@Deprecated public void setLockAcquireSleepInterval(long lockAcquireSleepInterval) throws IOException
Locker.setLockAcquireSleepInterval(long)
instead
millisecond interval between lock acquire attempts, applied to newly created DefaultDatabaseLocker
not applied if DataBaseLocker is injected.IOException
public void setTransactionIsolation(int transactionIsolation)
Connection
transactionIsolation
- the isolation level to usepublic int getMaxProducersToAudit()
public void setMaxProducersToAudit(int maxProducersToAudit)
public int getMaxAuditDepth()
public void setMaxAuditDepth(int maxAuditDepth)
public boolean isEnableAudit()
public void setEnableAudit(boolean enableAudit)
public int getAuditRecoveryDepth()
public void setAuditRecoveryDepth(int auditRecoveryDepth)
public long getNextSequenceId()
public int getMaxRows()
public void setMaxRows(int maxRows)
public void recover(JdbcMemoryTransactionStore jdbcMemoryTransactionStore) throws IOException
IOException
public void commitAdd(ConnectionContext context, MessageId messageId, long preparedSequenceId) throws IOException
IOException
public void commitRemove(ConnectionContext context, MessageAck ack) throws IOException
IOException
public void commitLastAck(ConnectionContext context, long xidLastAck, long priority, ActiveMQDestination destination, String subName, String clientId) throws IOException
IOException
public void rollbackLastAck(ConnectionContext context, JDBCTopicMessageStore store, MessageAck ack, String subName, String clientId) throws IOException
IOException
public void rollbackLastAck(ConnectionContext context, byte priority, ActiveMQDestination destination, String subName, String clientId) throws IOException
IOException
public JobSchedulerStore createJobSchedulerStore() throws IOException, UnsupportedOperationException
PersistenceAdapter
createJobSchedulerStore
in interface PersistenceAdapter
IOException
- If an error occurs while creating the new JobSchedulerStore.UnsupportedOperationException
- If this adapter does not provide its own
scheduler store implementation.Copyright © 2005–2019 The Apache Software Foundation. All rights reserved.