Improved logout mechanism a bit, still pretty buggy
(and fixed some inconsistencies)
This commit is contained in:
@ -1,11 +1,9 @@
|
||||
package envoy.client.data;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.LinkedList;
|
||||
import java.util.Queue;
|
||||
import java.util.*;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import java.util.logging.*;
|
||||
|
||||
import envoy.util.EnvoyLog;
|
||||
|
||||
@ -62,4 +60,11 @@ public final class Cache<T> implements Consumer<T>, Serializable {
|
||||
elements.forEach(processor::accept);
|
||||
elements.clear();
|
||||
}
|
||||
|
||||
/**
|
||||
* Clears this cache of all stored elements.
|
||||
*
|
||||
* @since Envoy Client v0.2-beta
|
||||
*/
|
||||
public void clear() { elements.clear(); }
|
||||
}
|
||||
|
@ -40,6 +40,10 @@ public final class LocalDB implements EventListener {
|
||||
private CacheMap cacheMap = new CacheMap();
|
||||
private String authToken;
|
||||
|
||||
// auto save Timer
|
||||
private Timer autoSaver;
|
||||
private boolean autoSaveRestart = true;
|
||||
|
||||
// State management
|
||||
private Instant lastSync = Instant.EPOCH;
|
||||
|
||||
@ -167,7 +171,14 @@ public final class LocalDB implements EventListener {
|
||||
* @since Envoy Client v0.2-beta
|
||||
*/
|
||||
public void initAutoSave() {
|
||||
new Timer("LocalDB Autosave", true).schedule(new TimerTask() {
|
||||
|
||||
if (autoSaveRestart) {
|
||||
// A logout happened so the timer should be restarted
|
||||
autoSaver = new Timer("LocalDB Autosave", true);
|
||||
autoSaveRestart = false;
|
||||
}
|
||||
|
||||
autoSaver.schedule(new TimerTask() {
|
||||
|
||||
@Override
|
||||
public void run() { save(); }
|
||||
@ -219,12 +230,16 @@ public final class LocalDB implements EventListener {
|
||||
*/
|
||||
@Event(eventType = Logout.class, priority = 100)
|
||||
public void onLogout() {
|
||||
autoSaver.cancel();
|
||||
autoSaveRestart = true;
|
||||
lastLoginFile.delete();
|
||||
userFile = null;
|
||||
user = null;
|
||||
authToken = null;
|
||||
chats.clear();
|
||||
cacheMap = new CacheMap();
|
||||
lastSync = Instant.EPOCH;
|
||||
cacheMap.getMap().forEach((key, cache) -> cache.clear());
|
||||
// cacheMap = new CacheMap();
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user