Add a LocalDB Auto Save Mechanism #41
@ -35,6 +35,7 @@ public final class ClientConfig extends Config {
|
|||||||
put("server", "s", identity());
|
put("server", "s", identity());
|
||||||
put("port", "p", Integer::parseInt);
|
put("port", "p", Integer::parseInt);
|
||||||
put("localDB", "db", File::new);
|
put("localDB", "db", File::new);
|
||||||
|
put("localDBSaveInterval", "db-si", Integer::parseInt);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -54,4 +55,10 @@ public final class ClientConfig extends Config {
|
|||||||
* @since Envoy Client v0.1-alpha
|
* @since Envoy Client v0.1-alpha
|
||||||
*/
|
*/
|
||||||
public File getLocalDB() { return (File) items.get("localDB").get(); }
|
public File getLocalDB() { return (File) items.get("localDB").get(); }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the amount of minutes after which the local database should be saved
|
||||||
|
* @since Envoy Client v0.2-beta
|
||||||
|
*/
|
||||||
|
public Integer getLocalDBSaveInterval() { return (Integer) items.get("localDBSaveInterval").get(); }
|
||||||
}
|
}
|
||||||
|
@ -160,6 +160,20 @@ public final class LocalDB implements EventListener {
|
|||||||
.forEach(chats::add);
|
.forEach(chats::add);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initializes a timer that automatically saves this local database after a
|
||||||
|
* period of time specified in the settings.
|
||||||
|
*
|
||||||
|
* @since Envoy Client v0.2-beta
|
||||||
|
*/
|
||||||
|
public void initAutoSave() {
|
||||||
|
new Timer("LocalDB Autosave", true).schedule(new TimerTask() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run() { save(); }
|
||||||
|
}, 2000, ClientConfig.getInstance().getLocalDBSaveInterval() * 60000);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Stores all users. If the client user is specified, their chats will be stored
|
* Stores all users. If the client user is specified, their chats will be stored
|
||||||
* as well. The message id generator will also be saved if present.
|
* as well. The message id generator will also be saved if present.
|
||||||
|
@ -226,5 +226,8 @@ public final class Startup extends Application {
|
|||||||
else trayIcon.hide();
|
else trayIcon.hide();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Start auto save thread
|
||||||
|
localDB.initAutoSave();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,8 +1,6 @@
|
|||||||
server=localhost
|
server=localhost
|
||||||
port=8080
|
port=8080
|
||||||
localDB=localDB
|
localDB=localDB
|
||||||
password=
|
localDBSaveInterval=2
|
||||||
user=
|
|
||||||
ignoreLocalDB=false
|
|
||||||
consoleLevelBarrier=FINER
|
consoleLevelBarrier=FINER
|
||||||
fileLevelBarrier=OFF
|
fileLevelBarrier=OFF
|
||||||
|
Reference in New Issue
Block a user