Skip to content

Commit

Permalink
move shutdown task to FacelessServer from UserInterface
Browse files Browse the repository at this point in the history
  • Loading branch information
pabender committed Feb 14, 2018
1 parent 45940b1 commit fc0b46f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 17 deletions.
15 changes: 15 additions & 0 deletions java/src/jmri/jmrit/withrottle/FacelessServer.java
Expand Up @@ -38,6 +38,7 @@ public class FacelessServer implements DeviceListener, DeviceManager, ZeroConfSe

FacelessServer() {
createServerThread();
setShutDownTask();
} // End of constructor

@Override
Expand Down Expand Up @@ -236,6 +237,20 @@ private void stopDevices() {
deviceList.clear();
}

private jmri.implementation.AbstractShutDownTask task = null;

private void setShutDownTask() {
if (jmri.InstanceManager.getNullableDefault(jmri.ShutDownManager.class) != null) {
task = new jmri.implementation.AbstractShutDownTask("WiThrottle Server ShutdownTask") {
@Override
public boolean execute() {
disableServer();
return true;
}
};
jmri.InstanceManager.getDefault(jmri.ShutDownManager.class).register(task);
}
}

@Override
public void serviceUnpublished(ZeroConfServiceEvent se) {
Expand Down
17 changes: 0 additions & 17 deletions java/src/jmri/jmrit/withrottle/UserInterface.java
Expand Up @@ -105,7 +105,6 @@ public class UserInterface extends JmriJFrame implements DeviceListener, RosterG

createWindow();

setShutDownTask();
} // End of constructor

protected void createWindow() {
Expand Down Expand Up @@ -318,22 +317,6 @@ public void notifyDeviceInfoChanged(DeviceServer device) {
withrottlesListModel.updateDeviceList(deviceList);
}

private jmri.implementation.AbstractShutDownTask task = null;

@Override
protected void setShutDownTask() {
if (jmri.InstanceManager.getNullableDefault(jmri.ShutDownManager.class) != null) {
task = new jmri.implementation.AbstractShutDownTask(getTitle()) {
@Override
public boolean execute() {
disableServer();
return true;
}
};
jmri.InstanceManager.getDefault(jmri.ShutDownManager.class).register(task);
}
}

// this is package protected so tests can trigger easilly.
void disableServer() {
facelessServer.disableServer();
Expand Down

0 comments on commit fc0b46f

Please sign in to comment.