[dmx] Improve exception handling in refresh job (#16281)

If an exception is thrown while sending (or connecting) the refreshJob died. This exception is now handled gracefully.

Signed-off-by: Jan N. Klug <github@klug.nrw>
Signed-off-by: Ciprian Pascu <contact@ciprianpascu.ro>
This commit is contained in:
J-N-K 2024-01-14 20:29:38 +01:00 committed by Ciprian Pascu
parent 27e85c5878
commit 9c5314183b

View File

@ -60,7 +60,7 @@ public abstract class DmxBridgeHandler extends BaseBridgeHandler {
private boolean isMuted = false;
private int refreshTime = 1000 / DEFAULT_REFRESH_RATE;
public DmxBridgeHandler(Bridge dmxBridge) {
protected DmxBridgeHandler(Bridge dmxBridge) {
super(dmxBridge);
}
@ -148,21 +148,27 @@ public abstract class DmxBridgeHandler extends BaseBridgeHandler {
uninstallScheduler();
}
if (refreshTime > 0) {
senderJob = scheduler.scheduleAtFixedRate(() -> {
logger.trace("runnable packet sender for universe {} called, state {}/{}", universe.getUniverseId(),
getThing().getStatus(), isMuted);
if (!isMuted) {
sendDmxData();
} else {
logger.trace("bridge {} is muted", getThing().getUID());
}
}, 1, refreshTime, TimeUnit.MILLISECONDS);
senderJob = scheduler.scheduleAtFixedRate(this::refresh, 1, refreshTime, TimeUnit.MILLISECONDS);
logger.trace("started scheduler for thing {}", this.thing.getUID());
} else {
logger.info("refresh disabled for thing {}", this.thing.getUID());
}
}
private void refresh() {
try {
logger.trace("runnable packet sender for universe {} called, state {}/{}", universe.getUniverseId(),
getThing().getStatus(), isMuted);
if (!isMuted) {
sendDmxData();
} else {
logger.trace("bridge {} is muted", getThing().getUID());
}
} catch (RuntimeException e) {
logger.debug("failed to send DMX data: ", e);
}
}
/**
* uninstall the sending and updating scheduler
*/