Remove idle-disconnect-monitor and let the command queue take care of that.

This commit is contained in:
Johannes Mockenhaupt 2017-12-05 22:57:06 +01:00
parent 21fc05a707
commit 960cb92789
No known key found for this signature in database
GPG key ID: 9E1EA6AF7BBBB0D1
4 changed files with 20 additions and 27 deletions

View file

@ -226,12 +226,12 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf
@Override
public void connect(String reason) {
// we're not doing that
// ruffyscripter establishes a connection as needed
}
@Override
public void disconnect(String reason) {
// we're not doing that
ruffyScripter.disconnect();
}
@Override
@ -676,6 +676,8 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf
}
}
// Pass this to qeueue??
// hm, now that each PumpInterface method is basically one RuffyCommand again ....
commandResult = commandExecution.execute();
if (!commandResult.success && retries > 0) {

View file

@ -26,6 +26,8 @@ public interface RuffyCommands {
/** Whether there's an active BT connection to the pump. */
boolean isConnected();
void disconnect();
/** Read the state of the pump, which encompasses all information displayed on the main menu. */
CommandResult readPumpState();

View file

@ -73,6 +73,11 @@ public class RuffyCommandsV1Impl implements RuffyCommands {
return delegate.isConnected();
}
@Override
public void disconnect() {
delegate.disconnect();
}
@Override
public CommandResult readPumpState() {
return delegate.readPumpState();

View file

@ -53,8 +53,6 @@ import de.jotomo.ruffyscripter.commands.SetTbrCommand;
public class RuffyScripter implements RuffyCommands {
private static final Logger log = LoggerFactory.getLogger(RuffyScripter.class);
private static final long DISCONNECT_TIME_OUT_MS = 5000;
private IRuffyService ruffyService;
@Nullable
@ -151,7 +149,6 @@ public class RuffyScripter implements RuffyCommands {
} catch (Exception e) {
log.error("Ruffy handler has issues", e);
}
idleDisconnectMonitorThread.start();
started = true;
}
@ -175,28 +172,6 @@ public class RuffyScripter implements RuffyCommands {
return started;
}
private Thread idleDisconnectMonitorThread = new Thread(new Runnable() {
@Override
public void run() {
while (!Thread.currentThread().isInterrupted()) {
try {
long now = System.currentTimeMillis();
if (ruffyService.isConnected() && activeCmd == null
&& now > lastCmdExecutionTime + DISCONNECT_TIME_OUT_MS) {
log.debug("Disconnecting after " + (DISCONNECT_TIME_OUT_MS / 1000) + "s inactivity timeout");
ruffyService.doRTDisconnect();
// don't attempt anything fancy in the next 10s, let the pump settle
SystemClock.sleep(10 * 1000);
}
} catch (Exception e) {
log.debug("Exception in idle disconnect monitor thread, taking a break and then carrying on", e);
SystemClock.sleep(10 * 1000);
}
SystemClock.sleep(1000);
}
}
}, "idle-disconnect-monitor");
@Override
public boolean isPumpBusy() {
return activeCmd != null;
@ -211,6 +186,15 @@ public class RuffyScripter implements RuffyCommands {
}
}
@Override
public void disconnect() {
try {
ruffyService.doRTDisconnect();
} catch (RemoteException e) {
throw new CommandException("Disconnect failed", e);
}
}
@Override
public CommandResult readPumpState() {
return runCommand(new ReadPumpStateCommand());