java.lang.Object
com.github.cowwoc.tokenbucket.ConsumptionResult
The result of an attempt to consume tokens.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionboolean
Returns the time at which the requested tokens are expected to become available.Returns the amount of time until the requested number of tokens will become available.Returns the list of limits that are preventing tokens from being consumed.Returns the time at which an attempt was made to consume tokens.Returns the container that tokens were consumed from.long
Returns the maximum number of tokens that were requested.long
Returns the minimum number of tokens that were requested.long
Returns the number of tokens that were consumed by the request.long
Returns the number of tokens left.int
hashCode()
boolean
Returns true if the bucket was able to consume any tokens.toString()
-
Constructor Details
-
ConsumptionResult
public ConsumptionResult(Container container, long minimumTokensRequested, long maximumTokensRequested, long tokensConsumed, Instant requestedAt, Instant consumedAt, Instant availableAt, long tokensLeft, List<Limit> bottlenecks) Creates a result of a request to consume tokens.- Parameters:
container
- the container that gave up tokensminimumTokensRequested
- the minimum number of tokens that were requested (inclusive)maximumTokensRequested
- the maximum number of tokens that were requested (inclusive)tokensConsumed
- the number of tokens that were consumedrequestedAt
- the time at which the tokens were requestedconsumedAt
- the time at which an attempt was made to consume tokens. This value differs fromrequestedAt
in that the caller may have to block until tokens become available for consumption, at which timeconsumedAt
is set.availableAt
- the time at which the requested tokens are expected to become available. If tokens were consumed, this value is equal toconsumedAt
.tokensLeft
- the number of tokens leftbottlenecks
- the list of Limits that are preventing tokens from being consumed (empty if none)- Throws:
NullPointerException
- if any of the arguments are nullIllegalArgumentException
- ifminimumTokensRequested
ormaximumTokensRequests
are negative or zero. IftokensConsumed
ortokensLeft
are negative. IfminimumTokensRequested > maximumTokensRequested
. IftokensConsumed > 0 && tokensConsumed < minimumTokensRequested
. IfrequestedAt > consumedAt
orconsumedAt > availableAt
.
-
-
Method Details
-
getContainer
Returns the container that tokens were consumed from. If tokens were consumed from a single bucket, it is returned. If tokens were consumed from multiple buckets, the lowest common ancestor is returned.- Returns:
- the container that gave up tokens
-
getMinimumTokensRequested
public long getMinimumTokensRequested()Returns the minimum number of tokens that were requested.- Returns:
- the minimum number of tokens that were requested (inclusive)
-
getMaximumTokensRequested
public long getMaximumTokensRequested()Returns the maximum number of tokens that were requested.- Returns:
- the maximum number of tokens that were requested (inclusive)
-
getTokensConsumed
public long getTokensConsumed()Returns the number of tokens that were consumed by the request.- Returns:
- the number of tokens that were consumed by the request
-
isSuccessful
public boolean isSuccessful()Returns true if the bucket was able to consume any tokens.- Returns:
- true if the bucket was able to consume any tokens
-
getAvailableAt
Returns the time at which the requested tokens are expected to become available. If tokens were consumed, this value is equal toconsumedAt
.- Returns:
- the time at which the requested tokens are expected to become available
-
getConsumeAt
Returns the time at which an attempt was made to consume tokens.This value differs from
requestedAt
in that the caller may have to block until tokens become available for consumption, at which timeconsumedAt
is set.- Returns:
- the time at which an attempt was made to consume tokens
-
getAvailableIn
Returns the amount of time until the requested number of tokens will become available.- Returns:
- the amount of time until the requested number of tokens will become available
-
getTokensLeft
public long getTokensLeft()Returns the number of tokens left.- Returns:
- the number of tokens left
-
getBottlenecks
Returns the list of limits that are preventing tokens from being consumed.- Returns:
- empty if tokens were consumed
-
equals
-
hashCode
public int hashCode() -
toString
-