Fix: output device now has queue of size 1. a newer command always overrides the previous one
parent
88991ea9ff
commit
1cf16d8386
|
@ -11,7 +11,7 @@ import meerkat.voting.output.outputcommands.*;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
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).
|
* 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 {
|
public abstract class AsyncRunnableOutputDevice implements BallotOutputDevice, Runnable {
|
||||||
|
|
||||||
private Logger logger;
|
private Logger logger;
|
||||||
private LinkedBlockingQueue<OutputCommand> queue;
|
private ArrayBlockingQueue<OutputCommand> queue;
|
||||||
private volatile boolean shutDownHasBeenCalled;
|
private volatile boolean shutDownHasBeenCalled;
|
||||||
|
|
||||||
public AsyncRunnableOutputDevice() {
|
public AsyncRunnableOutputDevice() {
|
||||||
logger = LoggerFactory.getLogger(AsyncRunnableOutputDevice.class);
|
logger = LoggerFactory.getLogger(AsyncRunnableOutputDevice.class);
|
||||||
logger.info("AsyncRunnableOutputDevice is constructed");
|
logger.info("AsyncRunnableOutputDevice is constructed");
|
||||||
queue = new LinkedBlockingQueue<>();
|
queue = new ArrayBlockingQueue<>(1);
|
||||||
shutDownHasBeenCalled = false;
|
shutDownHasBeenCalled = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -87,24 +87,28 @@ public abstract class AsyncRunnableOutputDevice implements BallotOutputDevice, R
|
||||||
SignedEncryptedBallot signedEncryptedBallot,
|
SignedEncryptedBallot signedEncryptedBallot,
|
||||||
FutureCallback<Void> callback) {
|
FutureCallback<Void> callback) {
|
||||||
logger.debug("Output interface call to commit to ballot");
|
logger.debug("Output interface call to commit to ballot");
|
||||||
|
queue.clear();
|
||||||
queue.add(new CommitOutputCommand(plaintextBallot, signedEncryptedBallot, (OutputDeviceCommitCallback)callback));
|
queue.add(new CommitOutputCommand(plaintextBallot, signedEncryptedBallot, (OutputDeviceCommitCallback)callback));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void audit(BallotSecrets ballotSecrets, FutureCallback<Void> callback) {
|
public void audit(BallotSecrets ballotSecrets, FutureCallback<Void> callback) {
|
||||||
logger.debug("an interface call to audit");
|
logger.debug("an interface call to audit");
|
||||||
|
queue.clear();
|
||||||
queue.add(new AuditOutputCommand(ballotSecrets, (OutputDeviceFinalizeCallback)callback));
|
queue.add(new AuditOutputCommand(ballotSecrets, (OutputDeviceFinalizeCallback)callback));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void castBallot(FutureCallback<Void> callback) {
|
public void castBallot(FutureCallback<Void> callback) {
|
||||||
logger.debug("an interface call to cast ballot");
|
logger.debug("an interface call to cast ballot");
|
||||||
|
queue.clear();
|
||||||
queue.add(new CastOutputCommand((OutputDeviceFinalizeCallback)callback));
|
queue.add(new CastOutputCommand((OutputDeviceFinalizeCallback)callback));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void cancelBallot(FutureCallback<Void> callback) {
|
public void cancelBallot(FutureCallback<Void> callback) {
|
||||||
logger.debug("an interface call to cancel the output");
|
logger.debug("an interface call to cancel the output");
|
||||||
|
queue.clear();
|
||||||
queue.add(new CancelOutputCommand((ControllerCallback<Void>)callback));
|
queue.add(new CancelOutputCommand((ControllerCallback<Void>)callback));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue