Class JournalPersistenceAdapter
- java.lang.Object
-
- org.apache.activemq.store.journal.JournalPersistenceAdapter
-
- All Implemented Interfaces:
org.apache.activeio.journal.JournalEventListener,BrokerServiceAware,Service,PersistenceAdapter,UsageListener
public class JournalPersistenceAdapter extends Object implements PersistenceAdapter, org.apache.activeio.journal.JournalEventListener, UsageListener, BrokerServiceAware
An implementation ofPersistenceAdapterdesigned for use with aJournaland then check pointing asynchronously on a timeout with some other long term persistent storage.
-
-
Constructor Summary
Constructors Constructor Description JournalPersistenceAdapter()JournalPersistenceAdapter(org.apache.activeio.journal.Journal journal, PersistenceAdapter longTermPersistence, TaskRunnerFactory taskRunnerFactory)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidallowIOResumption()voidbeginTransaction(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.voidcheckpoint(boolean sync)checkpoint anyvoidcheckpoint(boolean sync, boolean fullCheckpoint)When we checkpoint we move all the journalled data to long term storage.voidcommitTransaction(ConnectionContext context)Commit a persistence transactionJobSchedulerStorecreateJobSchedulerStore()Creates and returns a new Job Scheduler store instance.MessageStorecreateQueueMessageStore(ActiveMQQueue destination)Factory method to create a new queue message store with the given destination nameprotected IOExceptioncreateRecoveryFailedException(Exception e)TopicMessageStorecreateTopicMessageStore(ActiveMQTopic destinationName)Factory method to create a new topic message store with the given destination nameTransactionStorecreateTransactionStore()Factory method to create a new persistent prepared transaction store for XA recoveryprotected IOExceptioncreateWriteException(String command, Exception e)protected IOExceptioncreateWriteException(DataStructure packet, Exception e)voiddeleteAllMessages()Delete's all the messages in the persistent store.booleandoCheckpoint()This does the actual checkpoint.longgetCheckpointInterval()Set<ActiveMQDestination>getDestinations()Returns a set of all theActiveMQDestinationobjects that the persistence store is aware exist.FilegetDirectory()longgetLastMessageBrokerSequenceId()longgetLastProducerSequenceId(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 occursPersistenceAdaptergetLongTermPersistence()intgetMaxCheckpointMessageAddSize()intgetMaxCheckpointWorkers()JournalTransactionStoregetTransactionStore()SystemUsagegetUsageManager()WireFormatgetWireFormat()booleanisUseExternalMessageReferences()voidonUsageChanged(Usage usage, int oldPercentUsage, int newPercentUsage)voidoverflowNotification(org.apache.activeio.journal.RecordLocation safeLocation)The Journal give us a call back so that we can move old data out of the journal.DataStructurereadCommand(org.apache.activeio.journal.RecordLocation location)voidremoveQueueMessageStore(ActiveMQQueue destination)Cleanup method to remove any state associated with the given destinationvoidremoveTopicMessageStore(ActiveMQTopic destination)Cleanup method to remove any state associated with the given destinationvoidrollbackTransaction(ConnectionContext context)Rollback a persistence transactionvoidsetBrokerName(String brokerName)Set the name of the broker using the adaptervoidsetBrokerService(BrokerService brokerService)voidsetCheckpointInterval(long checkpointInterval)voidsetDirectory(File dir)Set the directory where any data files should be createdvoidsetJournal(org.apache.activeio.journal.Journal journal)voidsetMaxCheckpointMessageAddSize(int maxCheckpointMessageAddSize)voidsetMaxCheckpointWorkers(int maxCheckpointWorkers)voidsetPersistenceAdapter(PersistenceAdapter longTermPersistence)voidsetTaskRunnerFactory(TaskRunnerFactory taskRunnerFactory)voidsetUsageManager(SystemUsage usageManager)voidsetUseExternalMessageReferences(boolean enable)longsize()A hint to return the size of the store on diskvoidstart()voidstop()ByteSequencetoByteSequence(org.apache.activeio.packet.Packet packet)org.apache.activeio.packet.PackettoPacket(ByteSequence sequence)StringtoString()org.apache.activeio.journal.RecordLocationwriteCommand(DataStructure command, boolean sync)
-
-
-
Field Detail
-
scheduler
protected Scheduler scheduler
-
-
Constructor Detail
-
JournalPersistenceAdapter
public JournalPersistenceAdapter()
-
JournalPersistenceAdapter
public JournalPersistenceAdapter(org.apache.activeio.journal.Journal journal, PersistenceAdapter longTermPersistence, TaskRunnerFactory taskRunnerFactory) throws IOException- Throws:
IOException
-
-
Method Detail
-
setTaskRunnerFactory
public void setTaskRunnerFactory(TaskRunnerFactory taskRunnerFactory)
-
setJournal
public void setJournal(org.apache.activeio.journal.Journal journal)
-
setPersistenceAdapter
public void setPersistenceAdapter(PersistenceAdapter longTermPersistence)
-
setUsageManager
public void setUsageManager(SystemUsage usageManager)
- Specified by:
setUsageManagerin interfacePersistenceAdapter- Parameters:
usageManager- The UsageManager that is controlling the destination's memory usage.
-
getDestinations
public Set<ActiveMQDestination> getDestinations()
Description copied from interface:PersistenceAdapterReturns a set of all theActiveMQDestinationobjects that the persistence store is aware exist.- Specified by:
getDestinationsin interfacePersistenceAdapter- Returns:
- active destinations
-
createQueueMessageStore
public MessageStore createQueueMessageStore(ActiveMQQueue destination) throws IOException
Description copied from interface:PersistenceAdapterFactory method to create a new queue message store with the given destination name- Specified by:
createQueueMessageStorein interfacePersistenceAdapter- Returns:
- the message store
- Throws:
IOException
-
createTopicMessageStore
public TopicMessageStore createTopicMessageStore(ActiveMQTopic destinationName) throws IOException
Description copied from interface:PersistenceAdapterFactory method to create a new topic message store with the given destination name- Specified by:
createTopicMessageStorein interfacePersistenceAdapter- Returns:
- the topic message store
- Throws:
IOException
-
removeQueueMessageStore
public void removeQueueMessageStore(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(ActiveMQTopic destination)
Cleanup method to remove any state associated with the given destination- Specified by:
removeTopicMessageStorein interfacePersistenceAdapter- Parameters:
destination- Destination to forget
-
createTransactionStore
public TransactionStore createTransactionStore() throws IOException
Description copied from interface:PersistenceAdapterFactory method to create a new persistent prepared transaction store for XA recovery- Specified by:
createTransactionStorein interfacePersistenceAdapter- Returns:
- transaction store
- Throws:
IOException
-
getLastMessageBrokerSequenceId
public long getLastMessageBrokerSequenceId() throws IOException- Specified by:
getLastMessageBrokerSequenceIdin interfacePersistenceAdapter- Returns:
- last broker sequence
- Throws:
IOException
-
beginTransaction
public void beginTransaction(ConnectionContext context) throws IOException
Description copied from interface:PersistenceAdapterThis 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:
beginTransactionin interfacePersistenceAdapter- Throws:
IOException
-
commitTransaction
public void commitTransaction(ConnectionContext context) throws IOException
Description copied from interface:PersistenceAdapterCommit a persistence transaction- Specified by:
commitTransactionin interfacePersistenceAdapter- Throws:
IOException- See Also:
PersistenceAdapter.beginTransaction(ConnectionContext context)
-
rollbackTransaction
public void rollbackTransaction(ConnectionContext context) throws IOException
Description copied from interface:PersistenceAdapterRollback a persistence transaction- Specified by:
rollbackTransactionin interfacePersistenceAdapter- Throws:
IOException- See Also:
PersistenceAdapter.beginTransaction(ConnectionContext context)
-
start
public void start() 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:
overflowNotificationin interfaceorg.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.
-
checkpoint
public void checkpoint(boolean sync)
Description copied from interface:PersistenceAdaptercheckpoint any- Specified by:
checkpointin interfacePersistenceAdapter
-
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
-
onUsageChanged
public void onUsageChanged(Usage usage, int oldPercentUsage, int newPercentUsage)
- Specified by:
onUsageChangedin interfaceUsageListener
-
getTransactionStore
public JournalTransactionStore getTransactionStore()
-
deleteAllMessages
public void deleteAllMessages() throws IOExceptionDescription copied from interface:PersistenceAdapterDelete's all the messages in the persistent store.- Specified by:
deleteAllMessagesin interfacePersistenceAdapter- Throws:
IOException
-
getUsageManager
public SystemUsage getUsageManager()
-
getMaxCheckpointMessageAddSize
public int getMaxCheckpointMessageAddSize()
-
setMaxCheckpointMessageAddSize
public void setMaxCheckpointMessageAddSize(int maxCheckpointMessageAddSize)
-
getMaxCheckpointWorkers
public int getMaxCheckpointWorkers()
-
setMaxCheckpointWorkers
public void setMaxCheckpointWorkers(int maxCheckpointWorkers)
-
getCheckpointInterval
public long getCheckpointInterval()
-
setCheckpointInterval
public void setCheckpointInterval(long checkpointInterval)
-
isUseExternalMessageReferences
public boolean isUseExternalMessageReferences()
-
setUseExternalMessageReferences
public void setUseExternalMessageReferences(boolean enable)
-
toPacket
public org.apache.activeio.packet.Packet toPacket(ByteSequence sequence)
-
toByteSequence
public ByteSequence toByteSequence(org.apache.activeio.packet.Packet packet)
-
setBrokerName
public void setBrokerName(String brokerName)
Description copied from interface:PersistenceAdapterSet the name of the broker using the adapter- Specified by:
setBrokerNamein interfacePersistenceAdapter
-
setDirectory
public void setDirectory(File dir)
Description copied from interface:PersistenceAdapterSet the directory where any data files should be created- Specified by:
setDirectoryin interfacePersistenceAdapter
-
getDirectory
public File getDirectory()
- Specified by:
getDirectoryin interfacePersistenceAdapter- Returns:
- the directory used by the persistence adaptor
-
size
public long size()
Description copied from interface:PersistenceAdapterA hint to return the size of the store on disk- Specified by:
sizein interfacePersistenceAdapter- Returns:
- disk space used in bytes of 0 if not implemented
-
setBrokerService
public void setBrokerService(BrokerService brokerService)
- Specified by:
setBrokerServicein interfaceBrokerServiceAware
-
getLastProducerSequenceId
public long getLastProducerSequenceId(ProducerId id)
Description copied from interface:PersistenceAdapterreturn the last stored producer sequenceId for this producer Id used to suppress duplicate sends on failover reconnect at the transport when a reconnect occurs- Specified by:
getLastProducerSequenceIdin interfacePersistenceAdapter- Parameters:
id- the producerId to find a sequenceId for- Returns:
- the last stored sequence id or -1 if no suppression needed
-
allowIOResumption
public void allowIOResumption()
- Specified by:
allowIOResumptionin interfacePersistenceAdapter
-
createJobSchedulerStore
public JobSchedulerStore createJobSchedulerStore() throws IOException, UnsupportedOperationException
Description copied from interface:PersistenceAdapterCreates and returns a new Job Scheduler store instance.- Specified by:
createJobSchedulerStorein interfacePersistenceAdapter- Returns:
- a new JobSchedulerStore instance if this Persistence adapter provides its own.
- Throws:
IOException- If an error occurs while creating the new JobSchedulerStore.UnsupportedOperationException- If this adapter does not provide its own scheduler store implementation.
-
-