Skip to content

Commit

Permalink
Add the basic functionality to clean and/or pause the background refr…
Browse files Browse the repository at this point in the history
…esh queue
  • Loading branch information
costing committed Mar 28, 2019
1 parent 208aba7 commit f4f2402
Showing 1 changed file with 31 additions and 6 deletions.
37 changes: 31 additions & 6 deletions java/src/jmri/jmrix/dccpp/serial/SerialDCCppPacketizer.java
Expand Up @@ -41,6 +41,8 @@
public class SerialDCCppPacketizer extends DCCppPacketizer {

final DelayQueue<DCCppMessage> resendFunctions = new DelayQueue<>();

boolean activeBackgroundRefresh = true;

public SerialDCCppPacketizer(final jmri.jmrix.dccpp.DCCppCommandStation pCommandStation) {
super(pCommandStation);
Expand Down Expand Up @@ -70,12 +72,14 @@ final class RefreshAction implements ThreadingUtil.ThreadAction {
@Override
public void run() {
try {
final DCCppMessage message = resendFunctions.poll();

if (message != null) {
message.setRetries(0);
sendDCCppMessage(message, null);
}
if (activeBackgroundRefresh) {
final DCCppMessage message = resendFunctions.poll();

if (message != null) {
message.setRetries(0);
sendDCCppMessage(message, null);
}
}
} finally {
ThreadingUtil.runOnLayoutDelayed(this, 250);
}
Expand Down Expand Up @@ -115,6 +119,27 @@ public void sendDCCppMessage(final DCCppMessage m, final DCCppListener reply) {
if (isFunction)
enqueueFunction(m);
}

/**
* Clear the background refresh queue. The state is still kept in JMRI.
*/
public void clearRefreshQueue() {
resendFunctions.clear();
}

/**
* Enable or disable the background refresh thread
*
* @param activeState <code>true</code> to keep refreshing the functions, <code>false</code> to disable this functionality.
* @return the previous active state of the background refresh thread
*/
public boolean setActiveRefresh(final boolean activeState) {
final boolean oldActiveState = activeBackgroundRefresh;

activeBackgroundRefresh = activeState;

return oldActiveState;
}

private final static Logger log = LoggerFactory.getLogger(SerialDCCppPacketizer.class);
}

0 comments on commit f4f2402

Please sign in to comment.