summaryrefslogtreecommitdiff
path: root/src/main/java/com/keuin/kbackupfabric/autobackup
diff options
context:
space:
mode:
authorKeuin <[email protected]>2022-09-17 15:59:40 +0800
committerKeuin <[email protected]>2022-09-17 15:59:40 +0800
commit3e8fae576d7afccb29f5a35d07df970bafdecd36 (patch)
tree41fdeb6c19bb3daef7ca7054a9bbb84fed0cd8b6 /src/main/java/com/keuin/kbackupfabric/autobackup
parentea3658cd57899398d885d86be9f74798b8c5ef39 (diff)
stashed updatesmaster-auto-backup
Diffstat (limited to 'src/main/java/com/keuin/kbackupfabric/autobackup')
-rw-r--r--src/main/java/com/keuin/kbackupfabric/autobackup/AutoBackupDispatcher.java29
1 files changed, 11 insertions, 18 deletions
diff --git a/src/main/java/com/keuin/kbackupfabric/autobackup/AutoBackupDispatcher.java b/src/main/java/com/keuin/kbackupfabric/autobackup/AutoBackupDispatcher.java
index 32d626e..d143118 100644
--- a/src/main/java/com/keuin/kbackupfabric/autobackup/AutoBackupDispatcher.java
+++ b/src/main/java/com/keuin/kbackupfabric/autobackup/AutoBackupDispatcher.java
@@ -8,27 +8,28 @@ import java.util.logging.Logger;
public class AutoBackupDispatcher {
private Timer timer = null;
- private final Logger logger = Logger.getLogger(AutoBackupDispatcher.class.getName());
+ private final Logger logger = Logger.getLogger("KBackup-AutoBackup");
private boolean skipIfNoPlayerLoggedIn;
private final PlayerActivityTracker playerActivityTracker;
public AutoBackupDispatcher(int intervalSeconds, boolean skipIfNoPlayerLoggedIn, PlayerActivityTracker playerActivityTracker) {
+ if (intervalSeconds < 1)
+ throw new IllegalArgumentException("interval is too small");
this.skipIfNoPlayerLoggedIn = skipIfNoPlayerLoggedIn;
this.playerActivityTracker = playerActivityTracker;
- if (intervalSeconds > 0)
- setInterval(intervalSeconds);
- }
-
- public synchronized void setInterval(int intervalSeconds) {
+ // start timer
Optional.ofNullable(timer).ifPresent(Timer::cancel);
- Timer newTimer = new Timer("AutoBackupTimer");
- newTimer.schedule(new TimerTask() {
+ Timer timer = new Timer("AutoBackupTimer");
+ timer.schedule(new TimerTask() {
@Override
public void run() {
- toggleBackup();
+ if (playerActivityTracker.getCheckpoint() || !skipIfNoPlayerLoggedIn) {
+ logger.info("Making regular backup...");
+ // TODO: perform a backup
+ }
}
}, 0L, intervalSeconds * 1000L);
- timer = newTimer;
+ this.timer = timer;
}
public void setSkipIfNoPlayerLoggedIn(boolean skipIfNoPlayerLoggedIn) {
@@ -39,12 +40,4 @@ public class AutoBackupDispatcher {
timer.cancel();
timer = null;
}
-
- private void toggleBackup() {
- if (playerActivityTracker.getCheckpoint() || !skipIfNoPlayerLoggedIn) {
- logger.info("Interval backup event is triggered.");
- // TODO: perform a backup
- }
- }
-
}