org.apache.activemq.store.jdbc
Class JDBCPersistenceAdapter

java.lang.Object
  extended by org.apache.activemq.util.ServiceSupport
      extended by org.apache.activemq.broker.LockableServiceSupport
          extended by org.apache.activemq.store.jdbc.DataSourceServiceSupport
              extended by org.apache.activemq.store.jdbc.JDBCPersistenceAdapter
All Implemented Interfaces:
BrokerServiceAware, Lockable, org.apache.activemq.Service, PersistenceAdapter

public class JDBCPersistenceAdapter
extends DataSourceServiceSupport
implements 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
protected  org.apache.activemq.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
           
 
Fields inherited from class org.apache.activemq.broker.LockableServiceSupport
brokerService
 
Constructor Summary
JDBCPersistenceAdapter()
           
JDBCPersistenceAdapter(DataSource ds, org.apache.activemq.wireformat.WireFormat wireFormat)
           
 
Method Summary
 void beginTransaction(ConnectionContext context)
           
 void checkpoint(boolean sync)
           
 void cleanup()
           
 void commitAdd(ConnectionContext context, org.apache.activemq.command.MessageId messageId)
           
 void commitLastAck(ConnectionContext context, long xidLastAck, long priority, org.apache.activemq.command.ActiveMQDestination destination, String subName, String clientId)
           
 void commitRemove(ConnectionContext context, org.apache.activemq.command.MessageAck ack)
           
 void commitTransaction(ConnectionContext context)
           
protected  JDBCAdapter createAdapter()
           
 Locker createDefaultLocker()
           
protected  void createMessageAudit()
           
 MessageStore createQueueMessageStore(org.apache.activemq.command.ActiveMQQueue destination)
           
 TopicMessageStore createTopicMessageStore(org.apache.activemq.command.ActiveMQTopic destination)
           
 TransactionStore createTransactionStore()
           
 void deleteAllMessages()
           
 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<org.apache.activemq.command.ActiveMQDestination> getDestinations()
           
 File getDirectory()
           
 long getLastMessageBrokerSequenceId()
           
 long getLastProducerSequenceId(org.apache.activemq.command.ProducerId id)
           
 DataSource getLockDataSource()
           
 int getMaxAuditDepth()
           
 int getMaxProducersToAudit()
           
 int getMaxRows()
           
 long getNextSequenceId()
           
 ScheduledThreadPoolExecutor getScheduledThreadPoolExecutor()
           
 Statements getStatements()
           
 TransactionContext getTransactionContext()
           
 TransactionContext getTransactionContext(ConnectionContext context)
           
 org.apache.activemq.wireformat.WireFormat getWireFormat()
           
 void init()
           
 void initSequenceIdGenerator()
           
 boolean isChangeAutoCommitAllowed()
           
 boolean isCreateTablesOnStartup()
           
 boolean isEnableAudit()
           
 boolean isUseExternalMessageReferences()
           
static void log(String msg, SQLException e)
           
 void recover(JdbcMemoryTransactionStore jdbcMemoryTransactionStore)
           
 void removeQueueMessageStore(org.apache.activemq.command.ActiveMQQueue destination)
          Cleanup method to remove any state associated with the given destination
 void removeTopicMessageStore(org.apache.activemq.command.ActiveMQTopic destination)
          Cleanup method to remove any state associated with the given destination No state retained....
 void rollbackLastAck(ConnectionContext context, byte priority, org.apache.activemq.command.ActiveMQDestination destination, String subName, String clientId)
           
 void rollbackLastAck(ConnectionContext context, JDBCTopicMessageStore store, org.apache.activemq.command.MessageAck ack, String subName, String clientId)
           
 void rollbackTransaction(ConnectionContext context)
           
 void setAdapter(JDBCAdapter adapter)
           
 void setAuditRecoveryDepth(int auditRecoveryDepth)
           
 void setBrokerName(String brokerName)
           
 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)
           
 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 setScheduledThreadPoolExecutor(ScheduledThreadPoolExecutor clockDaemon)
           
 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(org.apache.activemq.wireformat.WireFormat wireFormat)
           
 long size()
           
 String toString()
           
 
