Make recovering from command failure more robust.
This commit is contained in:
parent
715366b2b4
commit
f4c1f4a3a1
1 changed files with 14 additions and 7 deletions
|
@ -324,12 +324,12 @@ public class RuffyScripter implements RuffyCommands {
|
||||||
return result;
|
return result;
|
||||||
} catch (CommandException e) {
|
} catch (CommandException e) {
|
||||||
log.error("CommandException while executing command", e);
|
log.error("CommandException while executing command", e);
|
||||||
recoverFromCommandFailure();
|
PumpState pumpState = recoverFromCommandFailure();
|
||||||
return activeCmd.getResult().success(false).state(readPumpStateInternal());
|
return activeCmd.getResult().success(false).state(pumpState);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("Unexpected exception communication with ruffy", e);
|
log.error("Unexpected exception communication with ruffy", e);
|
||||||
recoverFromCommandFailure();
|
PumpState pumpState = recoverFromCommandFailure();
|
||||||
return activeCmd.getResult().success(false).state(readPumpStateInternal());
|
return activeCmd.getResult().success(false).state(pumpState);
|
||||||
} finally {
|
} finally {
|
||||||
Menu menu = this.currentMenu;
|
Menu menu = this.currentMenu;
|
||||||
if (activeCmd.getResult().success && menu != null && menu.getType() != MenuType.MAIN_MENU) {
|
if (activeCmd.getResult().success && menu != null && menu.getType() != MenuType.MAIN_MENU) {
|
||||||
|
@ -416,12 +416,12 @@ public class RuffyScripter implements RuffyCommands {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns to the main menu (if possible) after a command failure, so that subsequent commands
|
* Returns to the main menu (if possible) after a command failure, so that subsequent commands
|
||||||
* reusing the connection won't fail.
|
* reusing the connection won't fail and returns the current PumpState (empty if unreadable).
|
||||||
*/
|
*/
|
||||||
private void recoverFromCommandFailure() {
|
private PumpState recoverFromCommandFailure() {
|
||||||
Menu menu = this.currentMenu;
|
Menu menu = this.currentMenu;
|
||||||
if (menu == null) {
|
if (menu == null) {
|
||||||
return;
|
return null;
|
||||||
}
|
}
|
||||||
MenuType type = menu.getType();
|
MenuType type = menu.getType();
|
||||||
if (type != MenuType.WARNING_OR_ERROR && type != MenuType.MAIN_MENU) {
|
if (type != MenuType.WARNING_OR_ERROR && type != MenuType.MAIN_MENU) {
|
||||||
|
@ -432,6 +432,12 @@ public class RuffyScripter implements RuffyCommands {
|
||||||
log.warn("Error returning to main menu, when trying to recover from command failure", e);
|
log.warn("Error returning to main menu, when trying to recover from command failure", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
try {
|
||||||
|
return readPumpStateInternal();
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.debug("Reading pump state during recovery failed", e);
|
||||||
|
return new PumpState();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -480,6 +486,7 @@ public class RuffyScripter implements RuffyCommands {
|
||||||
state.timestamp = System.currentTimeMillis();
|
state.timestamp = System.currentTimeMillis();
|
||||||
Menu menu = currentMenu;
|
Menu menu = currentMenu;
|
||||||
if (menu == null) {
|
if (menu == null) {
|
||||||
|
log.debug("Returning empty PumpState, menu is unavailable");
|
||||||
return state;
|
return state;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue