Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow a waitTime of zero. #19

Merged
merged 1 commit into from
Jan 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -101,12 +101,8 @@ public final boolean pushIfNotExists(

@Override
public final List<String> pop(String queueName, int count, int timeout) {
// Keep the timeout to a minimum of 100ms
if (timeout < 100) {
timeout = 100;
}
List<QueueMessage> messages = get(queueName).pop(count, timeout, TimeUnit.MILLISECONDS);
return messages.stream().map(msg -> msg.getId()).collect(Collectors.toList());
return messages.stream().map(QueueMessage::getId).collect(Collectors.toList());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public QueueMonitor(String queueName) {

public List<QueueMessage> pop(int count, int waitTime, TimeUnit timeUnit) {
if (count <= 0) {
log.warn("Negative poll count {}");
log.warn("Negative poll count {}", count);
// Negative number shouldn't happen, but it can be zero and in that case we don't do
// anything!
return new ArrayList<>();
Expand All @@ -76,7 +76,7 @@ public List<QueueMessage> pop(int count, int waitTime, TimeUnit timeUnit) {
// The sleep method below, just does Thread.wait should be more CPU friendly
QueueMessage message = peekedMessages.poll();
if (message == null) {
if (!waited) {
if (!waited && waitTime > 0) {
Uninterruptibles.sleepUninterruptibly(waitTime, timeUnit);
waited = true;
continue;
Expand Down
Loading