Methods inherited from class org.apache.activemq.store.jdbc.DataSourceServiceSupport
createDataSource, getDataDirectory, getDataDirectoryFile, getDataSource, setDataDirectory, setDataDirectoryFile, setDataSource
 
Methods inherited from class org.apache.activemq.broker.LockableServiceSupport
getLocker, getLockKeepAlivePeriod, isUseLock, keepLockAlive, postStop, preStart, setBrokerService, setLocker, setLockKeepAlivePeriod, setUseLock, stopBroker
 
Methods inherited from class org.apache.activemq.util.ServiceSupport
addServiceListener, dispose, isStarted, isStopped, isStopping, removeServiceListener, start, stop
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.apache.activemq.Service
start, stop
 

Field Detail

DEFAULT_LOCK_KEEP_ALIVE_PERIOD

public static final long DEFAULT_LOCK_KEEP_ALIVE_PERIOD
See Also:
Constant Field Values

maxProducersToAudit

protected int maxProducersToAudit

maxAuditDepth

protected int maxAuditDepth

enableAudit

protected boolean enableAudit

auditRecoveryDepth

protected int auditRecoveryDepth

audit

protected org.apache.activemq.ActiveMQMessageAudit audit

sequenceGenerator

protected LongSequenceGenerator sequenceGenerator

maxRows

protected int maxRows
Constructor Detail

JDBCPersistenceAdapter

public JDBCPersistenceAdapter()

JDBCPersistenceAdapter

public JDBCPersistenceAdapter(DataSource ds,
                              org.apache.activemq.wireformat.WireFormat wireFormat)
Method Detail

getDestinations

public Set<org.apache.activemq.command.ActiveMQDestination> getDestinations()
Specified by:
getDestinations in interface PersistenceAdapter

createMessageAudit

protected void createMessageAudit()

initSequenceIdGenerator

public void initSequenceIdGenerator()

createQueueMessageStore

public MessageStore createQueueMessageStore(org.apache.activemq.command.ActiveMQQueue destination)
                                     throws IOException
Specified by:
createQueueMessageStore in interface PersistenceAdapter
Throws:
IOException

createTopicMessageStore

public TopicMessageStore createTopicMessageStore(org.apache.activemq.command.ActiveMQTopic destination)
                                          throws IOException
Specified by:
createTopicMessageStore in interface PersistenceAdapter
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:
removeQueueMessageStore in interface PersistenceAdapter
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:
removeTopicMessageStore in interface PersistenceAdapter
Parameters:
destination - Destination to forget

createTransactionStore

public TransactionStore createTransactionStore()
                                        throws IOException
Specified by:
createTransactionStore in interface PersistenceAdapter
Throws:
IOException

getLastMessageBrokerSequenceId

public long getLastMessageBrokerSequenceId()
                                    throws IOException
Specified by:
getLastMessageBrokerSequenceId in interface PersistenceAdapter
Throws:
IOException

getLastProducerSequenceId

public long getLastProducerSequenceId(org.apache.activemq.command.ProducerId id)
                               throws IOException
Specified by:
getLastProducerSequenceId in interface PersistenceAdapter
Throws:
IOException

init

public void init()
          throws Exception
Specified by:
init in class LockableServiceSupport
Throws:
Exception

doStart

public void doStart()
             throws Exception
Specified by:
doStart in class ServiceSupport
Throws:
Exception

doStop

public void doStop(ServiceStopper stopper)
            throws Exception
Specified by:
doStop in class ServiceSupport
Throws:
Exception

cleanup

public void cleanup()

setScheduledThreadPoolExecutor

public void setScheduledThreadPoolExecutor(ScheduledThreadPoolExecutor clockDaemon)

getScheduledThreadPoolExecutor

