Add Ability to Logout #50

Merged
kske merged 7 commits from f/logout into develop 2020-09-27 15:48:13 +02:00
5 changed files with 22 additions and 19 deletions
Showing only changes of commit 61fbeda05e - Show all commits

View File

@ -1,8 +1,7 @@
package envoy.client.data;
import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;
import java.util.*;
/**
* Stores a heterogeneous map of {@link Cache} objects with different type
@ -11,7 +10,7 @@ import java.util.Map;
* Project: <strong>envoy-client</strong><br>
* File: <strong>CacheMap.java</strong><br>
* Created: <strong>09.07.2020</strong><br>
*
*
* @author Kai S. K. Engelbart
* @since Envoy Client v0.1-beta
*/
@ -23,7 +22,7 @@ public final class CacheMap implements Serializable {
/**
* Adds a cache to the map.
*
*
* @param <T> the type accepted by the cache
* @param key the class that maps to the cache
* @param cache the cache to store
@ -33,7 +32,7 @@ public final class CacheMap implements Serializable {
/**
* Returns a cache mapped by a class.
*
*
* @param <T> the type accepted by the cache
* @param key the class that maps to the cache
* @return the cache
@ -43,7 +42,7 @@ public final class CacheMap implements Serializable {
/**
* Returns a cache mapped by a class or any of its subclasses.
*
*
* @param <T> the type accepted by the cache
* @param key the class that maps to the cache
* @return the cache
@ -51,10 +50,8 @@ public final class CacheMap implements Serializable {
*/
public <T> Cache<? super T> getApplicable(Class<T> key) {
Cache<? super T> cache = get(key);
if (cache == null)
for (var e : map.entrySet())
if (e.getKey().isAssignableFrom(key))
cache = (Cache<? super T>) e.getValue();
if (cache == null) for (final var e : map.entrySet())
if (e.getKey().isAssignableFrom(key)) cache = (Cache<? super T>) e.getValue();
return cache;
}
@ -63,4 +60,11 @@ public final class CacheMap implements Serializable {
* @since Envoy Client v0.1-beta
*/
public Map<Class<?>, Cache<?>> getMap() { return map; }
/**
* Clears the caches of this map of any values.
*
* @since Envoy Client v0.2-beta
*/
public void clear() { map.values().forEach(Cache::clear); }
}

View File

@ -40,7 +40,7 @@ public final class LocalDB implements EventListener {
private CacheMap cacheMap = new CacheMap();
private String authToken;
// auto save Timer
// Auto save timer
Outdated
Review

This should be // Auto save time.

This should be `// Auto save time`.
Outdated
Review

you mean // Auto save timer?

you mean `// Auto save timer`?
private Timer autoSaver;
private boolean autoSaveRestart = true;
@ -172,8 +172,8 @@ public final class LocalDB implements EventListener {
*/
public void initAutoSave() {
// A logout happened so the timer should be restarted
if (autoSaveRestart) {
delvh marked this conversation as resolved Outdated
Outdated
Review

Maybe move the comment above the if statement.

Maybe move the comment above the `if` statement.
// A logout happened so the timer should be restarted
autoSaver = new Timer("LocalDB Autosave", true);
autoSaveRestart = false;
}
@ -229,7 +229,7 @@ public final class LocalDB implements EventListener {
* @since Envoy Client v0.2-beta
*/
@Event(eventType = Logout.class, priority = 100)
public void onLogout() {
private void onLogout() {
delvh marked this conversation as resolved Outdated
Outdated
Review

Why is this public?

Why is this public?
autoSaver.cancel();
autoSaveRestart = true;
lastLoginFile.delete();
@ -238,8 +238,7 @@ public final class LocalDB implements EventListener {
authToken = null;
chats.clear();
lastSync = Instant.EPOCH;
cacheMap.getMap().forEach((key, cache) -> cache.clear());
// cacheMap = new CacheMap();
cacheMap.clear();
delvh marked this conversation as resolved Outdated
Outdated
Review

Please remove the comment and add a clearing method to CacheMap.

Please remove the comment and add a clearing method to `CacheMap`.
}
/**

View File

@ -5,7 +5,7 @@ import envoy.event.Event.Valueless;
/**
* Indicates that a logout has been requested.
*
* @author leon
* @author Leon Hofmeister
delvh marked this conversation as resolved Outdated
Outdated
Review

Fix your @author tag.

Fix your `@author` tag.
* @since Envoy Client v0.2-beta
*/
public final class Logout extends Valueless {

View File

@ -10,7 +10,7 @@ import envoy.client.data.Settings;
* @author Leon Hofmeister
* @since Envoy Client v0.2-beta
*/
public class AlertHelper {
public final class AlertHelper {
delvh marked this conversation as resolved Outdated
Outdated
Review

Make this final.

Make this `final`.
private AlertHelper() {}

View File

@ -13,12 +13,12 @@ import envoy.util.EnvoyLog;
import dev.kske.eventbus.EventBus;
/**
* Contains methods that have a direct impact on the user.
* Simplifies shutdown actions.
Outdated
Review

What on earth does that even mean?

What on earth does that even mean?
Outdated
Review

Changed it now.
If you don't like it, suggest a better alternative.
I cannot think of one.

Changed it now. If you don't like it, suggest a better alternative. I cannot think of one.
*
* @author Leon Hofmeister
* @since Envoy Client v0.2-beta
*/
public class ShutdownHelper {
public final class ShutdownHelper {
delvh marked this conversation as resolved Outdated
Outdated
Review

Make this final.

Make this `final`.
private ShutdownHelper() {}