Class PrefetchSubscription

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

public abstract class PrefetchSubscription extends AbstractSubscription
A subscription that honors the pre-fetch option of the ConsumerInfo.
  • Field Details

    • scheduler

      protected final org.apache.activemq.thread.Scheduler scheduler
    • pending

      protected PendingMessageCursor pending
    • dispatched

      protected final List<org.apache.activemq.broker.region.MessageReference> dispatched
    • usageManager

      protected final SystemUsage usageManager
    • pendingLock

      protected final Object pendingLock
    • dispatchLock

      protected final Object dispatchLock
  • Constructor Details

    • PrefetchSubscription

      public PrefetchSubscription(Broker broker, SystemUsage usageManager, ConnectionContext context, org.apache.activemq.command.ConsumerInfo info, PendingMessageCursor cursor) throws jakarta.jms.JMSException
      Throws:
      jakarta.jms.JMSException
    • PrefetchSubscription

      public PrefetchSubscription(Broker broker, SystemUsage usageManager, ConnectionContext context, org.apache.activemq.command.ConsumerInfo info) throws jakarta.jms.JMSException
      Throws:
      jakarta.jms.JMSException
  • Method Details

    • pullMessage

      public org.apache.activemq.command.Response pullMessage(ConnectionContext context, org.apache.activemq.command.MessagePull pull) throws Exception
      Allows a message to be pulled on demand by a client
      Throws:
      Exception
    • add

      public void add(org.apache.activemq.broker.region.MessageReference node) throws Exception
      Description copied from interface: Subscription
      Used to add messages that match the subscription.
      Throws:
      Exception
      InterruptedException
      IOException
    • processMessageDispatchNotification

      public void processMessageDispatchNotification(org.apache.activemq.command.MessageDispatchNotification mdn) throws Exception
      Description copied from interface: Subscription
      Used by a Slave Broker to update dispatch infomation
      Throws:
      Exception
    • acknowledge

      public final void acknowledge(ConnectionContext context, org.apache.activemq.command.MessageAck ack) throws Exception
      Description copied from interface: Subscription
      Used when client acknowledge receipt of dispatched message.
      Specified by:
      acknowledge in interface Subscription
      Overrides:
      acknowledge in class AbstractSubscription
      Throws:
      IOException
      Exception
    • assertAckMatchesDispatched

      protected void assertAckMatchesDispatched(org.apache.activemq.command.MessageAck ack) throws jakarta.jms.JMSException
      Checks an ack versus the contents of the dispatched list. called with dispatchLock held
      Parameters:
      ack -
      Throws:
      jakarta.jms.JMSException - if it does not match
    • sendToDLQ

      protected void sendToDLQ(ConnectionContext context, org.apache.activemq.broker.region.MessageReference node, Throwable poisonCause) throws IOException, Exception
      Parameters:
      context -
      node -
      poisonCause -
      Throws:
      IOException
      Exception
    • getInFlightSize

      public int getInFlightSize()
      Returns:
      the number of messages awaiting acknowledgement
    • isFull

      public boolean isFull()
      Used to determine if the broker can dispatch to the consumer.
      Returns:
      true if the subscription is full
    • 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
    • countBeforeFull

      public int countBeforeFull()
      Specified by:
      countBeforeFull in interface Subscription
      Overrides:
      countBeforeFull in class AbstractSubscription
      Returns:
      the number of messages this subscription can accept before its full
    • getPendingQueueSize

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

      public long getPendingMessageSize()
      Returns:
      size of the 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:
    • getPending

      public PendingMessageCursor getPending()
    • setPending

      public void setPending(PendingMessageCursor pending)
    • add

      public void add(ConnectionContext context, Destination destination) throws 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:
      Exception
    • remove

      public List<org.apache.activemq.broker.region.MessageReference> remove(ConnectionContext context, Destination destination) throws 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
      Returns:
      a list of un-acked messages that were added to the subscription.
      Throws:
      Exception
    • remove

      public List<org.apache.activemq.broker.region.MessageReference> remove(ConnectionContext context, Destination destination, List<org.apache.activemq.broker.region.MessageReference> dispatched) throws Exception
      Throws:
      Exception
    • dispatchPending

      public void dispatchPending() throws IOException
      Throws:
      IOException
    • trackedInPendingTransaction

      protected boolean trackedInPendingTransaction(org.apache.activemq.broker.region.MessageReference node)
    • setPendingBatchSize

      protected void setPendingBatchSize(PendingMessageCursor pending, int numberToDispatch)
    • dispatch

      protected boolean dispatch(org.apache.activemq.broker.region.MessageReference node) throws IOException
      Throws:
      IOException
    • onDispatch

      protected void onDispatch(org.apache.activemq.broker.region.MessageReference node, org.apache.activemq.command.Message message)
    • updateConsumerPrefetch

      public void updateConsumerPrefetch(int newPrefetch)
      inform the MessageConsumer on the client to change it's prefetch
      Parameters:
      newPrefetch -
    • createMessageDispatch

      protected org.apache.activemq.command.MessageDispatch createMessageDispatch(org.apache.activemq.broker.region.MessageReference node, org.apache.activemq.command.Message message)
      Parameters:
      node -
      message -
      Returns:
      MessageDispatch
    • canDispatch

      protected abstract boolean canDispatch(org.apache.activemq.broker.region.MessageReference node) throws 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:
      IOException
    • isDropped

      protected abstract boolean isDropped(org.apache.activemq.broker.region.MessageReference node)
    • acknowledge

      protected abstract void acknowledge(ConnectionContext context, org.apache.activemq.command.MessageAck ack, org.apache.activemq.broker.region.MessageReference node) throws IOException
      Used during acknowledgment to remove the message.
      Throws:
      IOException
    • getMaxProducersToAudit

      public int getMaxProducersToAudit()
    • setMaxProducersToAudit

      public void setMaxProducersToAudit(int maxProducersToAudit)
    • getMaxAuditDepth

      public int getMaxAuditDepth()
    • setMaxAuditDepth

      public void setMaxAuditDepth(int maxAuditDepth)
    • setPrefetchSize

      public void setPrefetchSize(int prefetchSize)
      Overrides:
      setPrefetchSize in class AbstractSubscription