public ScheduledThreadPoolExecutor getScheduledThreadPoolExecutor()
Overrides:
getScheduledThreadPoolExecutor in class LockableServiceSupport

getAdapter

public JDBCAdapter getAdapter()
                       throws IOException
Throws:
IOException

getDatabaseLocker

@Deprecated
public Locker getDatabaseLocker()
                         throws IOException
Deprecated. as of 5.7.0, replaced by LockableServiceSupport.getLocker()

Throws:
IOException

setDatabaseLocker

@Deprecated
public void setDatabaseLocker(Locker locker)
                       throws IOException
Deprecated. as of 5.7.0, replaced by LockableServiceSupport.setLocker(org.apache.activemq.broker.Locker)

Sets the database locker strategy to use to lock the database on startup

Throws:
IOException

getLockDataSource

public DataSource getLockDataSource()
                             throws IOException
Throws:
IOException

setLockDataSource

public void setLockDataSource(DataSource dataSource)

getBrokerService

public BrokerService getBrokerService()
Overrides:
getBrokerService in class LockableServiceSupport

createAdapter

protected JDBCAdapter createAdapter()
                             throws IOException
Throws:
IOException

setAdapter

public void setAdapter(JDBCAdapter adapter)

getWireFormat

public org.apache.activemq.wireformat.WireFormat getWireFormat()

setWireFormat

public void setWireFormat(org.apache.activemq.wireformat.WireFormat wireFormat)

getTransactionContext

public TransactionContext getTransactionContext(ConnectionContext context)
                                         throws IOException
Throws:
IOException

getTransactionContext

public TransactionContext getTransactionContext()
                                         throws IOException
Throws:
IOException

beginTransaction

public void beginTransaction(ConnectionContext context)
                      throws IOException
Specified by:
beginTransaction in interface PersistenceAdapter
Throws:
IOException

commitTransaction

public void commitTransaction(ConnectionContext context)
                       throws IOException
Specified by:
commitTransaction in interface PersistenceAdapter
Throws:
IOException

rollbackTransaction

public void rollbackTransaction(ConnectionContext context)
                         throws IOException
Specified by:
rollbackTransaction in interface PersistenceAdapter
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.

deleteAllMessages

public void deleteAllMessages()
                       throws IOException
Specified by:
deleteAllMessages in interface PersistenceAdapter
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
public 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.


log

public static void log(String msg,
                       SQLException e)

getStatements

public Statements getStatements()

setStatements

public void setStatements(Statements statements)

setUsageManager

public void setUsageManager(SystemUsage usageManager)
Specified by:
setUsageManager in interface PersistenceAdapter
Parameters:
usageManager - The UsageManager that is controlling the destination's memory usage.

createDefaultLocker

public Locker createDefaultLocker()
                           throws IOException
Specified by:
createDefaultLocker in interface Lockable
Throws:
IOException

setBrokerName

public void setBrokerName(String brokerName)
Specified by:
setBrokerName in interface PersistenceAdapter

toString

public String toString()
Overrides:
toString in class DataSourceServiceSupport

setDirectory

public void setDirectory(File dir)
Specified by:
setDirectory in interface PersistenceAdapter

getDirectory

public File getDirectory()
Specified by:
getDirectory in interface PersistenceAdapter

checkpoint

public void checkpoint(boolean sync)
                throws IOException
Specified by:
checkpoint in interface PersistenceAdapter
Throws:
IOException

size

public long size()
Specified by:
size in interface PersistenceAdapter

setLockAcquireSleepInterval

@Deprecated
public void setLockAcquireSleepInterval(long lockAcquireSleepInterval)
                                 throws IOException
Deprecated. use Locker.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 in Connection

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

public void recover(JdbcMemoryTransactionStore jdbcMemoryTransactionStore)
             throws IOException
Throws:
IOException

commitAdd

public void commitAdd(ConnectionContext context,
                      org.apache.activemq.command.MessageId messageId)
               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


Copyright © 2005-2013 The Apache Software Foundation. All Rights Reserved.