Package com.yahoo.messagebus
Class StaticThrottlePolicy
java.lang.Object
com.yahoo.messagebus.StaticThrottlePolicy
- All Implemented Interfaces:
ThrottlePolicy
- Direct Known Subclasses:
DynamicThrottlePolicy
,RateThrottlingPolicy
This is an implementation of the
ThrottlePolicy
that offers static limits to the amount of pending data a
SourceSession
is allowed to have. You may choose to set a limit to the total number of pending messages (by
way of setMaxPendingCount(int)
), the total size of pending messages (by way of setMaxPendingSize(long)
), or some combination thereof.
NOTE: By context, "pending" refers to the number of sent messages that have not been replied to yet.- Author:
- Simon Thoresen Hult
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionboolean
Returns whether or not the given message can be sent according to the current state of this policy.int
Returns the maximum number of pending messages allowed.long
Returns the maximum total size of pending messages allowed.long
Returns the total size of pending messages.void
processMessage
(Message message) This method is called once for every message that was accepted byThrottlePolicy.canSend(Message, int)
and sent.void
processReply
(Reply reply) This method is called once for every reply that is received.setMaxPendingCount
(int maxCount) Sets the maximum number of pending messages allowed.setMaxPendingSize
(long maxSize) Sets the maximum total size of pending messages allowed.
-
Constructor Details
-
StaticThrottlePolicy
public StaticThrottlePolicy()
-
-
Method Details
-
canSend
Description copied from interface:ThrottlePolicy
Returns whether or not the given message can be sent according to the current state of this policy.- Specified by:
canSend
in interfaceThrottlePolicy
- Parameters:
message
- the message to evaluatependingCount
- the current number of pending messages- Returns:
- true to send the message
-
processMessage
Description copied from interface:ThrottlePolicy
This method is called once for every message that was accepted byThrottlePolicy.canSend(Message, int)
and sent.- Specified by:
processMessage
in interfaceThrottlePolicy
- Parameters:
message
- the message being sent
-
processReply
Description copied from interface:ThrottlePolicy
This method is called once for every reply that is received.- Specified by:
processReply
in interfaceThrottlePolicy
- Parameters:
reply
- the reply received
-
getMaxPendingCount
public int getMaxPendingCount()Returns the maximum number of pending messages allowed.- Returns:
- the max limit
-
setMaxPendingCount
Sets the maximum number of pending messages allowed.- Parameters:
maxCount
- The max count- Returns:
- this, to allow chaining
-
getMaxPendingSize
public long getMaxPendingSize()Returns the maximum total size of pending messages allowed.- Returns:
- The max limit.
-
setMaxPendingSize
Sets the maximum total size of pending messages allowed. This size is relative to the value returned byMessage.getApproxSize()
.- Parameters:
maxSize
- The max size.- Returns:
- This, to allow chaining.
-
getPendingSize
public long getPendingSize()Returns the total size of pending messages.- Returns:
- The size.
-