Class AMQPFederationConsumer

java.lang.Object
org.apache.activemq.artemis.protocol.amqp.connect.federation.AMQPFederationConsumer
All Implemented Interfaces:
FederationConsumer
Direct Known Subclasses:
AMQPFederationAddressConsumer, AMQPFederationQueueConsumer

public abstract class AMQPFederationConsumer extends Object implements FederationConsumer
Base class for AMQP Federation consumers that implements some of the common functionality.
  • Field Details

  • Constructor Details

  • Method Details

    • getRole

      public final FederationConsumerInfo.Role getRole()
      Returns the type of federation consumer being represented.
      Returns:
      the type of federation consumer being represented
    • getMessagesReceived

      public final long getMessagesReceived()
      Returns the number of messages this consumer has received from the remote during its lifetime.
      Returns:
      the number of messages this consumer has received from the remote during its lifetime
    • getPolicyManager

      public AMQPFederationLocalPolicyManager getPolicyManager()
      Returns the federation policy manager that created this consumer instance.
      Returns:
      the federation policy manager that created this consumer instance
    • getConfiguration

      public AMQPFederationConsumerConfiguration getConfiguration()
      Returns the consumer configuration that was assigned to this federation consumer.
      Returns:
      the consumer configuration that was assigned to this federation consumer
    • getReceiverIdleTimeout

      public abstract int getReceiverIdleTimeout()
      Returns the idle timeout value that is used applied to quiesced receivers.
      Returns:
      the idle timeout value that is used applied to quiesced receivers
    • getFederation

      public final AMQPFederation getFederation()
      Description copied from interface: FederationConsumer
      Returns the Federation that this consumer operates under.
      Specified by:
      getFederation in interface FederationConsumer
      Returns:
      the Federation that this consumer operates under
    • getConsumerInfo

      public final FederationConsumerInfo getConsumerInfo()
      Description copied from interface: FederationConsumer
      Returns an information object that defines the characteristics of the FederationConsumer.
      Specified by:
      getConsumerInfo in interface FederationConsumer
      Returns:
      an information object that defines the characteristics of the FederationConsumer
    • isInitialized

      public final boolean isInitialized()
      Returns true if the consumer has previously been initialized.
      Returns:
      true if the consumer has previously been initialized
    • initialize

      public void initialize()
      Called to initialize the AMQP federation consumer which will trigger an asynchronous task to attach the link and handle all setup receiver and eventually start the flow of credit to the remote. This method should be called once after the basic configuration of the consumer is complete and should not be called again after that.
    • doCreateReceiver

      protected abstract void doCreateReceiver()
      Called during the initialization of the consumer to trigger an asynchronous link attach of the underlying AMQP receiver that backs this federation consumer. The new receiver should be initialized in a started state. This method executes on the connection thread and should not block. This method will be called from the thread of the connection this consumer operates on.
    • startAsync

      public final void startAsync(AMQPFederationAsyncCompletion<AMQPFederationConsumer> completion)
      Asynchronously starts a previously stopped federation consumer which should trigger a grant of credit to the remote thereby allowing new incoming messages to be federated. In general the start should only happen when the receiver is know to be stopped but given the asynchronous nature of the receiver handling this won't always be the case, below the outcomes of various cases that could result from calls to this method. The completion methods are always called from a different thread than this method is called in which means the caller should ensure that the handling accounts for thread safety of those methods.

      Calling start on an already closed consumer should immediately throw an IllegalStateException immediately. Calling start on an non-initialized consumer should immediately throw an IllegalStateException immediately.

      Calling start on a stopped consumer should start the consumer and signal success to the completion. Calling start on an already started consumer should simply signal success to the completion. Calling start on a stopping consumer should fail the completion with an IllegalStateException. Calling start on a consumer that closes while the start is in-flight should fail the completion with an IllegalStateException

      Parameters:
      completion - A AMQPFederationAsyncCompletion that will be notified when the stop request succeeds or fails.
    • stopAsync

      public final void stopAsync(AMQPFederationAsyncCompletion<AMQPFederationConsumer> completion)
      Stops message consumption on this consumer instance but leaves the consumer in a state where it could be restarted by a call to startAsync(AMQPFederationAsyncCompletion) once the consumer enters the stopped state.

      Since the request to stop can take time to complete and this method cannot block a completion must be provided by the caller that will respond when the consumer has fully come to rest and all pending work is complete. Before the stopped completion is signaled the state of the underlying consumer will be stopping and attempt to restart it should fail until the stopped state has been reached.

      The supplied AMQPFederationAsyncCompletion will be completed successfully once the underling AMQP receiver has drained and pending work is completed. If the stop does not complete by the supplied timeout the completion will be signaled that a failure has occurred with a TimeoutException. The completion methods are always called from a different thread than this method is called in which means the caller should ensure that the handling accounts for thread safety of those methods.

      Parameters:
      completion - A AMQPFederationAsyncCompletion that will be notified when the stop request succeeds or fails.
    • close

      public final void close()
      Close the federation consumer instance and cleans up its resources. This method should not block and the actual resource shutdown work should occur asynchronously however the closed state should be indicated immediately and any further attempts start the consumer should result in an exception being thrown.
    • isClosed

      public boolean isClosed()
      Returns true if the receiver has already been closed.
      Returns:
      true if the receiver has already been closed
    • setRemoteOpenHandler

      public final AMQPFederationConsumer setRemoteOpenHandler(Consumer<AMQPFederationConsumer> handler)
      Provides and event point for notification of the receiver having been opened successfully by the remote. This handler will not be called if the remote rejects the link attach and a Detach is expected to follow.
      Parameters:
      handler - The handler that will be invoked when the remote opens this receiver.
      Returns:
      this receiver instance
    • setRemoteClosedHandler

      public final AMQPFederationConsumer setRemoteClosedHandler(Consumer<AMQPFederationConsumer> handler)
      Provides and event point for notification of the consumer having been closed by the remote.
      Parameters:
      handler - The handler that will be invoked when the remote closes this consumer.
      Returns:
      this consumer instance
    • remoteLinkClosedInterceptor

      protected final boolean remoteLinkClosedInterceptor(org.apache.qpid.proton.engine.Link link)
    • recordFederatedMessageReceived

      protected final void recordFederatedMessageReceived(Message message)
      Called from a subclass upon handling an incoming federated message from the remote.
      Parameters:
      message - The original message that arrived from the remote.
    • signalPluginBeforeFederationConsumerMessageHandled

      protected final void signalPluginBeforeFederationConsumerMessageHandled(Message message) throws ActiveMQException
      Called before the message is dispatched to the broker for processing.
      Parameters:
      message - The message after any processing which is about to be dispatched.
      Throws:
      ActiveMQException - if any broker plugin throws an exception during its processing.
    • signalPluginAfterFederationConsumerMessageHandled

      protected final void signalPluginAfterFederationConsumerMessageHandled(Message message) throws ActiveMQException
      Called after the message is dispatched to the broker for processing.
      Parameters:
      message - The message after any processing which has been dispatched to the broker.
      Throws:
      ActiveMQException - if any broker plugin throws an exception during its processing.