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 Broker
broker
protected String
name
protected Scheduler
scheduler
protected Map<Subscription,SlowConsumerEntry>
slowConsumers
protected AtomicBoolean
taskStarted
-
Constructor Summary
Constructors Constructor Description AbortSlowConsumerStrategy()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
abortConsumer(Subscription sub, boolean abortSubscriberConnection)
protected void
abortSubscription(Map<Subscription,SlowConsumerEntry> toAbort, boolean abortSubscriberConnection)
void
addDestination(Destination destination)
For Strategies that need to examine assigned destination for slow consumers periodically the destination is assigned here.long
getCheckPeriod()
long
getMaxSlowCount()
long
getMaxSlowDuration()
String
getName()
Map<Subscription,SlowConsumerEntry>
getSlowConsumers()
boolean
isAbortConnection()
boolean
isIgnoreNetworkSubscriptions()
Returns whether the strategy is configured to ignore subscriptions that are from a network connection.void
run()
void
setAbortConnection(boolean abortConnection)
abort the consumers connection rather than sending a stop command to the remote consumervoid
setBrokerService(Broker broker)
Sets the Broker instance which can provide a Scheduler among other things.void
setCheckPeriod(long checkPeriod)
time in milliseconds between checks for slow subscriptionsvoid
setIgnoreNetworkConsumers(boolean ignoreNetworkConsumers)
Sets whether the strategy is configured to ignore consumers that are part of a network connection to another broker.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 dispatchvoid
setMaxSlowDuration(long maxSlowDuration)
time in milliseconds that a sub can remain slow before triggering an abort.void
setName(String name)
void
slowConsumer(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:SlowConsumerStrategy
Sets the Broker instance which can provide a Scheduler among other things.- Specified by:
setBrokerService
in interfaceSlowConsumerStrategy
- Parameters:
broker
- The running Broker.
-
slowConsumer
public void slowConsumer(ConnectionContext context, Subscription subs)
Description copied from interface:SlowConsumerStrategy
Slow consumer event.- Specified by:
slowConsumer
in 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:SlowConsumerStrategy
For 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:
addDestination
in interfaceSlowConsumerStrategy
- Parameters:
destination
- A destination to add to a watch list.
-
-