java.lang.Iterable<Message>
public class MessagePaginationAction extends PaginationAction<Message,MessagePaginationAction>
PaginationAction
that paginates the endpoints Route.Messages.GET_MESSAGE_HISTORY
.
Must provide not-null MessageChannel
to compile a valid
pagination route.
/**
* Iterates messages in an async stream and stops once the limit has been reached.
*/
public static void onEachMessageAsync(MessageChannel channel, Consumer<Message> consumer, int limit)
{
if (limit< 1)
return;
MessagePaginationAction action = channel.getIterableHistory();
AtomicInteger counter = new AtomicInteger(limit);
action.forEachAsync( (message)->
{
consumer.accept(message);
// if false the iteration is terminated; else it continues
return counter.decrementAndGet() == 0;
});
}
PaginationAction.PaginationIterator
RestAction.EmptyRestAction<T>
DEFAULT_FAILURE, DEFAULT_SUCCESS, LOG
Constructor | Description |
---|---|
MessagePaginationAction(MessageChannel channel) |
Modifier and Type | Method | Description |
---|---|---|
MessageChannel |
getChannel() |
The targeted
MessageChannel |
ChannelType |
getType() |
The
ChannelType of
the targeted MessageChannel . |
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
cache, cacheSize, forEachAsync, forEachAsync, forEachRemaining, forEachRemainingAsync, forEachRemainingAsync, getCached, getFirst, getLast, getLimit, getMaxLimit, getMinLimit, isCacheEnabled, isEmpty, iterator, limit, parallelStream, setCheck, spliterator, stream, takeAsync, takeRemainingAsync
complete, complete, completeAfter, getJDA, isPassContext, queue, queue, queue, queueAfter, queueAfter, queueAfter, queueAfter, queueAfter, queueAfter, setPassContext, submit, submit, submitAfter, submitAfter
public MessagePaginationAction(MessageChannel channel)
public ChannelType getType()
ChannelType
of
the targeted MessageChannel
.ChannelType
public MessageChannel getChannel()
MessageChannel