Class FederationAddressPolicyManager

  • All Implemented Interfaces:
    ActiveMQServerAddressPlugin, ActiveMQServerBasePlugin, ActiveMQServerBindingPlugin
    Direct Known Subclasses:
    AMQPFederationAddressPolicyManager

    public abstract class FederationAddressPolicyManager
    extends Object
    implements ActiveMQServerBindingPlugin, ActiveMQServerAddressPlugin
    Manager for a federation which has address federation configuration which requires monitoring broker addresses and diverts for demand and creating a consumer on the remote side to federate messages back to this peer. Address federation replicates messages from the remote broker's address to an address on this broker but only when there is local demand on that address. If there is no local demand then federation if already established is halted. The manager creates a remote consumer on the federated address without any filtering other than that required for internal functionality in order to allow for a single remote consumer which can federate all messages to the local side where the existing queues can apply any filtering they have in place.
    • Field Detail

      • server

        protected final org.apache.activemq.artemis.core.server.ActiveMQServer server
      • divertsTracking

        protected final Map<org.apache.activemq.artemis.core.postoffice.impl.DivertBinding,​Set<org.apache.activemq.artemis.core.postoffice.QueueBinding>> divertsTracking
    • Method Detail

      • start

        public void start()
        Start the address policy manager which will initiate a scan of all broker divert bindings and create and matching remote receivers. Start on a policy manager should only be called after its parent Federation is started and the federation connection has been established.
      • stop

        public void stop()
        Stops the address policy manager which will close any open remote receivers that are active for local queue demand. Stop should generally be called whenever the parent Federation loses its connection to the remote.
      • tryRemoveDemandOnAddress

        protected final void tryRemoveDemandOnAddress​(FederationAddressEntry entry,
                                                      org.apache.activemq.artemis.core.postoffice.Binding binding)
      • scanAllBindings

        protected final void scanAllBindings()
        Scans all bindings and push them through the normal bindings checks that would be done on an add. We filter here based on whether diverts are enabled just to reduce the result set but the check call should also filter as during normal operations divert bindings could be added.
      • afterAddAddress

        public void afterAddAddress​(org.apache.activemq.artemis.core.server.impl.AddressInfo addressInfo,
                                    boolean reload)
        Specified by:
        afterAddAddress in interface ActiveMQServerAddressPlugin
      • checkBindingForMatch

        protected final void checkBindingForMatch​(org.apache.activemq.artemis.core.postoffice.Binding binding)
        Called under lock this method should check if the given Binding matches the configured address federation policy and federate the address if so. The incoming Binding can be either a QueueBinding or a DivertBinding so the code should check both.
        Parameters:
        binding - The binding that should be checked against the federated address policy,
      • reactIfAnyQueueBindingMatchesDivertTarget

        protected final void reactIfAnyQueueBindingMatchesDivertTarget​(org.apache.activemq.artemis.core.postoffice.impl.DivertBinding divertBinding)
      • reactIfQueueBindingMatchesAnyDivertTarget

        protected final void reactIfQueueBindingMatchesAnyDivertTarget​(org.apache.activemq.artemis.core.postoffice.QueueBinding queueBinding)
      • createOrUpdateFederatedAddressConsumerForBinding

        protected final void createOrUpdateFederatedAddressConsumerForBinding​(org.apache.activemq.artemis.core.server.impl.AddressInfo addressInfo,
                                                                              org.apache.activemq.artemis.core.postoffice.Binding binding)
      • afterRemoteAddressAdded

        public void afterRemoteAddressAdded​(String addressName)
                                     throws Exception
        Checks if the remote address added falls within the set of addresses that match the configured address policy and if so scans for local demand on that address to see if a new attempt to federate the address is needed.
        Parameters:
        addressName - The address that was added on the remote.
        Throws:
        Exception - if an error occurs while processing the address added event.
      • testIfAddressMatchesPolicy

        protected boolean testIfAddressMatchesPolicy​(org.apache.activemq.artemis.core.server.impl.AddressInfo addressInfo)
        Performs the test against the configured address policy to check if the target address is a match or not. A subclass can override this method and provide its own match tests in combination with the configured matching policy.
        Parameters:
        addressInfo - The address that is being tested for a policy match.
        Returns:
        true if the address given is a match against the policy.
      • testIfAddressMatchesPolicy

        protected boolean testIfAddressMatchesPolicy​(String address,
                                                     RoutingType type)
        Performs the test against the configured address policy to check if the target address is a match or not. A subclass can override this method and provide its own match tests in combination with the configured matching policy.
        Parameters:
        address - The address that is being tested for a policy match.
        type - The routing type of the address to test against the policy.
        Returns:
        true if the address given is a match against the policy.
      • handlePolicyManagerStarted

        protected abstract void handlePolicyManagerStarted​(FederationReceiveFromAddressPolicy policy)
        Called on start of the manager before any other actions are taken to allow the subclass time to configure itself and prepare any needed state prior to starting management of federated resources.
        Parameters:
        policy - The policy configuration for this policy manager.
      • createConsumerInfo

        protected abstract FederationConsumerInfo createConsumerInfo​(org.apache.activemq.artemis.core.server.impl.AddressInfo address)
        Create a new FederationConsumerInfo based on the given AddressInfo and the configured FederationReceiveFromAddressPolicy. A subclass must override this method to return a consumer information object with the data used be that implementation.
        Parameters:
        address - The AddressInfo to use as a basis for the consumer information object.
        Returns:
        a new FederationConsumerInfo instance based on the given address.
      • createConsumerEntry

        protected FederationAddressEntry createConsumerEntry​(org.apache.activemq.artemis.core.server.impl.AddressInfo addressInfo)
        Creates a FederationAddressEntry instance that will be used to store an instance of an FederationConsumer along with other state data needed to manage a federation consumer instance lifetime. A subclass can override this method to return a more customized entry type with additional state data.
        Parameters:
        addressInfo - The address information that the created entry is meant to track demand for.
        Returns:
        a new FederationAddressEntry that tracks demand on an address.
      • createFederationConsumer

        protected abstract FederationConsumerInternal createFederationConsumer​(FederationConsumerInfo consumerInfo)
        Create a new FederationConsumerInternal instance using the consumer information given. This is called when local demand for a matched queue requires a new consumer to be created. This method by default will call the configured consumer factory function that was provided when the manager was created, a subclass can override this to perform additional actions for the create operation.
        Parameters:
        consumerInfo - The FederationConsumerInfo that defines the consumer to be created.
        Returns:
        a new FederationConsumerInternal instance that will reside in this manager.
      • signalBeforeCreateFederationConsumer

        protected abstract void signalBeforeCreateFederationConsumer​(FederationConsumerInfo info)
        Signal any registered plugins for this federation instance that a remote Address consumer is being created.
        Parameters:
        info - The FederationConsumerInfo that describes the remote Address consumer
      • signalAfterCreateFederationConsumer

        protected abstract void signalAfterCreateFederationConsumer​(FederationConsumer consumer)
        Signal any registered plugins for this federation instance that a remote Address consumer has been created.
        Parameters:
        consumer - The FederationConsumerInfo that describes the remote Address consumer
      • signalBeforeCloseFederationConsumer

        protected abstract void signalBeforeCloseFederationConsumer​(FederationConsumer consumer)
        Signal any registered plugins for this federation instance that a remote Address consumer is about to be closed.
        Parameters:
        consumer - The FederationConsumer that that is about to be closed.
      • signalAfterCloseFederationConsumer

        protected abstract void signalAfterCloseFederationConsumer​(FederationConsumer consumer)
        Signal any registered plugins for this federation instance that a remote Address consumer has now been closed.
        Parameters:
        consumer - The FederationConsumer that that has been closed.
      • isPluginBlockingFederationConsumerCreate

        protected abstract boolean isPluginBlockingFederationConsumerCreate​(org.apache.activemq.artemis.core.server.impl.AddressInfo address)
        Query all registered plugins for this federation instance to determine if any wish to prevent a federation consumer from being created for the given Queue.
        Parameters:
        address - The address on which the manager is intending to create a remote consumer for.
        Returns:
        true if any registered plugin signaled that creation should be suppressed.
      • isPluginBlockingFederationConsumerCreate

        protected abstract boolean isPluginBlockingFederationConsumerCreate​(org.apache.activemq.artemis.core.server.Divert divert,
                                                                            org.apache.activemq.artemis.core.server.Queue queue)
        Query all registered plugins for this federation instance to determine if any wish to prevent a federation consumer from being created for the given Queue.
        Parameters:
        divert - The Divert that triggered the manager to attempt to create a remote consumer.
        queue - The Queue that triggered the manager to attempt to create a remote consumer.
        Returns:
        true if any registered plugin signaled that creation should be suppressed.
      • isPluginBlockingFederationConsumerCreate

        protected abstract boolean isPluginBlockingFederationConsumerCreate​(org.apache.activemq.artemis.core.server.Queue queue)
        Query all registered plugins for this federation instance to determine if any wish to prevent a federation consumer from being created for the given Queue.
        Parameters:
        queue - The Queue that triggered the manager to attempt to create a remote consumer.
        Returns:
        true if any registered plugin signaled that creation should be suppressed.