org.apache.activemq.broker.region
Class PrefetchSubscription

java.lang.Object
  extended by org.apache.activemq.broker.region.AbstractSubscription
      extended by org.apache.activemq.broker.region.PrefetchSubscription
All Implemented Interfaces:
Subscription
Direct Known Subclasses:
DurableTopicSubscription, QueueSubscription

public abstract class PrefetchSubscription
extends AbstractSubscription

A subscription that honors the pre-fetch option of the ConsumerInfo.

Version:
$Revision: 1.15 $

Field Summary
protected  java.util.LinkedList dispatched
           
protected  PendingMessageCursor pending
           
protected  int prefetchExtension
           
 
Fields inherited from class org.apache.activemq.broker.region.AbstractSubscription
broker, context, destinationFilter, destinations, info
 
Constructor Summary
PrefetchSubscription(Broker broker, ConnectionContext context, ConsumerInfo info)
           
PrefetchSubscription(Broker broker, ConnectionContext context, ConsumerInfo info, PendingMessageCursor cursor)
           
 
Method Summary
 void acknowledge(ConnectionContext context, MessageAck ack)
          Used when client acknowledge receipt of dispatched message.
protected  void acknowledge(ConnectionContext context, MessageAck ack, MessageReference node)
          Used during acknowledgment to remove the message.
 void add(ConnectionContext context, Destination destination)
          The subscription will be receiving messages from the destination.
 void add(MessageReference node)
          Used to add messages that match the subscription.
protected abstract  boolean canDispatch(MessageReference node)
          Use when a matched message is about to be dispatched to the client.
protected  MessageDispatch createMessageDispatch(MessageReference node, Message message)
           
protected  boolean dispatch(MessageReference node)
           
protected  void dispatchMatched()
           
 long getDequeueCounter()
           
 long getDispatchedCounter()
           
 int getDispatchedQueueSize()
           
 long getEnqueueCounter()
           
 int getPendingQueueSize()
           
protected  boolean isFull()
          Used to determine if the broker can dispatch to the consumer.
 boolean isHighWaterMark()
           
 boolean isLowWaterMark()
           
 boolean isRecoveryRequired()
          Informs the Broker if the subscription needs to intervention to recover it's state e.g.
protected  void onDispatch(MessageReference node, Message message)
           
 void optimizePrefetch()
          optimize message consumer prefetch if the consumer supports it
 void processMessageDispatchNotification(MessageDispatchNotification mdn)
          Used by a Slave Broker to update dispatch infomation
 Response pullMessage(ConnectionContext context, MessagePull pull)
          Allows a message to be pulled on demand by a client
 void remove(ConnectionContext context, Destination destination)
          The subscription will be no longer be receiving messages from the destination.
protected  void sendToDLQ(ConnectionContext context, MessageReference node)
           
 void updateConsumerPrefetch(int newPrefetch)
          inform the MessageConsumer on the client to change it's prefetch
 
Methods inherited from class org.apache.activemq.broker.region.AbstractSubscription
gc, getConsumerInfo, getContext, getInfo, getObjectName, getPrefetchSize, getSelector, getSelectorExpression, isSlaveBroker, matches, matches, setObjectName, setSelector
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.apache.activemq.broker.region.Subscription
destroy
 

Field Detail

pending

protected final PendingMessageCursor pending

dispatched

protected final java.util.LinkedList dispatched

prefetchExtension

protected int prefetchExtension
Constructor Detail

PrefetchSubscription

public PrefetchSubscription(Broker broker,
                            ConnectionContext context,
                            ConsumerInfo info,
                            PendingMessageCursor cursor)
                     throws javax.jms.InvalidSelectorException
Throws:
javax.jms.InvalidSelectorException

PrefetchSubscription

public PrefetchSubscription(Broker broker,
                            ConnectionContext context,
                            ConsumerInfo info)
                     throws javax.jms.InvalidSelectorException
Throws:
javax.jms.InvalidSelectorException
Method Detail

pullMessage

public Response pullMessage(ConnectionContext context,
                            MessagePull pull)
                     throws java.lang.Exception
Allows a message to be pulled on demand by a client

Throws:
java.lang.Exception

add

