org.apache.activemq.store.jdbc
Class JDBCPersistenceAdapter

java.lang.Object
  extended by org.apache.activemq.store.jdbc.DataSourceSupport
      extended by org.apache.activemq.store.jdbc.JDBCPersistenceAdapter
All Implemented Interfaces:
BrokerServiceAware, Service, PersistenceAdapter

public class JDBCPersistenceAdapter
extends DataSourceSupport
implements PersistenceAdapter, BrokerServiceAware

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.

Version:
$Revision: 1.9 $

Constructor Summary
JDBCPersistenceAdapter()
           
JDBCPersistenceAdapter(javax.sql.DataSource ds, WireFormat wireFormat)
           
 
Method Summary
 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 cleanup()
           
 void commitTransaction(ConnectionContext context)
          Commit a persistence transaction
protected  JDBCAdapter createAdapter()
           
protected  DatabaseLocker createDatabaseLocker()
           
 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
protected  void databaseLockKeepAlive()
           
 void deleteAllMessages()
          Delete's all the messages in the persistent store.
 JDBCAdapter getAdapter()
           
 BrokerService getBrokerService()
           
 int getCleanupPeriod()
           
 DatabaseLocker getDatabaseLocker()
           
 java.util.Set getDestinations()
          Returns a set of all the ActiveMQDestination objects that the persistence store is aware exist.
 long getLastMessageBrokerSequenceId()
           
 edu.emory.mathcs.backport.java.util.concurrent.ScheduledThreadPoolExecutor getScheduledThreadPoolExecutor()
           
 Statements getStatements()
           
 TransactionContext getTransactionContext()
           
 TransactionContext getTransactionContext(ConnectionContext context)
           
 WireFormat getWireFormat()
           
 boolean isCreateTablesOnStartup()
           
 boolean isUseDatabaseLock()
           
 boolean isUseExternalMessageReferences()
           
static void log(java.lang.String msg, java.sql.SQLException e)
           
 void rollbackTransaction(ConnectionContext context)
          Rollback a persistence transaction
 void setAdapter(JDBCAdapter adapter)
           
 void setBrokerService(BrokerService brokerService)
           
 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(DatabaseLocker databaseLocker)
          Sets the database locker strategy to use to lock the database on startup
 void setScheduledThreadPoolExecutor(edu.emory.mathcs.backport.java.util.concurrent.ScheduledThreadPoolExecutor clockDaemon)
           
 void setStatements(Statements statements)
           
 void setUsageManager(UsageManager usageManager)
           
 void setUseDatabaseLock(boolean useDatabaseLock)
          Sets whether or not an exclusive database lock should be used to enable JDBC Master/Slave.
 void setUseExternalMessageReferences(boolean useExternalMessageReferences)
           
 void setWireFormat(WireFormat wireFormat)
           
 void start()
           
 void stop()
           
protected  void stopBroker()
           
 
Methods inherited from class org.apache.activemq.store.jdbc.DataSourceSupport
createDataSource, getDataDirectory, getDataDirectoryFile, getDataSource, setDataDirectory, setDataDirectoryFile, setDataSource
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JDBCPersistenceAdapter

public JDBCPersistenceAdapter()

JDBCPersistenceAdapter

public JDBCPersistenceAdapter(javax.sql.DataSource ds,
                              WireFormat wireFormat)
Method Detail

getDestinations

public java.util.Set getDestinations()
Description copied from interface: PersistenceAdapter
Returns a set of all the ActiveMQDestination objects that the persistence store is aware exist.

Specified by:
getDestinations in interface PersistenceAdapter
Returns:

createQueueMessageStore

public MessageStore createQueueMessageStore(ActiveMQQueue destination)
                                     throws java.io.IOException
Description copied from interface: PersistenceAdapter
Factory method to create a new queue message store with the given destination name

Specified by:
createQueueMessageStore in interface PersistenceAdapter
Throws:
java.io.IOException

createTopicMessageStore

public TopicMessageStore createTopicMessageStore(ActiveMQTopic destination)
                                          throws java.io.IOException
Description copied from interface: PersistenceAdapter
Factory method to create a new topic message store with the given destination name

Specified by:
createTopicMessageStore in interface PersistenceAdapter
Throws:
java.io.IOException

createTransactionStore

public TransactionStore createTransactionStore()
                                        throws java.io.IOException
Description copied from interface: PersistenceAdapter
Factory method to create a new persistent prepared transaction store for XA recovery

Specified by:
createTransactionStore in interface PersistenceAdapter
Throws:
java.io.IOException

getLastMessageBrokerSequenceId

public long getLastMessageBrokerSequenceId()
                                    throws java.io.IOException
