public class MessageProviders
extends java.lang.Object
MessageProvider implementations.| Modifier and Type | Class and Description |
|---|---|
static interface |
MessageProviders.NextCallback |
| Constructor and Description |
|---|
MessageProviders() |
| Modifier and Type | Method and Description |
|---|---|
static MessageProvider |
filtered(MessageProvider messageProvider,
com.google.common.base.Predicate<Message> filter)
Filters the values returned by
Iterator.next() by some filter. |
static MessageProvider |
newDefaultMessageProvider(MessageProvider messageProvider,
long maxTimesNextEmpty)
Chain together a safe and an empty message return tracking
MessageProvider. |
static MessageProvider |
newDefaultMessageProvider(MessageProvider messageProvider,
long maxTimesNextEmpty,
int maxMessages)
Chain together a safe and an empty message return tracking
MessageProvider. |
static MessageProvider |
newSafeMessageProvider(MessageProvider messageProvider)
Wrap each call of the given
MessageProvider with a try/catch
such that they always return correctly without throwing an
Exception. |
static MessageProvider |
newUntilNextEmptyMessageProvider(MessageProvider messageProvider,
long maxTimesNextEmpty)
Wrap an existing
MessageProvider such that after a specified
number of calls to next() that results in 0 messages being returned,
hasNext() flips over to return false. |
static MessageProvider |
newUntilNextEmptyOrMaximumMessageProvider(MessageProvider messageProvider,
long maxTimesNextEmpty,
int maxMessages)
Wrap an existing
MessageProvider such that after a specified
number of calls to next() that results in 0 messages being returned, or
the maximum limit of messages is reached, hasNext() flips over to
return false. |
static MessageProvider |
newUntilSlowOrMaximumMessageProvider(MessageProvider messageProvider,
long maxTimesSlow,
int slowThreshold,
int maxMessages)
Like
newUntilNextEmptyOrMaximumMessageProvider(MessageProvider, long, int) but instead of detecting
numerous "empties" considers numerous "slows", where that is defined to be calls to next that produce less
than the specified batch threshold. |
static MessageProvider |
scanningCallback(MessageProvider messageProvider,
MessageProviders.NextCallback nextCallback)
Applies an arbitrary callback to the results of calls to
Iterator.next() before bubbling onward. |
public static MessageProvider newDefaultMessageProvider(MessageProvider messageProvider, long maxTimesNextEmpty)
MessageProvider.messageProvider - the base MessageProvider to wrapmaxTimesNextEmpty - the number of times next() can return with 0
messages until hasNext() begins to return falseMessageProviderpublic static MessageProvider newDefaultMessageProvider(MessageProvider messageProvider, long maxTimesNextEmpty, int maxMessages)
MessageProvider.messageProvider - the base MessageProvider to wrapmaxTimesNextEmpty - the number of times next() can return with 0
messages until hasNext() begins to return falsemaxMessages - An maximum limit of messages to provide
until hasNext() begins to return falseMessageProviderpublic static MessageProvider newSafeMessageProvider(MessageProvider messageProvider)
MessageProvider with a try/catch
such that they always return correctly without throwing an
Exception. Caught Exception's are swallowed and logged.messageProvider - the base MessageProvider to wrapMessageProviderpublic static MessageProvider newUntilNextEmptyMessageProvider(MessageProvider messageProvider, long maxTimesNextEmpty)
MessageProvider such that after a specified
number of calls to next() that results in 0 messages being returned,
hasNext() flips over to return false. If the underlying
MessageProvider's hasNext() returns false before the threshold is
exceeded, the hasNext() will also return false.messageProvider - the base MessageProvider to wrapmaxTimesNextEmpty - the number of times next() can return with 0
messages until hasNext() begins to return falseMessageProviderpublic static MessageProvider newUntilNextEmptyOrMaximumMessageProvider(MessageProvider messageProvider, long maxTimesNextEmpty, int maxMessages)
MessageProvider such that after a specified
number of calls to next() that results in 0 messages being returned, or
the maximum limit of messages is reached, hasNext() flips over to
return false. If the underlying MessageProvider's hasNext()
returns false before the threshold is exceeded,
the hasNext() will also return false.
Since the existing MessageProvider's next() method might return more
than one message, the maxMessages parameter can be exceeded for that particular
next() call. However, the hasNext() method will return false on the following call.messageProvider - the base MessageProvider to wrapmaxTimesNextEmpty - the number of times next() can return with 0
messages until hasNext() begins to return falsemaxMessages - An maximum limit of messages to provide
until hasNext() begins to return falseMessageProviderpublic static MessageProvider newUntilSlowOrMaximumMessageProvider(MessageProvider messageProvider, long maxTimesSlow, int slowThreshold, int maxMessages)
newUntilNextEmptyOrMaximumMessageProvider(MessageProvider, long, int) but instead of detecting
numerous "empties" considers numerous "slows", where that is defined to be calls to next that produce less
than the specified batch threshold. This is useful in the case that a queue is being written to while being
dumped. This can cause endless, slow queue reading as a messages continuously trickle in before "timesEmpty" is
achieved. Logic is identical except that instead of requiring empty, "timesSlow" is counted.
newUntilNextEmptyOrMaximumMessageProvider(MessageProvider, long, int) is actually a specialized form
of this wrapper, where 'slowThreshold = 0'slowThreshold - calls to next that contribute less than or equal to this threshold will contribute one
increment to 'timesSlow' where when 'timesSlow == maxTimesSlow', the MessageProvider will
terminate. For AmazonSQS, 10 is the usual returned message clump. So anything less than 10
may be a valid consideration for slow, e.g. 9, but in any case depends on the underlying
MessageProvider.public static MessageProvider filtered(MessageProvider messageProvider, com.google.common.base.Predicate<Message> filter)
Iterator.next() by some filter. This does not reduce the
scan count of the given message provider, but does reduce what bubbles out of it throught `next`. Note that
this may cause some calls to `next` to contain 0 elements even though there are more messages to scan.public static MessageProvider scanningCallback(MessageProvider messageProvider, MessageProviders.NextCallback nextCallback)
Iterator.next() before bubbling onward.