class SQSPoller {

    public void poll(final int remainingTimeInMillis) {
        Instant cutoff = Instant.now(clock)
                .plusMillis(remainingTimeInMillis)
                .minusMillis(TIMEOUT_BUFFER_IN_MILLIS);
        messageDispatcher.reset();
        int estimatedCapacity;
        while ((estimatedCapacity = messageDispatcher.getEstimatedCapacity(cutoff)) > 0) {
            List<Message> toProcess = sqsProxy.receiveMessages(estimatedCapacity);

            if (toProcess.isEmpty()) {
                log.info("No messages received from queue. Returning until next polling cycle to save cost.");
                return;
            }

            messageDispatcher.dispatch(toProcess);
        }
    }

    public  SQSPoller(final SQSProxy sqsProxy, final MessageDispatcher messageDispatcher);

}