CommandQueue synchronized
This commit is contained in:
parent
4b8395a373
commit
4d1fccaf01
1 changed files with 43 additions and 25 deletions
|
@ -101,16 +101,20 @@ public class CommandQueue {
|
||||||
}
|
}
|
||||||
|
|
||||||
private synchronized void removeAll(Command.CommandType type) {
|
private synchronized void removeAll(Command.CommandType type) {
|
||||||
for (int i = queue.size() - 1; i >= 0; i--) {
|
synchronized (queue) {
|
||||||
if (queue.get(i).commandType == type) {
|
for (int i = queue.size() - 1; i >= 0; i--) {
|
||||||
queue.remove(i);
|
if (queue.get(i).commandType == type) {
|
||||||
|
queue.remove(i);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private synchronized boolean isLastScheduled(Command.CommandType type) {
|
private synchronized boolean isLastScheduled(Command.CommandType type) {
|
||||||
if (queue.size() > 0 && queue.get(queue.size() - 1).commandType == type) {
|
synchronized (queue) {
|
||||||
return true;
|
if (queue.size() > 0 && queue.get(queue.size() - 1).commandType == type) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -119,26 +123,33 @@ public class CommandQueue {
|
||||||
// inject as a first command
|
// inject as a first command
|
||||||
if (L.isEnabled(L.PUMPQUEUE))
|
if (L.isEnabled(L.PUMPQUEUE))
|
||||||
log.debug("Adding as first: " + command.getClass().getSimpleName() + " - " + command.status());
|
log.debug("Adding as first: " + command.getClass().getSimpleName() + " - " + command.status());
|
||||||
queue.addFirst(command);
|
synchronized (queue) {
|
||||||
|
queue.addFirst(command);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private synchronized void add(Command command) {
|
private synchronized void add(Command command) {
|
||||||
if (L.isEnabled(L.PUMPQUEUE))
|
if (L.isEnabled(L.PUMPQUEUE))
|
||||||
log.debug("Adding: " + command.getClass().getSimpleName() + " - " + command.status());
|
log.debug("Adding: " + command.getClass().getSimpleName() + " - " + command.status());
|
||||||
queue.add(command);
|
synchronized (queue) {
|
||||||
|
queue.add(command);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
synchronized void pickup() {
|
synchronized void pickup() {
|
||||||
performing = queue.poll();
|
synchronized (queue) {
|
||||||
|
performing = queue.poll();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
synchronized void clear() {
|
synchronized void clear() {
|
||||||
performing = null;
|
performing = null;
|
||||||
for (int i = 0; i < queue.size(); i++) {
|
synchronized (queue) {
|
||||||
queue.get(i).cancel();
|
for (int i = 0; i < queue.size(); i++) {
|
||||||
|
queue.get(i).cancel();
|
||||||
|
}
|
||||||
|
queue.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
queue.clear();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public int size() {
|
public int size() {
|
||||||
|
@ -181,9 +192,11 @@ public class CommandQueue {
|
||||||
|
|
||||||
public synchronized boolean bolusInQueue() {
|
public synchronized boolean bolusInQueue() {
|
||||||
if (isRunning(Command.CommandType.BOLUS)) return true;
|
if (isRunning(Command.CommandType.BOLUS)) return true;
|
||||||
for (int i = 0; i < queue.size(); i++) {
|
synchronized (queue) {
|
||||||
if (queue.get(i).commandType == Command.CommandType.BOLUS) {
|
for (int i = 0; i < queue.size(); i++) {
|
||||||
return true;
|
if (queue.get(i).commandType == Command.CommandType.BOLUS) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
@ -440,9 +453,11 @@ public class CommandQueue {
|
||||||
public synchronized boolean statusInQueue() {
|
public synchronized boolean statusInQueue() {
|
||||||
if (isRunning(Command.CommandType.READSTATUS))
|
if (isRunning(Command.CommandType.READSTATUS))
|
||||||
return true;
|
return true;
|
||||||
for (int i = 0; i < queue.size(); i++) {
|
synchronized (queue) {
|
||||||
if (queue.get(i).commandType == Command.CommandType.READSTATUS) {
|
for (int i = 0; i < queue.size(); i++) {
|
||||||
return true;
|
if (queue.get(i).commandType == Command.CommandType.READSTATUS) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
@ -528,15 +543,18 @@ public class CommandQueue {
|
||||||
public Spanned spannedStatus() {
|
public Spanned spannedStatus() {
|
||||||
String s = "";
|
String s = "";
|
||||||
int line = 0;
|
int line = 0;
|
||||||
if (performing != null) {
|
Command perf = performing;
|
||||||
s += "<b>" + performing.status() + "</b>";
|
if (perf != null) {
|
||||||
|
s += "<b>" + perf.status() + "</b>";
|
||||||
line++;
|
line++;
|
||||||
}
|
}
|
||||||
for (int i = 0; i < queue.size(); i++) {
|
synchronized (queue) {
|
||||||
if (line != 0)
|
for (int i = 0; i < queue.size(); i++) {
|
||||||
s += "<br>";
|
if (line != 0)
|
||||||
s += queue.get(i).status();
|
s += "<br>";
|
||||||
line++;
|
s += queue.get(i).status();
|
||||||
|
line++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return Html.fromHtml(s);
|
return Html.fromHtml(s);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue