Package com.yahoo.messagebus
Class StaticThrottlePolicy
- java.lang.Object
-
- com.yahoo.messagebus.StaticThrottlePolicy
-
- All Implemented Interfaces:
ThrottlePolicy
- Direct Known Subclasses:
DynamicThrottlePolicy
,RateThrottlingPolicy
public class StaticThrottlePolicy extends java.lang.Object implements ThrottlePolicy
This is an implementation of theThrottlePolicy
that offers static limits to the amount of pending data aSourceSession
is allowed to have. You may choose to set a limit to the total number of pending messages (by way ofsetMaxPendingCount(int)
), the total size of pending messages (by way ofsetMaxPendingSize(long)
), or some combination thereof. NOTE: By context, "pending" is refering to the number of sent messages that have not been replied to yet.- Author:
- Simon Thoresen Hult
-
-
Constructor Summary
Constructors Constructor Description StaticThrottlePolicy()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
canSend(Message message, int pendingCount)
Returns whether or not the given message can be sent according to the current state of this policy.int
getMaxPendingCount()
Returns the maximum number of pending messages allowed.long
getMaxPendingSize()
Returns the maximum total size of pending messages allowed.long
getPendingSize()
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.StaticThrottlePolicy
setMaxPendingCount(int maxCount)
Sets the maximum number of pending messages allowed.StaticThrottlePolicy
setMaxPendingSize(long maxSize)
Sets the maximum total size of pending messages allowed.
-
-
-
Method Detail
-
canSend
public boolean canSend(Message message, int pendingCount)
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
public void processMessage(Message message)
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
public void processReply(Reply reply)
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
public StaticThrottlePolicy setMaxPendingCount(int maxCount)
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
public StaticThrottlePolicy setMaxPendingSize(long maxSize)
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.
-
-