Class AbortSlowConsumerStrategy
- java.lang.Object
-
- org.apache.activemq.broker.region.policy.AbortSlowConsumerStrategy
-
- All Implemented Interfaces:
Runnable,SlowConsumerStrategy
- Direct Known Subclasses:
AbortSlowAckConsumerStrategy
public class AbortSlowConsumerStrategy extends Object implements SlowConsumerStrategy, Runnable
Abort slow consumers when they reach the configured threshold of slowness, default is slow for 30 seconds
-
-
Field Summary
Fields Modifier and Type Field Description protected Brokerbrokerprotected Stringnameprotected Schedulerschedulerprotected Map<Subscription,SlowConsumerEntry>slowConsumersprotected AtomicBooleantaskStarted
-
Constructor Summary
Constructors Constructor Description AbortSlowConsumerStrategy()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidabortConsumer(Subscription sub, boolean abortSubscriberConnection)protected voidabortSubscription(Map<Subscription,SlowConsumerEntry> toAbort, boolean abortSubscriberConnection)voidaddDestination(Destination destination)For Strategies that need to examine assigned destination for slow consumers periodically the destination is assigned here.longgetCheckPeriod()longgetMaxSlowCount()longgetMaxSlowDuration()StringgetName()Map<Subscription,SlowConsumerEntry>getSlowConsumers()booleanisAbortConnection()booleanisIgnoreNetworkSubscriptions()Returns whether the strategy is configured to ignore subscriptions that are from a network connection.voidrun()voidsetAbortConnection(boolean abortConnection)abort the consumers connection rather than sending a stop command to the remote consumervoidsetBrokerService(Broker broker)Sets the Broker instance which can provide a Scheduler among other things.voidsetCheckPeriod(long checkPeriod)time in milliseconds between checks for slow subscriptionsvoidsetIgnoreNetworkConsumers(boolean ignoreNetworkConsumers)Sets whether the strategy is configured to ignore consumers that are part of a network connection to another broker.voidsetMaxSlowCount(long maxSlowCount)number of times a subscription can be deemed slow before triggering abort effect depends on dispatch rate as slow determination is done on dispatchvoidsetMaxSlowDuration(long maxSlowDuration)time in milliseconds that a sub can remain slow before triggering an abort.voidsetName(String name)voidslowConsumer(ConnectionContext context, Subscription subs)Slow consumer event.
-
-
-
Field Detail
-
name
protected String name
-
scheduler
protected Scheduler scheduler
-
broker
protected Broker broker
-
taskStarted
protected final AtomicBoolean taskStarted
-
slowConsumers
protected final Map<Subscription,SlowConsumerEntry> slowConsumers
-
-
Method Detail
-
setBrokerService
public void setBrokerService(Broker broker)
Description copied from interface:SlowConsumerStrategySets the Broker instance which can provide a Scheduler among other things.- Specified by:
setBrokerServicein interfaceSlowConsumerStrategy- Parameters:
broker- The running Broker.
-
slowConsumer
public void slowConsumer(ConnectionContext context, Subscription subs)
Description copied from interface:SlowConsumerStrategySlow consumer event.- Specified by:
slowConsumerin interfaceSlowConsumerStrategy- Parameters:
context- Connection context of the subscription.subs- The subscription object for the slow consumer.
-
abortSubscription
protected void abortSubscription(Map<Subscription,SlowConsumerEntry> toAbort, boolean abortSubscriberConnection)
-
abortConsumer
public void abortConsumer(Subscription sub, boolean abortSubscriberConnection)
-
getMaxSlowCount
public long getMaxSlowCount()
-
setMaxSlowCount
public void setMaxSlowCount(long maxSlowCount)
number of times a subscription can be deemed slow before triggering abort effect depends on dispatch rate as slow determination is done on dispatch
-
getMaxSlowDuration
public long getMaxSlowDuration()
-
setMaxSlowDuration
public void setMaxSlowDuration(long maxSlowDuration)
time in milliseconds that a sub can remain slow before triggering an abort.- Parameters:
maxSlowDuration-
-
getCheckPeriod
public long getCheckPeriod()
-
setCheckPeriod
public void setCheckPeriod(long checkPeriod)
time in milliseconds between checks for slow subscriptions- Parameters:
checkPeriod-
-
isAbortConnection
public boolean isAbortConnection()
-
setAbortConnection
public void setAbortConnection(boolean abortConnection)
abort the consumers connection rather than sending a stop command to the remote consumer- Parameters:
abortConnection-
-
isIgnoreNetworkSubscriptions
public boolean isIgnoreNetworkSubscriptions()
Returns whether the strategy is configured to ignore subscriptions that are from a network connection.- Returns:
- true if the strategy will ignore network connection subscriptions when looking for slow consumers.
-
setIgnoreNetworkConsumers
public void setIgnoreNetworkConsumers(boolean ignoreNetworkConsumers)
Sets whether the strategy is configured to ignore consumers that are part of a network connection to another broker. When configured to not ignore idle consumers this strategy acts not only on consumers that are actually slow but also on any consumer that has not received any messages for the maxTimeSinceLastAck. This allows for a way to evict idle consumers while also aborting slow consumers however for a network subscription this can create a lot of unnecessary churn and if the abort connection option is also enabled this can result in the entire network connection being torn down and rebuilt for no reason.- Parameters:
ignoreNetworkConsumers- Should this strategy ignore subscriptions made by a network connector.
-
setName
public void setName(String name)
-
getName
public String getName()
-
getSlowConsumers
public Map<Subscription,SlowConsumerEntry> getSlowConsumers()
-
addDestination
public void addDestination(Destination destination)
Description copied from interface:SlowConsumerStrategyFor Strategies that need to examine assigned destination for slow consumers periodically the destination is assigned here. If the strategy doesn't is event driven it can just ignore assigned destination.- Specified by:
addDestinationin interfaceSlowConsumerStrategy- Parameters:
destination- A destination to add to a watch list.
-
-