Skip to content

Commit

Permalink
Annotate CompletionService classes.
Browse files Browse the repository at this point in the history
Compare
google/xplat@9de0f25
(which missed `@Nullable` on the `poll` methods, so I'll be fixing
that later).
  • Loading branch information
cpovirk committed Feb 12, 2025
1 parent 2ada91b commit 142852e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@

package java.util.concurrent;

import org.jspecify.annotations.NullMarked;
import org.jspecify.annotations.Nullable;

/**
* A service that decouples the production of new asynchronous tasks
* from the consumption of the results of completed tasks. Producers
Expand Down Expand Up @@ -62,7 +65,8 @@
*
* @since 1.5
*/
public interface CompletionService<V> {
@NullMarked
public interface CompletionService<V extends @Nullable Object> {
/**
* Submits a value-returning task for execution and returns a Future
* representing the pending results of the task. Upon completion,
Expand Down Expand Up @@ -108,7 +112,7 @@ public interface CompletionService<V> {
* @return the Future representing the next completed task, or
* {@code null} if none are present
*/
Future<V> poll();
@Nullable Future<V> poll();

/**
* Retrieves and removes the Future representing the next
Expand All @@ -124,5 +128,5 @@ public interface CompletionService<V> {
* before one is present
* @throws InterruptedException if interrupted while waiting
*/
Future<V> poll(long timeout, TimeUnit unit) throws InterruptedException;
@Nullable Future<V> poll(long timeout, TimeUnit unit) throws InterruptedException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@

package java.util.concurrent;

import org.jspecify.annotations.NullMarked;
import org.jspecify.annotations.Nullable;

/**
* A {@link CompletionService} that uses a supplied {@link Executor}
* to execute tasks. This class arranges that submitted tasks are,
Expand Down Expand Up @@ -102,7 +105,8 @@
*
* @since 1.5
*/
public class ExecutorCompletionService<V> implements CompletionService<V> {
@NullMarked
public class ExecutorCompletionService<V extends @Nullable Object> implements CompletionService<V> {
private final Executor executor;
private final AbstractExecutorService aes;
private final BlockingQueue<Future<V>> completionQueue;
Expand Down Expand Up @@ -202,11 +206,11 @@ public Future<V> take() throws InterruptedException {
return completionQueue.take();
}

public Future<V> poll() {
public @Nullable Future<V> poll() {
return completionQueue.poll();
}

public Future<V> poll(long timeout, TimeUnit unit)
public @Nullable Future<V> poll(long timeout, TimeUnit unit)
throws InterruptedException {
return completionQueue.poll(timeout, unit);
}
Expand Down

0 comments on commit 142852e

Please sign in to comment.