org.apache.activemq.store.journal
Class QuickJournalPersistenceAdapter

java.lang.Object
  extended by org.apache.activemq.store.journal.QuickJournalPersistenceAdapter
All Implemented Interfaces:
org.apache.activeio.journal.JournalEventListener, UsageListener, Service, PersistenceAdapter

public class QuickJournalPersistenceAdapter
extends Object
implements PersistenceAdapter, org.apache.activeio.journal.JournalEventListener, UsageListener

An implementation of PersistenceAdapter designed for use with a Journal and then check pointing asynchronously on a timeout with some other long term persistent storage.

Version:
$Revision: 1.17 $

Constructor Summary
QuickJournalPersistenceAdapter(org.apache.activeio.journal.Journal journal, PersistenceAdapter longTermPersistence, TaskRunnerFactory taskRunnerFactory)
           
 
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 checkpoint(boolean sync, boolean fullCheckpoint)
          When we checkpoint we move all the journalled data to long term storage.
 void commitTransaction(ConnectionContext context)
          Commit a persistence transaction
 MessageStore createQueueMessageStore(ActiveMQQueue destination)
          Factory method to create a new queue message store with the given destination name
protected  IOException createRecoveryFailedException(Exception e)
           
 TopicMessageStore createTopicMessageStore(ActiveMQTopic destinationName)
          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  IOException createWriteException(DataStructure packet, Exception e)
           
protected  IOException createWriteException(String command, Exception e)
           
 void deleteAllMessages()
          Delete's all the messages in the persistent store.
 boolean doCheckpoint()
          This does the actual checkpoint.
 Set getDestinations()
          Returns a set of all the ActiveMQDestination objects that the persistence store is aware exist.
 long getLastMessageBrokerSequenceId()
           
 PersistenceAdapter getLongTermPersistence()
           
 int getMaxCheckpointMessageAddSize()
           
 int getMaxCheckpointWorkers()
           
 QuickJournalTransactionStore getTransactionStore()
           
 UsageManager getUsageManager()
           
 WireFormat getWireFormat()
           
 boolean isUseExternalMessageReferences()
           
 void onMemoryUseChanged(UsageManager memoryManager, int oldPercentUsage, int newPercentUsage)
           
 void overflowNotification(org.apache.activeio.journal.RecordLocation safeLocation)
          The Journal give us a call back so that we can move old data out of the journal.
 DataStructure readCommand(org.apache.activeio.journal.RecordLocation location)
           
 void rollbackTransaction(ConnectionContext context)
          Rollback a persistence transaction
 void setMaxCheckpointMessageAddSize(int maxCheckpointMessageAddSize)
           
 void setMaxCheckpointWorkers(int maxCheckpointWorkers)
           
 void setUsageManager(UsageManager usageManager)
           
 void setUseExternalMessageReferences(boolean enable)
           
 void start()
           
 void stop()
           
 ByteSequence toByteSequence(org.apache.activeio.packet.Packet packet)
           
 org.apache.activeio.packet.Packet toPacket(ByteSequence sequence)
           
 org.apache.activeio.journal.RecordLocation writeCommand(DataStructure command, boolean sync)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

QuickJournalPersistenceAdapter

public QuickJournalPersistenceAdapter(org.apache.activeio.journal.Journal journal,
                                      PersistenceAdapter longTermPersistence,
                                      TaskRunnerFactory taskRunnerFactory)
                               throws IOException
Throws:
IOException
Method Detail

setUsageManager

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

getDestinations

public 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 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:
IOException

createTopicMessageStore

public TopicMessageStore createTopicMessageStore(ActiveMQTopic destinationName)
                                          throws 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:
IOException

createTransactionStore

public TransactionStore createTransactionStore()
                                        throws 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:
IOException

getLastMessageBrokerSequenceId

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

beginTransaction

public void beginTransaction(ConnectionContext context)
                      throws 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:
IOException

commitTransaction

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

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

rollbackTransaction

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

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

start

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

stop

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

getLongTermPersistence

public PersistenceAdapter getLongTermPersistence()

getWireFormat

public WireFormat getWireFormat()
Returns:
Returns the wireFormat.

overflowNotification

public void overflowNotification(org.apache.activeio.journal.RecordLocation safeLocation)
The Journal give us a call back so that we can move old data out of the journal. Taking a checkpoint does this for us.

Specified by:
overflowNotification in interface org.apache.activeio.journal.JournalEventListener
See Also:
org.apache.activemq.journal.JournalEventListener#overflowNotification(org.apache.activemq.journal.RecordLocation)

checkpoint

public void checkpoint(boolean sync,
                       boolean fullCheckpoint)
When we checkpoint we move all the journalled data to long term storage.

Parameters:
stopping -
b -

doCheckpoint

public boolean doCheckpoint()
This does the actual checkpoint.

Returns:

readCommand

public DataStructure readCommand(org.apache.activeio.journal.RecordLocation location)
                          throws IOException
Parameters:
location -
Returns:
Throws:
IOException

createWriteException

protected IOException createWriteException(DataStructure packet,
                                           Exception e)

createWriteException

protected IOException createWriteException(String command,
                                           Exception e)

createRecoveryFailedException

protected IOException createRecoveryFailedException(Exception e)

writeCommand

public org.apache.activeio.journal.RecordLocation writeCommand(DataStructure command,
                                                               boolean sync)
                                                        throws IOException
Parameters:
command -
sync -
Returns:
Throws:
IOException

onMemoryUseChanged

public void onMemoryUseChanged(UsageManager memoryManager,
                               int oldPercentUsage,
                               int newPercentUsage)
Specified by:
onMemoryUseChanged in interface UsageListener

getTransactionStore

public QuickJournalTransactionStore getTransactionStore()

deleteAllMessages

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

Specified by:
deleteAllMessages in interface PersistenceAdapter
Throws:
IOException

getUsageManager

public UsageManager getUsageManager()

getMaxCheckpointMessageAddSize

public int getMaxCheckpointMessageAddSize()

setMaxCheckpointMessageAddSize

public void setMaxCheckpointMessageAddSize(int maxCheckpointMessageAddSize)

getMaxCheckpointWorkers

public int getMaxCheckpointWorkers()

setMaxCheckpointWorkers

public void setMaxCheckpointWorkers(int maxCheckpointWorkers)

isUseExternalMessageReferences

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

setUseExternalMessageReferences

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

toPacket

public org.apache.activeio.packet.Packet toPacket(ByteSequence sequence)

toByteSequence

public ByteSequence toByteSequence(org.apache.activeio.packet.Packet packet)


Copyright © 2011 Apache Software Foundation. All Rights Reserved.