Skip to content

Commit

Permalink
Do a save on shutdown.
Browse files Browse the repository at this point in the history
This avoids losing up to 10s worth of data.

In passing also don't try running the scoreboard without autosave,
and make gui use a monospaced font to match terminals
  • Loading branch information
brian-brazil committed Dec 8, 2019
1 parent fd8d76f commit 3a4e949
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 5 deletions.
2 changes: 1 addition & 1 deletion scoreboard.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ if [ -x /usr/libexec/java_home ]; then
JAVA="/usr/libexec/java_home -exec java"
fi

$JAVA -Done-jar.silent=true -Dorg.eclipse.jetty.server.LEVEL=WARN -jar lib/crg-scoreboard.jar "$GUI" "$@"
exec $JAVA -Done-jar.silent=true -Dorg.eclipse.jetty.server.LEVEL=WARN -jar lib/crg-scoreboard.jar "$GUI" "$@"
12 changes: 11 additions & 1 deletion src/com/carolinarollergirls/scoreboard/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
*/

import java.awt.Dimension;
import java.awt.Font;
import java.awt.Toolkit;
import java.io.File;
import java.io.IOException;
Expand Down Expand Up @@ -84,8 +85,16 @@ public void run() {
});

// Only start auto-saves once everything is loaded in.
new AutoSaveJSONState(jsm, autoSaveDir);
final AutoSaveJSONState autosaver = new AutoSaveJSONState(jsm, autoSaveDir);
jetty.start();

Runtime.getRuntime().addShutdownHook(new Thread() {
@Override
public void run() {
// Save any changes since last regular autosave before we shutdown.
autosaver.run();
}
});
}

private void setSystemProperties() {
Expand Down Expand Up @@ -139,6 +148,7 @@ private void createGui() {
guiFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
guiMessages = new JTextArea();
guiMessages.setEditable(false);
guiMessages.setFont(new Font("monospaced", Font.PLAIN, 12));
guiFrameText = new JLabel("ScoreBoard status: starting...");
guiFrame.getContentPane().setLayout(new BoxLayout(guiFrame.getContentPane(), BoxLayout.Y_AXIS));
guiFrame.getContentPane().add(guiFrameText);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ protected void addSession(AbstractSession session) {

@Override
protected void invalidateSessions() {
throw new RuntimeException("Not implemented");
// Our session objects are created per request, so nothing to cleanup on shutdown.
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,14 @@ public AutoSaveJSONState(JSONStateManager jsm, File dir) {
FileUtils.forceMkdir(dir);
} catch ( IOException ioE ) {
Logger.printMessage("WARNING: Unable to create auto-save directory '"+dir+"' : "+ioE.getMessage());
return;
throw new RuntimeException(ioE);
}
backupAutoSavedFiles();
executor.scheduleAtFixedRate(AutoSaveJSONState.this, INTERVAL_SECONDS, INTERVAL_SECONDS, TimeUnit.SECONDS);
}

@Override
public void run() {
public synchronized void run() {
Histogram.Timer timer = autosaveDuration.startTimer();
try {
int n = AUTOSAVE_FILES;
Expand Down

0 comments on commit 3a4e949

Please sign in to comment.