public void add(MessageReference node)
         throws java.lang.Exception
Description copied from interface: Subscription
Used to add messages that match the subscription.

Throws:
java.lang.InterruptedException
java.io.IOException
java.lang.Exception

processMessageDispatchNotification

public void processMessageDispatchNotification(MessageDispatchNotification mdn)
                                        throws java.lang.Exception
Description copied from interface: Subscription
Used by a Slave Broker to update dispatch infomation

Throws:
java.lang.Exception

acknowledge

public void acknowledge(ConnectionContext context,
                        MessageAck ack)
                 throws java.lang.Exception
Description copied from interface: Subscription
Used when client acknowledge receipt of dispatched message.

Throws:
java.io.IOException
java.lang.Exception

sendToDLQ

protected void sendToDLQ(ConnectionContext context,
                         MessageReference node)
                  throws java.io.IOException,
                         java.lang.Exception
Parameters:
context -
node -
Throws:
java.io.IOException
java.lang.Exception

isFull

protected boolean isFull()
Used to determine if the broker can dispatch to the consumer.

Returns:

isLowWaterMark

public boolean isLowWaterMark()
Returns:
true when 60% or more room is left for dispatching messages

isHighWaterMark

public boolean isHighWaterMark()
Returns:
true when 10% or less room is left for dispatching messages

getPendingQueueSize

public int getPendingQueueSize()
Returns:
number of messages pending delivery

getDispatchedQueueSize

public int getDispatchedQueueSize()
Returns:
number of messages dispatched to the client

getDequeueCounter

public long getDequeueCounter()
Returns:
number of messages queued by the client

getDispatchedCounter

public long getDispatchedCounter()
Returns:
number of messages dispatched to the client

getEnqueueCounter

public long getEnqueueCounter()
Returns:
number of messages that matched the subscription

isRecoveryRequired

public boolean isRecoveryRequired()
Description copied from interface: Subscription
Informs the Broker if the subscription needs to intervention to recover it's state e.g. DurableTopicSubscriber may do

Specified by:
isRecoveryRequired in interface Subscription
Overrides:
isRecoveryRequired in class AbstractSubscription
Returns:
true if recovery required
See Also:
org.apache.activemq.region.cursors.PendingMessageCursor

optimizePrefetch

public void optimizePrefetch()
optimize message consumer prefetch if the consumer supports it


add

public void add(ConnectionContext context,
                Destination destination)
         throws java.lang.Exception
Description copied from interface: Subscription
The subscription will be receiving messages from the destination.

Specified by:
add in interface Subscription
Overrides:
add in class AbstractSubscription
Throws:
java.lang.Exception

remove

public void remove(ConnectionContext context,
                   Destination destination)
            throws java.lang.Exception
Description copied from interface: Subscription
The subscription will be no longer be receiving messages from the destination.

Specified by:
remove in interface Subscription
Overrides:
remove in class AbstractSubscription
Throws:
java.lang.Exception

dispatchMatched

protected void dispatchMatched()
                        throws java.io.IOException
Throws:
java.io.IOException

dispatch

protected boolean dispatch(MessageReference node)
                    throws java.io.IOException
Throws:
java.io.IOException

onDispatch

protected void onDispatch(MessageReference node,
                          Message message)

updateConsumerPrefetch

public void updateConsumerPrefetch(int newPrefetch)
inform the MessageConsumer on the client to change it's prefetch

Parameters:
newPrefetch -

createMessageDispatch

protected MessageDispatch createMessageDispatch(MessageReference node,
                                                Message message)
Parameters:
node -
message -
Returns:
MessageDispatch

canDispatch

protected abstract boolean canDispatch(MessageReference node)
                                throws java.io.IOException
Use when a matched message is about to be dispatched to the client.

Parameters:
node -
Returns:
false if the message should not be dispatched to the client (another sub may have already dispatched it for example).
Throws:
java.io.IOException

acknowledge

protected void acknowledge(ConnectionContext context,
                           MessageAck ack,
                           MessageReference node)
                    throws java.io.IOException
Used during acknowledgment to remove the message.

Throws:
java.io.IOException


Copyright © 2011 Apache Software Foundation. All Rights Reserved.