Specified by:
getLastMessageBrokerSequenceId in interface PersistenceAdapter
Returns:
Throws:
java.io.IOException

start

public void start()
           throws java.lang.Exception
Specified by:
start in interface Service
Throws:
java.lang.Exception

stop

public void stop()
          throws java.lang.Exception
Specified by:
stop in interface Service
Throws:
java.lang.Exception

cleanup

public void cleanup()

setScheduledThreadPoolExecutor

public void setScheduledThreadPoolExecutor(edu.emory.mathcs.backport.java.util.concurrent.ScheduledThreadPoolExecutor clockDaemon)

getScheduledThreadPoolExecutor

public edu.emory.mathcs.backport.java.util.concurrent.ScheduledThreadPoolExecutor getScheduledThreadPoolExecutor()

getAdapter

public JDBCAdapter getAdapter()
                       throws java.io.IOException
Throws:
java.io.IOException

getDatabaseLocker

public DatabaseLocker getDatabaseLocker()
                                 throws java.io.IOException
Throws:
java.io.IOException

setDatabaseLocker

public void setDatabaseLocker(DatabaseLocker databaseLocker)
Sets the database locker strategy to use to lock the database on startup


getBrokerService

public BrokerService getBrokerService()

setBrokerService

public void setBrokerService(BrokerService brokerService)
Specified by:
setBrokerService in interface BrokerServiceAware

createAdapter

protected JDBCAdapter createAdapter()
                             throws java.io.IOException
Throws:
java.io.IOException

setAdapter

public void setAdapter(JDBCAdapter adapter)

getWireFormat

public WireFormat getWireFormat()

setWireFormat

public void setWireFormat(WireFormat wireFormat)

getTransactionContext

public TransactionContext getTransactionContext(ConnectionContext context)
                                         throws java.io.IOException
Throws:
java.io.IOException

getTransactionContext

public TransactionContext getTransactionContext()
                                         throws java.io.IOException
Throws:
java.io.IOException

beginTransaction

public void beginTransaction(ConnectionContext context)
                      throws java.io.IOException
Description copied from interface: PersistenceAdapter
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.

Typically one transaction will require one disk synchronization point and so for real high performance its usually faster to perform many writes within the same transaction to minimize latency caused by disk synchronization. This is especially true when using tools like Berkeley Db or embedded JDBC servers.

Specified by:
beginTransaction in interface PersistenceAdapter
Throws:
java.io.IOException

commitTransaction

public void commitTransaction(ConnectionContext context)
                       throws java.io.IOException
Description copied from interface: PersistenceAdapter
Commit a persistence transaction

Specified by:
commitTransaction in interface PersistenceAdapter
Throws:
java.io.IOException
See Also:
PersistenceAdapter#beginTransaction()

rollbackTransaction

public void rollbackTransaction(ConnectionContext context)
                         throws java.io.IOException
Description copied from interface: PersistenceAdapter
Rollback a persistence transaction

Specified by:
rollbackTransaction in interface PersistenceAdapter
Throws:
java.io.IOException
See Also:
PersistenceAdapter#beginTransaction()

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


deleteAllMessages

public void deleteAllMessages()
                       throws java.io.IOException
Description copied from interface: PersistenceAdapter
Delete's all the messages in the persistent store.

Specified by:
deleteAllMessages in interface PersistenceAdapter
Throws:
java.io.IOException

isUseExternalMessageReferences

public boolean isUseExternalMessageReferences()
Specified by:
isUseExternalMessageReferences in interface PersistenceAdapter

setUseExternalMessageReferences

public void setUseExternalMessageReferences(boolean useExternalMessageReferences)
Specified by:
setUseExternalMessageReferences in interface PersistenceAdapter

isCreateTablesOnStartup

public boolean isCreateTablesOnStartup()

setCreateTablesOnStartup

public void setCreateTablesOnStartup(boolean createTablesOnStartup)
Sets whether or not tables are created on startup


isUseDatabaseLock

public boolean isUseDatabaseLock()

setUseDatabaseLock

public void setUseDatabaseLock(boolean useDatabaseLock)
Sets whether or not an exclusive database lock should be used to enable JDBC Master/Slave. Enabled by default.


log

public static void log(java.lang.String msg,
                       java.sql.SQLException e)

getStatements

public Statements getStatements()

setStatements

public void setStatements(Statements statements)

setUsageManager

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

databaseLockKeepAlive

protected void databaseLockKeepAlive()

stopBroker

protected void stopBroker()

createDatabaseLocker

protected DatabaseLocker createDatabaseLocker()
                                       throws java.io.IOException
Throws:
java.io.IOException


Copyright © 2010 Apache Software Foundation. All Rights Reserved.