Class FederationAddressPolicyManager
- java.lang.Object
-
- org.apache.activemq.artemis.protocol.amqp.federation.internal.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 Summary
Fields Modifier and Type Field Description protected Map<String,FederationAddressEntry>demandTrackingprotected Map<org.apache.activemq.artemis.core.postoffice.impl.DivertBinding,Set<org.apache.activemq.artemis.core.postoffice.QueueBinding>>divertsTrackingprotected FederationInternalfederationprotected FederationReceiveFromAddressPolicypolicyprotected org.apache.activemq.artemis.core.server.ActiveMQServerserver
-
Constructor Summary
Constructors Constructor Description FederationAddressPolicyManager(FederationInternal federation, FederationReceiveFromAddressPolicy addressPolicy)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description voidafterAddAddress(org.apache.activemq.artemis.core.server.impl.AddressInfo addressInfo, boolean reload)voidafterAddBinding(org.apache.activemq.artemis.core.postoffice.Binding binding)voidafterRemoteAddressAdded(String addressName)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.voidafterRemoveAddress(SimpleString address, org.apache.activemq.artemis.core.server.impl.AddressInfo addressInfo)voidafterRemoveBinding(org.apache.activemq.artemis.core.postoffice.Binding binding, org.apache.activemq.artemis.core.transaction.Transaction tx, boolean deleteData)protected voidcheckBindingForMatch(org.apache.activemq.artemis.core.postoffice.Binding binding)Called under lock this method should check if the givenBindingmatches the configured address federation policy and federate the address if so.protected FederationAddressEntrycreateConsumerEntry(org.apache.activemq.artemis.core.server.impl.AddressInfo addressInfo)Creates aFederationAddressEntryinstance that will be used to store an instance of anFederationConsumeralong with other state data needed to manage a federation consumer instance lifetime.protected abstract FederationConsumerInfocreateConsumerInfo(org.apache.activemq.artemis.core.server.impl.AddressInfo address)Create a newFederationConsumerInfobased on the givenAddressInfoand the configuredFederationReceiveFromAddressPolicy.protected abstract FederationConsumerInternalcreateFederationConsumer(FederationConsumerInfo consumerInfo)Create a newFederationConsumerInternalinstance using the consumer information given.protected voidcreateOrUpdateFederatedAddressConsumerForBinding(org.apache.activemq.artemis.core.server.impl.AddressInfo addressInfo, org.apache.activemq.artemis.core.postoffice.Binding binding)protected abstract voidhandlePolicyManagerStarted(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.protected abstract booleanisPluginBlockingFederationConsumerCreate(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.protected abstract booleanisPluginBlockingFederationConsumerCreate(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.protected abstract booleanisPluginBlockingFederationConsumerCreate(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.protected voidreactIfAnyQueueBindingMatchesDivertTarget(org.apache.activemq.artemis.core.postoffice.impl.DivertBinding divertBinding)protected voidreactIfQueueBindingMatchesAnyDivertTarget(org.apache.activemq.artemis.core.postoffice.QueueBinding queueBinding)protected voidscanAllBindings()Scans all bindings and push them through the normal bindings checks that would be done on an add.protected abstract voidsignalAfterCloseFederationConsumer(FederationConsumer consumer)Signal any registered plugins for this federation instance that a remote Address consumer has now been closed.protected abstract voidsignalAfterCreateFederationConsumer(FederationConsumer consumer)Signal any registered plugins for this federation instance that a remote Address consumer has been created.protected abstract voidsignalBeforeCloseFederationConsumer(FederationConsumer consumer)Signal any registered plugins for this federation instance that a remote Address consumer is about to be closed.protected abstract voidsignalBeforeCreateFederationConsumer(FederationConsumerInfo info)Signal any registered plugins for this federation instance that a remote Address consumer is being created.voidstart()Start the address policy manager which will initiate a scan of all broker divert bindings and create and matching remote receivers.voidstop()Stops the address policy manager which will close any open remote receivers that are active for local queue demand.protected booleantestIfAddressMatchesPolicy(String address, RoutingType type)Performs the test against the configured address policy to check if the target address is a match or not.protected booleantestIfAddressMatchesPolicy(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.protected voidtryRemoveDemandOnAddress(FederationAddressEntry entry, org.apache.activemq.artemis.core.postoffice.Binding binding)-
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.artemis.core.server.plugin.ActiveMQServerAddressPlugin
afterUpdateAddress, beforeAddAddress, beforeRemoveAddress, beforeUpdateAddress
-
Methods inherited from interface org.apache.activemq.artemis.core.server.plugin.ActiveMQServerBasePlugin
init, registered, setInit, unregistered
-
Methods inherited from interface org.apache.activemq.artemis.core.server.plugin.ActiveMQServerBindingPlugin
beforeAddBinding, beforeRemoveBinding
-
-
-
-
Field Detail
-
server
protected final org.apache.activemq.artemis.core.server.ActiveMQServer server
-
federation
protected final FederationInternal federation
-
policy
protected final FederationReceiveFromAddressPolicy policy
-
demandTracking
protected final Map<String,FederationAddressEntry> demandTracking
-
-
Constructor Detail
-
FederationAddressPolicyManager
public FederationAddressPolicyManager(FederationInternal federation, FederationReceiveFromAddressPolicy addressPolicy) throws ActiveMQException
- Throws:
ActiveMQException
-
-
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 parentFederationis 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 parentFederationloses its connection to the remote.
-
afterRemoveAddress
public void afterRemoveAddress(SimpleString address, org.apache.activemq.artemis.core.server.impl.AddressInfo addressInfo) throws ActiveMQException
- Specified by:
afterRemoveAddressin interfaceActiveMQServerAddressPlugin- Throws:
ActiveMQException
-
afterRemoveBinding
public void afterRemoveBinding(org.apache.activemq.artemis.core.postoffice.Binding binding, org.apache.activemq.artemis.core.transaction.Transaction tx, boolean deleteData) throws ActiveMQException- Specified by:
afterRemoveBindingin interfaceActiveMQServerBindingPlugin- Throws:
ActiveMQException
-
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:
afterAddAddressin interfaceActiveMQServerAddressPlugin
-
afterAddBinding
public void afterAddBinding(org.apache.activemq.artemis.core.postoffice.Binding binding)
- Specified by:
afterAddBindingin interfaceActiveMQServerBindingPlugin
-
checkBindingForMatch
protected final void checkBindingForMatch(org.apache.activemq.artemis.core.postoffice.Binding binding)
Called under lock this method should check if the givenBindingmatches the configured address federation policy and federate the address if so. The incomingBindingcan be either aQueueBindingor aDivertBindingso 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:
trueif 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:
trueif 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 newFederationConsumerInfobased on the givenAddressInfoand the configuredFederationReceiveFromAddressPolicy. A subclass must override this method to return a consumer information object with the data used be that implementation.- Parameters:
address- TheAddressInfoto use as a basis for the consumer information object.- Returns:
- a new
FederationConsumerInfoinstance based on the given address.
-
createConsumerEntry
protected FederationAddressEntry createConsumerEntry(org.apache.activemq.artemis.core.server.impl.AddressInfo addressInfo)
Creates aFederationAddressEntryinstance that will be used to store an instance of anFederationConsumeralong 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
FederationAddressEntrythat tracks demand on an address.
-
createFederationConsumer
protected abstract FederationConsumerInternal createFederationConsumer(FederationConsumerInfo consumerInfo)
Create a newFederationConsumerInternalinstance 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- TheFederationConsumerInfothat defines the consumer to be created.- Returns:
- a new
FederationConsumerInternalinstance 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- TheFederationConsumerInfothat 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- TheFederationConsumerInfothat 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- TheFederationConsumerthat 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- TheFederationConsumerthat 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- TheDivertthat triggered the manager to attempt to create a remote consumer.queue- TheQueuethat 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- TheQueuethat triggered the manager to attempt to create a remote consumer.- Returns:
- true if any registered plugin signaled that creation should be suppressed.
-
-