Commit b6f4fbb7 by bachinger

Remove AutoClosable implementation of PlayerCommandQueue

PiperOrigin-RevId: 370875532
parent b336df3e
...@@ -39,7 +39,7 @@ import java.util.List; ...@@ -39,7 +39,7 @@ import java.util.List;
import java.util.concurrent.Callable; import java.util.concurrent.Callable;
/** Manages the queue of player actions and handles running them one by one. */ /** Manages the queue of player actions and handles running them one by one. */
/* package */ class PlayerCommandQueue implements AutoCloseable { /* package */ class PlayerCommandQueue {
private static final String TAG = "PlayerCommandQueue"; private static final String TAG = "PlayerCommandQueue";
private static final boolean DEBUG = false; private static final boolean DEBUG = false;
...@@ -141,9 +141,6 @@ import java.util.concurrent.Callable; ...@@ -141,9 +141,6 @@ import java.util.concurrent.Callable;
@GuardedBy("lock") @GuardedBy("lock")
private final Deque<PlayerCommand> pendingPlayerCommandQueue; private final Deque<PlayerCommand> pendingPlayerCommandQueue;
@GuardedBy("lock")
private boolean closed;
// Should be only used on the handler. // Should be only used on the handler.
@Nullable private AsyncPlayerCommandResult pendingAsyncPlayerCommandResult; @Nullable private AsyncPlayerCommandResult pendingAsyncPlayerCommandResult;
...@@ -154,17 +151,6 @@ import java.util.concurrent.Callable; ...@@ -154,17 +151,6 @@ import java.util.concurrent.Callable;
pendingPlayerCommandQueue = new ArrayDeque<>(); pendingPlayerCommandQueue = new ArrayDeque<>();
} }
@Override
public void close() {
synchronized (lock) {
if (closed) {
return;
}
closed = true;
}
reset();
}
public void reset() { public void reset() {
handler.removeCallbacksAndMessages(/* token= */ null); handler.removeCallbacksAndMessages(/* token= */ null);
List<PlayerCommand> queue; List<PlayerCommand> queue;
...@@ -187,11 +173,6 @@ import java.util.concurrent.Callable; ...@@ -187,11 +173,6 @@ import java.util.concurrent.Callable;
@CommandCode int commandCode, Callable<Boolean> command, @Nullable Object tag) { @CommandCode int commandCode, Callable<Boolean> command, @Nullable Object tag) {
SettableFuture<PlayerResult> result = SettableFuture.create(); SettableFuture<PlayerResult> result = SettableFuture.create();
synchronized (lock) { synchronized (lock) {
if (closed) {
// OK to set result with lock hold because developers cannot add listener here.
result.set(new PlayerResult(PlayerResult.RESULT_ERROR_INVALID_STATE, /* item= */ null));
return result;
}
PlayerCommand playerCommand = new PlayerCommand(commandCode, command, result, tag); PlayerCommand playerCommand = new PlayerCommand(commandCode, command, result, tag);
result.addListener( result.addListener(
() -> { () -> {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment