wait a few sec before disconnection for another command

This commit is contained in:
Milos Kozak 2017-12-20 18:26:47 +01:00
parent 0d7e950b73
commit 096b2e93a3

View file

@ -29,6 +29,7 @@ public class QueueThread extends Thread {
CommandQueue queue; CommandQueue queue;
private long connectionStartTime = 0; private long connectionStartTime = 0;
private long lastCommandTime = 0;
private boolean connectLogged = false; private boolean connectLogged = false;
private PowerManager.WakeLock mWakeLock; private PowerManager.WakeLock mWakeLock;
@ -45,7 +46,7 @@ public class QueueThread extends Thread {
public final void run() { public final void run() {
mWakeLock.acquire(); mWakeLock.acquire();
MainApp.bus().post(new EventQueueChanged()); MainApp.bus().post(new EventQueueChanged());
connectionStartTime = System.currentTimeMillis(); connectionStartTime = lastCommandTime = System.currentTimeMillis();
try { try {
while (true) { while (true) {
@ -107,17 +108,24 @@ public class QueueThread extends Thread {
queue.performing().execute(); queue.performing().execute();
queue.resetPerforming(); queue.resetPerforming();
MainApp.bus().post(new EventQueueChanged()); MainApp.bus().post(new EventQueueChanged());
lastCommandTime = System.currentTimeMillis();
SystemClock.sleep(100); SystemClock.sleep(100);
continue; continue;
} }
} }
if (queue.size() == 0 && queue.performing() == null) { if (queue.size() == 0 && queue.performing() == null) {
log.debug("QUEUE: queue empty. disconnect"); long secondsFromLastCommand = (System.currentTimeMillis() - lastCommandTime) / 1000;
MainApp.bus().post(new EventPumpStatusChanged(EventPumpStatusChanged.DISCONNECTING)); if (secondsFromLastCommand >= 5) {
pump.disconnect("Queue empty"); log.debug("QUEUE: queue empty. disconnect");
MainApp.bus().post(new EventPumpStatusChanged(EventPumpStatusChanged.DISCONNECTED)); MainApp.bus().post(new EventPumpStatusChanged(EventPumpStatusChanged.DISCONNECTING));
return; pump.disconnect("Queue empty");
MainApp.bus().post(new EventPumpStatusChanged(EventPumpStatusChanged.DISCONNECTED));
return;
} else {
log.debug("QUEUE: waiting for disconnect");
SystemClock.sleep(1000);
}
} }
} }
} finally { } finally {