Skip to content

Commit

Permalink
use the new event manager in StorageAgent
Browse files Browse the repository at this point in the history
  • Loading branch information
HSGamer committed Jun 5, 2024
1 parent b1c299e commit 18bebc9
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import me.hsgamer.topper.core.entry.DataEntry;
import me.hsgamer.topper.core.flag.EntryTempFlag;
import me.hsgamer.topper.core.holder.DataHolder;
import me.hsgamer.topper.core.listener.EventState;

import java.util.ArrayList;
import java.util.List;
Expand All @@ -14,10 +15,10 @@
import java.util.logging.Logger;

public class StorageAgent<K, V> extends RunnableAgent {
public static final EventState LOAD_EVENT = EventState.newState();
public static final EntryTempFlag NEED_SAVING = new EntryTempFlag("needSaving");
public static final EntryTempFlag IS_SAVING = new EntryTempFlag("isSaving");
private final Queue<K> saveQueue = new ConcurrentLinkedQueue<>();
private final List<Runnable> onLoadListeners = new ArrayList<>();
private final Logger logger;
private final DataHolder<K, V> holder;
private final DataStorage<K, V> storage;
Expand Down Expand Up @@ -76,7 +77,7 @@ public void start() {
if (entries != null) {
entries.forEach((uuid, value) -> holder.getOrCreateEntry(uuid).setValue(value, false));
}
onLoadListeners.forEach(Runnable::run);
holder.getListenerManager().call(LOAD_EVENT);
});
super.start();
}
Expand Down Expand Up @@ -113,10 +114,6 @@ public void setMaxEntryPerCall(int maxEntryPerCall) {
this.maxEntryPerCall = maxEntryPerCall;
}

public void addOnLoadListener(Runnable runnable) {
onLoadListeners.add(runnable);
}

public void setUrgentLoad(boolean urgentLoad) {
this.urgentLoad = urgentLoad;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package me.hsgamer.topper.core.listener;

public interface EventState {

static EventState newState() {
return new EventState() {
};
}
}

0 comments on commit 18bebc9

Please sign in to comment.