diff --git a/voting-booth/src/main/java/meerkat/voting/output/AsyncRunnableOutputDevice.java b/voting-booth/src/main/java/meerkat/voting/output/AsyncRunnableOutputDevice.java index 7a856a0..2946d77 100644 --- a/voting-booth/src/main/java/meerkat/voting/output/AsyncRunnableOutputDevice.java +++ b/voting-booth/src/main/java/meerkat/voting/output/AsyncRunnableOutputDevice.java @@ -11,7 +11,7 @@ import meerkat.voting.output.outputcommands.*; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.util.concurrent.LinkedBlockingQueue; +import java.util.concurrent.ArrayBlockingQueue; /** * This is a base class for simple OutputDevices which run asynchronously (as a separate thread). @@ -21,13 +21,13 @@ import java.util.concurrent.LinkedBlockingQueue; public abstract class AsyncRunnableOutputDevice implements BallotOutputDevice, Runnable { private Logger logger; - private LinkedBlockingQueue queue; + private ArrayBlockingQueue queue; private volatile boolean shutDownHasBeenCalled; public AsyncRunnableOutputDevice() { logger = LoggerFactory.getLogger(AsyncRunnableOutputDevice.class); logger.info("AsyncRunnableOutputDevice is constructed"); - queue = new LinkedBlockingQueue<>(); + queue = new ArrayBlockingQueue<>(1); shutDownHasBeenCalled = false; } @@ -87,24 +87,28 @@ public abstract class AsyncRunnableOutputDevice implements BallotOutputDevice, R SignedEncryptedBallot signedEncryptedBallot, FutureCallback callback) { logger.debug("Output interface call to commit to ballot"); + queue.clear(); queue.add(new CommitOutputCommand(plaintextBallot, signedEncryptedBallot, (OutputDeviceCommitCallback)callback)); } @Override public void audit(BallotSecrets ballotSecrets, FutureCallback callback) { logger.debug("an interface call to audit"); + queue.clear(); queue.add(new AuditOutputCommand(ballotSecrets, (OutputDeviceFinalizeCallback)callback)); } @Override public void castBallot(FutureCallback callback) { logger.debug("an interface call to cast ballot"); + queue.clear(); queue.add(new CastOutputCommand((OutputDeviceFinalizeCallback)callback)); } @Override public void cancelBallot(FutureCallback callback) { logger.debug("an interface call to cancel the output"); + queue.clear(); queue.add(new CancelOutputCommand((ControllerCallback)callback)); }