org.apache.activemq.store.amq
Class AMQMessageStore

java.lang.Object
  extended by org.apache.activemq.store.amq.AMQMessageStore
All Implemented Interfaces:
Service, MessageStore
Direct Known Subclasses:
AMQTopicMessageStore

public class AMQMessageStore
extends Object
implements MessageStore

A MessageStore that uses a Journal to store it's messages.

Version:
$Revision: 1.14 $

Field Summary
protected  TaskRunner asyncWriteTask
           
protected  ActiveMQDestination destination
           
protected  CountDownLatch flushLatch
           
protected  Set<Location> inFlightTxLocations
           
protected  Location lastLocation
           
protected  Location lastWrittenLocation
           
protected  Lock lock
           
protected  AMQPersistenceAdapter peristenceAdapter
           
protected  ReferenceStore referenceStore
           
protected  AMQTransactionStore transactionStore
           
protected  TransactionTemplate transactionTemplate
           
 
Constructor Summary
AMQMessageStore(AMQPersistenceAdapter adapter, ReferenceStore referenceStore, ActiveMQDestination destination)
           
 
Method Summary
 void addMessage(ConnectionContext context, Message message)
          Not synchronize since the Journal has better throughput if you increase the number of concurrent writes that it is doing.
 void addMessageReference(ConnectionContext context, MessageId messageId, long expirationTime, String messageRef)
           
protected  Location doAsyncWrite()
           
 void flush()
          Waits till the lastest data has landed on the referenceStore
 ActiveMQDestination getDestination()
          The destination that the message store is holding messages for.
protected  Location getLocation(MessageId messageId)
           
 Location getMark()
           
 Message getMessage(MessageId identity)
          Looks up a message using either the String messageID or the messageNumber.
 int getMessageCount()
           
 String getMessageReference(MessageId identity)
           
 ReferenceStore getReferenceStore()
           
 void recover(MessageRecoveryListener listener)
          Replays the referenceStore first as those messages are the oldest ones, then messages are replayed from the transaction log and then the cache is updated.
 void recoverNextMessages(int maxReturned, MessageRecoveryListener listener)
           
 void removeAllMessages(ConnectionContext context)
          Removes all the messages from the message store.
 void removeMessage(ConnectionContext context, MessageAck ack)
          Removes a message from the message store.
 boolean replayAddMessage(ConnectionContext context, Message message, Location location)
           
 boolean replayRemoveMessage(ConnectionContext context, MessageAck messageAck)
           
 void resetBatching()
          A hint to the Store to reset any batching state for the Destination
 void setMemoryUsage(MemoryUsage memoryUsage)
           
 void start()
           
 void stop()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

peristenceAdapter

protected final AMQPersistenceAdapter peristenceAdapter

transactionStore

protected final AMQTransactionStore transactionStore

referenceStore

protected final ReferenceStore referenceStore

destination

protected final ActiveMQDestination destination

transactionTemplate

protected final TransactionTemplate transactionTemplate

lastLocation

protected Location lastLocation

lastWrittenLocation

protected Location lastWrittenLocation

inFlightTxLocations

protected Set<Location> inFlightTxLocations

asyncWriteTask

protected final TaskRunner asyncWriteTask

flushLatch

protected CountDownLatch flushLatch

lock

protected final Lock lock
Constructor Detail

AMQMessageStore

public AMQMessageStore(AMQPersistenceAdapter adapter,
                       ReferenceStore referenceStore,
                       ActiveMQDestination destination)
Method Detail

setMemoryUsage

public void setMemoryUsage(MemoryUsage memoryUsage)
Specified by:
setMemoryUsage in interface MessageStore
Parameters:
memoryUsage - The SystemUsage that is controlling the destination's memory usage.

addMessage

public final void addMessage(ConnectionContext context,
                             Message message)
                      throws IOException
Not synchronize since the Journal has better throughput if you increase the number of concurrent writes that it is doing.

Specified by:
addMessage in interface MessageStore
Parameters:
context - context
Throws:
IOException

replayAddMessage

public boolean replayAddMessage(ConnectionContext context,
                                Message message,
                                Location location)

removeMessage

public void removeMessage(ConnectionContext context,
                          MessageAck ack)
                   throws IOException
Description copied from interface: MessageStore
Removes a message from the message store.

Specified by:
removeMessage in interface MessageStore
ack - the ack request that cause the message to be removed. It conatins the identity which contains the messageID of the message that needs to be removed.
Throws:
IOException

replayRemoveMessage

public boolean replayRemoveMessage(ConnectionContext context,
                                   MessageAck messageAck)

flush

public void flush()
           throws InterruptedIOException
Waits till the lastest data has landed on the referenceStore

Throws:
InterruptedIOException

doAsyncWrite

protected Location doAsyncWrite()
                         throws IOException
Returns:
Throws:
IOException

getMessage

public Message getMessage(MessageId identity)
                   throws IOException
Description copied from interface: MessageStore
Looks up a message using either the String messageID or the messageNumber. Implementations are encouraged to fill in the missing key if its easy to do so.

Specified by:
getMessage in interface MessageStore
Parameters:
identity - which contains either the messageID or the messageNumber
Returns:
the message or null if it does not exist
Throws:
IOException

getLocation

protected Location getLocation(MessageId messageId)
                        throws IOException
Throws:
IOException

recover

public void recover(MessageRecoveryListener listener)
             throws Exception
Replays the referenceStore first as those messages are the oldest ones, then messages are replayed from the transaction log and then the cache is updated.

Specified by:
recover in interface MessageStore
Parameters:
listener -
Throws:
Exception

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

getReferenceStore

public ReferenceStore getReferenceStore()
Returns:
Returns the longTermStore.

removeAllMessages

public void removeAllMessages(ConnectionContext context)
                       throws IOException
Description copied from interface: MessageStore
Removes all the messages from the message store.

Specified by:
removeAllMessages in interface MessageStore
Throws:
IOException
See Also:
MessageStore.removeAllMessages(ConnectionContext)

getDestination

public ActiveMQDestination getDestination()
Description copied from interface: MessageStore
The destination that the message store is holding messages for.

Specified by:
getDestination in interface MessageStore
Returns:
the destination

addMessageReference

public void addMessageReference(ConnectionContext context,
                                MessageId messageId,
                                long expirationTime,
                                String messageRef)
                         throws IOException
Throws:
IOException

getMessageReference

public String getMessageReference(MessageId identity)
                           throws IOException
Throws:
IOException

getMessageCount

public int getMessageCount()
                    throws IOException
Specified by:
getMessageCount in interface MessageStore
Returns:
Throws:
IOException
See Also:
MessageStore.getMessageCount()

recoverNextMessages

public void recoverNextMessages(int maxReturned,
                                MessageRecoveryListener listener)
                         throws Exception
Specified by:
recoverNextMessages in interface MessageStore
Throws:
Exception

resetBatching

public void resetBatching()
Description copied from interface: MessageStore
A hint to the Store to reset any batching state for the Destination

Specified by:
resetBatching in interface MessageStore

getMark

public Location getMark()


Copyright © 2008 The Apache Software Foundation. All Rights Reserved.