Package org.apache.activemq.store.jdbc
Class JDBCPersistenceAdapter
java.lang.Object
org.apache.activemq.util.ServiceSupport
org.apache.activemq.broker.LockableServiceSupport
org.apache.activemq.store.jdbc.DataSourceServiceSupport
org.apache.activemq.store.jdbc.JDBCPersistenceAdapter
- All Implemented Interfaces:
BrokerServiceAware,Lockable,org.apache.activemq.Service,PersistenceAdapter
A
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.-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected org.apache.activemq.ActiveMQMessageAuditprotected intstatic final longprotected booleanprotected intprotected intprotected intprotected LongSequenceGeneratorprotected final HashMap<org.apache.activemq.command.ActiveMQDestination,MessageStore> Fields inherited from class org.apache.activemq.broker.LockableServiceSupport
brokerService, clockDaemon -
Constructor Summary
ConstructorsConstructorDescriptionJDBCPersistenceAdapter(DataSource ds, org.apache.activemq.wireformat.WireFormat wireFormat) -
Method Summary
Modifier and TypeMethodDescriptionvoidvoidbeginTransaction(ConnectionContext context) voidcheckpoint(boolean sync) voidcleanup()voidcommitAdd(ConnectionContext context, org.apache.activemq.command.MessageId messageId, long preparedSequenceId, long newSequence) voidcommitLastAck(ConnectionContext context, long xidLastAck, long priority, org.apache.activemq.command.ActiveMQDestination destination, String subName, String clientId) voidcommitRemove(ConnectionContext context, org.apache.activemq.command.MessageAck ack) voidcommitTransaction(ConnectionContext context) protected JDBCAdapterprotected voidcreateQueueMessageStore(org.apache.activemq.command.ActiveMQQueue destination) createTopicMessageStore(org.apache.activemq.command.ActiveMQTopic destination) voidvoiddoStart()voiddoStop(ServiceStopper stopper) intintDeprecated.Set<org.apache.activemq.command.ActiveMQDestination>longlonggetLastProducerSequenceId(org.apache.activemq.command.ProducerId id) intintintintlongintgetTransactionContext(ConnectionContext context) org.apache.activemq.wireformat.WireFormatvoidinit()voidbooleanbooleanbooleanbooleanstatic voidlog(String msg, SQLException e) voidrecover(JdbcMemoryTransactionStore jdbcMemoryTransactionStore) voidremoveQueueMessageStore(org.apache.activemq.command.ActiveMQQueue destination) Cleanup method to remove any state associated with the given destinationvoidremoveTopicMessageStore(org.apache.activemq.command.ActiveMQTopic destination) Cleanup method to remove any state associated with the given destination No state retained.... nothing to dovoidrollbackLastAck(ConnectionContext context, byte priority, org.apache.activemq.command.ActiveMQDestination destination, String subName, String clientId) voidrollbackLastAck(ConnectionContext context, JDBCTopicMessageStore store, org.apache.activemq.command.MessageAck ack, String subName, String clientId) voidrollbackTransaction(ConnectionContext context) voidsetAdapter(JDBCAdapter adapter) voidsetAuditRecoveryDepth(int auditRecoveryDepth) voidsetBrokerName(String brokerName) voidsetChangeAutoCommitAllowed(boolean changeAutoCommitAllowed) Whether the JDBC driver allows to set the auto commit.voidsetCleanupPeriod(int cleanupPeriod) Sets the number of milliseconds until the database is attempted to be cleaned up for durable topicsvoidsetCreateTablesOnStartup(boolean createTablesOnStartup) Sets whether or not tables are created on startupvoidsetDatabaseLocker(Locker locker) Deprecated.as of 5.7.0, replaced byLockableServiceSupport.setLocker(org.apache.activemq.broker.Locker)voidsetDirectory(File dir) voidsetEnableAudit(boolean enableAudit) voidsetLockAcquireSleepInterval(long lockAcquireSleepInterval) Deprecated.useLocker.setLockAcquireSleepInterval(long)instead millisecond interval between lock acquire attempts, applied to newly created DefaultDatabaseLocker not applied if DataBaseLocker is injected.voidsetLockDataSource(DataSource dataSource) voidsetMaxAuditDepth(int maxAuditDepth) voidsetMaxProducersToAudit(int maxProducersToAudit) voidsetMaxRows(int maxRows) voidsetNetworkTimeout(int networkTimeout) Define the JDBC connection network timeout.voidsetQueryTimeout(int queryTimeout) Define the JDBC statement query timeout.voidsetStatements(Statements statements) voidsetTransactionIsolation(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 inConnectionvoidsetUsageManager(SystemUsage usageManager) voidsetUseDatabaseLock(boolean useDatabaseLock) Deprecated.useLockableServiceSupport.setUseLock(boolean)instead Sets whether or not an exclusive database lock should be used to enable JDBC Master/Slave.voidsetUseExternalMessageReferences(boolean useExternalMessageReferences) voidsetWireFormat(org.apache.activemq.wireformat.WireFormat wireFormat) longsize()toString()Methods inherited from class org.apache.activemq.store.jdbc.DataSourceServiceSupport
closeDataSource, createDataSource, createDataSource, getDataDirectory, getDataDirectoryFile, getDataSource, setDataDirectory, setDataDirectoryFile, setDataSource, shutdownDefaultDataSourceMethods inherited from class org.apache.activemq.broker.LockableServiceSupport
getLocker, getLockKeepAlivePeriod, isStopOnError, isUseLock, keepLockAlive, postStop, preStart, setBrokerService, setLocker, setLockKeepAlivePeriod, setScheduledThreadPoolExecutor, setStopOnError, setUseLock, stopBrokerMethods inherited from class org.apache.activemq.util.ServiceSupport
addServiceListener, dispose, isStarted, isStopped, isStopping, removeServiceListener, start, stopMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface org.apache.activemq.Service
start, stop
-
Field Details
-
DEFAULT_LOCK_KEEP_ALIVE_PERIOD
public static final long DEFAULT_LOCK_KEEP_ALIVE_PERIOD- See Also:
-
maxProducersToAudit
protected int maxProducersToAudit -
maxAuditDepth
protected int maxAuditDepth -
enableAudit
protected boolean enableAudit -
auditRecoveryDepth
protected int auditRecoveryDepth -
audit
protected org.apache.activemq.ActiveMQMessageAudit audit -
sequenceGenerator
-
maxRows
protected int maxRows -
storeCache
-
-
Constructor Details
-
JDBCPersistenceAdapter
public JDBCPersistenceAdapter() -
JDBCPersistenceAdapter
-
-
Method Details
-
getDestinations
- Specified by:
getDestinationsin interfacePersistenceAdapter
-
createMessageAudit
protected void createMessageAudit() -
initSequenceIdGenerator
public void initSequenceIdGenerator() -
createQueueMessageStore
public MessageStore createQueueMessageStore(org.apache.activemq.command.ActiveMQQueue destination) throws IOException - Specified by:
createQueueMessageStorein interfacePersistenceAdapter- Throws:
IOException
-
createTopicMessageStore
public TopicMessageStore createTopicMessageStore(org.apache.activemq.command.ActiveMQTopic destination) throws IOException - Specified by:
createTopicMessageStorein interfacePersistenceAdapter- Throws:
IOException
-
removeQueueMessageStore
public void removeQueueMessageStore(org.apache.activemq.command.ActiveMQQueue destination) Cleanup method to remove any state associated with the given destination- Specified by:
removeQueueMessageStorein interfacePersistenceAdapter- Parameters:
destination- Destination to forget
-
removeTopicMessageStore
public void removeTopicMessageStore(org.apache.activemq.command.ActiveMQTopic destination) Cleanup method to remove any state associated with the given destination No state retained.... nothing to do- Specified by:
removeTopicMessageStorein interfacePersistenceAdapter- Parameters:
destination- Destination to forget
-
createTransactionStore
- Specified by:
createTransactionStorein interfacePersistenceAdapter- Throws:
IOException
-
getLastMessageBrokerSequenceId
- Specified by:
getLastMessageBrokerSequenceIdin interfacePersistenceAdapter- Throws:
IOException
-
getLastProducerSequenceId
- Specified by:
getLastProducerSequenceIdin interfacePersistenceAdapter- Throws:
IOException
-
allowIOResumption
public void allowIOResumption()- Specified by:
allowIOResumptionin interfacePersistenceAdapter
-
init
- Specified by:
initin classLockableServiceSupport- Throws:
Exception
-
doStart
- Specified by:
doStartin classServiceSupport- Throws:
Exception
-
doStop
- Specified by:
doStopin classServiceSupport- Throws:
Exception
-
cleanup
public void cleanup() -
getScheduledThreadPoolExecutor
- Overrides:
getScheduledThreadPoolExecutorin classLockableServiceSupport
-
getAdapter
- Throws:
IOException
-
getDatabaseLocker
Deprecated.as of 5.7.0, replaced byLockableServiceSupport.getLocker()- Throws:
IOException
-
setDatabaseLocker
Deprecated.as of 5.7.0, replaced byLockableServiceSupport.setLocker(org.apache.activemq.broker.Locker)Sets the database locker strategy to use to lock the database on startup- Throws:
IOException
-
getLockDataSource
- Throws:
IOException
-
setLockDataSource
-
getBrokerService
- Overrides:
getBrokerServicein classLockableServiceSupport
-
createAdapter
- Throws:
IOException
-
setAdapter
-
getWireFormat
public org.apache.activemq.wireformat.WireFormat getWireFormat() -
setWireFormat
public void setWireFormat(org.apache.activemq.wireformat.WireFormat wireFormat) -
getTransactionContext
- Throws:
IOException
-
getTransactionContext
- Throws:
IOException
-
beginTransaction
- Specified by:
beginTransactionin interfacePersistenceAdapter- Throws:
IOException
-
commitTransaction
- Specified by:
commitTransactionin interfacePersistenceAdapter- Throws:
IOException
-
rollbackTransaction
- Specified by:
rollbackTransactionin interfacePersistenceAdapter- Throws:
IOException
-
getCleanupPeriod
public int getCleanupPeriod() -
setCleanupPeriod
public void setCleanupPeriod(int cleanupPeriod) Sets the number of milliseconds until the database is attempted to be cleaned up for durable topics -
isChangeAutoCommitAllowed
public boolean isChangeAutoCommitAllowed() -
setChangeAutoCommitAllowed
public void setChangeAutoCommitAllowed(boolean changeAutoCommitAllowed) Whether the JDBC driver allows to set the auto commit. Some drivers does not allow changing the auto commit. The default value is true.- Parameters:
changeAutoCommitAllowed- true to change, false to not change.
-
getNetworkTimeout
public int getNetworkTimeout() -
setNetworkTimeout
public void setNetworkTimeout(int networkTimeout) Define the JDBC connection network timeout.- Parameters:
networkTimeout- the connection network timeout (in milliseconds).
-
getQueryTimeout
public int getQueryTimeout() -
setQueryTimeout
public void setQueryTimeout(int queryTimeout) Define the JDBC statement query timeout.- Parameters:
queryTimeout- the statement query timeout (in seconds).
-
deleteAllMessages
- Specified by:
deleteAllMessagesin interfacePersistenceAdapter- Throws:
IOException
-
isUseExternalMessageReferences
public boolean isUseExternalMessageReferences() -
setUseExternalMessageReferences
public void setUseExternalMessageReferences(boolean useExternalMessageReferences) -
isCreateTablesOnStartup
public boolean isCreateTablesOnStartup() -
setCreateTablesOnStartup
public void setCreateTablesOnStartup(boolean createTablesOnStartup) Sets whether or not tables are created on startup -
setUseDatabaseLock
Deprecated.useLockableServiceSupport.setUseLock(boolean)instead Sets whether or not an exclusive database lock should be used to enable JDBC Master/Slave. Enabled by default. -
log
-
getStatements
-
setStatements
-
setUsageManager
- Specified by:
setUsageManagerin interfacePersistenceAdapter- Parameters:
usageManager- The UsageManager that is controlling the destination's memory usage.
-
createDefaultLocker
- Specified by:
createDefaultLockerin interfaceLockable- Throws:
IOException
-
setBrokerName
- Specified by:
setBrokerNamein interfacePersistenceAdapter
-
toString
- Overrides:
toStringin classDataSourceServiceSupport
-
setDirectory
- Specified by:
setDirectoryin interfacePersistenceAdapter
-
getDirectory
- Specified by:
getDirectoryin interfacePersistenceAdapter
-
checkpoint
- Specified by:
checkpointin interfacePersistenceAdapter- Throws:
IOException
-
size
public long size()- Specified by:
sizein interfacePersistenceAdapter
-
setLockAcquireSleepInterval
@Deprecated public void setLockAcquireSleepInterval(long lockAcquireSleepInterval) throws IOException Deprecated.useLocker.setLockAcquireSleepInterval(long)instead millisecond interval between lock acquire attempts, applied to newly created DefaultDatabaseLocker not applied if DataBaseLocker is injected.- Throws:
IOException
-
setTransactionIsolation
public 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 inConnection- Parameters:
transactionIsolation- the isolation level to use
-
getMaxProducersToAudit
public int getMaxProducersToAudit() -
setMaxProducersToAudit
public void setMaxProducersToAudit(int maxProducersToAudit) -
getMaxAuditDepth
public int getMaxAuditDepth() -
setMaxAuditDepth
public void setMaxAuditDepth(int maxAuditDepth) -
isEnableAudit
public boolean isEnableAudit() -
setEnableAudit
public void setEnableAudit(boolean enableAudit) -
getAuditRecoveryDepth
public int getAuditRecoveryDepth() -
setAuditRecoveryDepth
public void setAuditRecoveryDepth(int auditRecoveryDepth) -
getNextSequenceId
public long getNextSequenceId() -
getMaxRows
public int getMaxRows() -
setMaxRows
public void setMaxRows(int maxRows) -
recover
- Throws:
IOException
-
commitAdd
public void commitAdd(ConnectionContext context, org.apache.activemq.command.MessageId messageId, long preparedSequenceId, long newSequence) throws IOException - Throws:
IOException
-
commitRemove
public void commitRemove(ConnectionContext context, org.apache.activemq.command.MessageAck ack) throws IOException - Throws:
IOException
-
commitLastAck
public void commitLastAck(ConnectionContext context, long xidLastAck, long priority, org.apache.activemq.command.ActiveMQDestination destination, String subName, String clientId) throws IOException - Throws:
IOException
-
rollbackLastAck
public void rollbackLastAck(ConnectionContext context, JDBCTopicMessageStore store, org.apache.activemq.command.MessageAck ack, String subName, String clientId) throws IOException - Throws:
IOException
-
rollbackLastAck
public void rollbackLastAck(ConnectionContext context, byte priority, org.apache.activemq.command.ActiveMQDestination destination, String subName, String clientId) throws IOException - Throws:
IOException
-
createJobSchedulerStore
public JobSchedulerStore createJobSchedulerStore() throws IOException, UnsupportedOperationException- Specified by:
createJobSchedulerStorein interfacePersistenceAdapter- Throws:
IOExceptionUnsupportedOperationException
-
LockableServiceSupport.getLocker()