Remove idle-disconnect-monitor and let the command queue take care of that.
This commit is contained in:
parent
21fc05a707
commit
960cb92789
|
@ -226,12 +226,12 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void connect(String reason) {
|
public void connect(String reason) {
|
||||||
// we're not doing that
|
// ruffyscripter establishes a connection as needed
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void disconnect(String reason) {
|
public void disconnect(String reason) {
|
||||||
// we're not doing that
|
ruffyScripter.disconnect();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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();
|
commandResult = commandExecution.execute();
|
||||||
|
|
||||||
if (!commandResult.success && retries > 0) {
|
if (!commandResult.success && retries > 0) {
|
||||||
|
|
|
@ -26,6 +26,8 @@ public interface RuffyCommands {
|
||||||
/** Whether there's an active BT connection to the pump. */
|
/** Whether there's an active BT connection to the pump. */
|
||||||
boolean isConnected();
|
boolean isConnected();
|
||||||
|
|
||||||
|
void disconnect();
|
||||||
|
|
||||||
/** Read the state of the pump, which encompasses all information displayed on the main menu. */
|
/** Read the state of the pump, which encompasses all information displayed on the main menu. */
|
||||||
CommandResult readPumpState();
|
CommandResult readPumpState();
|
||||||
|
|
||||||
|
|
|
@ -73,6 +73,11 @@ public class RuffyCommandsV1Impl implements RuffyCommands {
|
||||||
return delegate.isConnected();
|
return delegate.isConnected();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void disconnect() {
|
||||||
|
delegate.disconnect();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CommandResult readPumpState() {
|
public CommandResult readPumpState() {
|
||||||
return delegate.readPumpState();
|
return delegate.readPumpState();
|
||||||
|
|
|
@ -53,8 +53,6 @@ import de.jotomo.ruffyscripter.commands.SetTbrCommand;
|
||||||
public class RuffyScripter implements RuffyCommands {
|
public class RuffyScripter implements RuffyCommands {
|
||||||
private static final Logger log = LoggerFactory.getLogger(RuffyScripter.class);
|
private static final Logger log = LoggerFactory.getLogger(RuffyScripter.class);
|
||||||
|
|
||||||
private static final long DISCONNECT_TIME_OUT_MS = 5000;
|
|
||||||
|
|
||||||
private IRuffyService ruffyService;
|
private IRuffyService ruffyService;
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
|
@ -151,7 +149,6 @@ public class RuffyScripter implements RuffyCommands {
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("Ruffy handler has issues", e);
|
log.error("Ruffy handler has issues", e);
|
||||||
}
|
}
|
||||||
idleDisconnectMonitorThread.start();
|
|
||||||
started = true;
|
started = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -175,28 +172,6 @@ public class RuffyScripter implements RuffyCommands {
|
||||||
return started;
|
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
|
@Override
|
||||||
public boolean isPumpBusy() {
|
public boolean isPumpBusy() {
|
||||||
return activeCmd != null;
|
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
|
@Override
|
||||||
public CommandResult readPumpState() {
|
public CommandResult readPumpState() {
|
||||||
return runCommand(new ReadPumpStateCommand());
|
return runCommand(new ReadPumpStateCommand());
|
||||||
|
|
Loading…
Reference in a new issue