mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2024-12-15 05:41:51 +08:00
Fixed possible "Database is closed" exceptions on ShutdownHook #546
This commit is contained in:
parent
84eeda66b2
commit
bf77d6edfa
@ -56,10 +56,6 @@ public class ShutdownHook extends Thread {
|
||||
Map<UUID, Session> activeSessions = SessionCache.getActiveSessions();
|
||||
long now = MiscUtils.getTime();
|
||||
db = Database.getActive();
|
||||
if (!db.isOpen()) {
|
||||
db.init();
|
||||
}
|
||||
|
||||
saveFirstSessionInformation(db, now);
|
||||
saveActiveSessions(db, activeSessions, now);
|
||||
} catch (IllegalStateException ignored) {
|
||||
@ -78,9 +74,12 @@ public class ShutdownHook extends Thread {
|
||||
}
|
||||
}
|
||||
|
||||
private void saveFirstSessionInformation(Database db, long now) {
|
||||
private void saveFirstSessionInformation(Database db, long now) throws DBInitException {
|
||||
DataCache dataCache = CacheSystem.getInstance().getDataCache();
|
||||
for (Map.Entry<UUID, Integer> entry : dataCache.getFirstSessionMsgCounts().entrySet()) {
|
||||
if (!db.isOpen()) {
|
||||
db.init();
|
||||
}
|
||||
try {
|
||||
UUID uuid = entry.getKey();
|
||||
int messagesSent = entry.getValue();
|
||||
@ -91,7 +90,7 @@ public class ShutdownHook extends Thread {
|
||||
}
|
||||
}
|
||||
|
||||
private void saveActiveSessions(Database db, Map<UUID, Session> activeSessions, long now) {
|
||||
private void saveActiveSessions(Database db, Map<UUID, Session> activeSessions, long now) throws DBInitException {
|
||||
for (Map.Entry<UUID, Session> entry : activeSessions.entrySet()) {
|
||||
UUID uuid = entry.getKey();
|
||||
Session session = entry.getValue();
|
||||
@ -99,6 +98,9 @@ public class ShutdownHook extends Thread {
|
||||
if (sessionEnd == -1) {
|
||||
session.endSession(now);
|
||||
}
|
||||
if (!db.isOpen()) {
|
||||
db.init();
|
||||
}
|
||||
try {
|
||||
Log.debug("Shutdown: Saving a session: " + session.getSessionStart());
|
||||
db.save().session(uuid, session);
|
||||
|
Loading…
Reference in New Issue
Block a user