From 955020005a95ce458d7040f26419f448da2bb3e0 Mon Sep 17 00:00:00 2001 From: Gravit Date: Mon, 1 Jul 2019 17:41:56 +0700 Subject: [PATCH] =?UTF-8?q?[FIX]=20=D0=A3=D0=B4=D0=B0=D0=BB=D1=91=D0=BD=20?= =?UTF-8?q?EventManager?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../gravit/launcher/events/ControlEvent.java | 9 +- .../pro/gravit/launcher/events/PingEvent.java | 13 +-- .../gravit/launcher/events/SignalEvent.java | 12 +-- .../events/request/AuthRequestEvent.java | 9 +- .../BatchProfileByUsernameRequestEvent.java | 9 +- .../request/CheckServerRequestEvent.java | 9 +- .../events/request/ErrorRequestEvent.java | 9 +- .../request/JoinServerRequestEvent.java | 9 +- .../events/request/LauncherRequestEvent.java | 9 +- .../request/ProfileByUUIDRequestEvent.java | 9 +- .../ProfileByUsernameRequestEvent.java | 9 +- .../events/request/ProfilesRequestEvent.java | 9 +- .../request/SetProfileRequestEvent.java | 9 +- .../request/UpdateListRequestEvent.java | 9 +- .../pro/gravit/utils/event/EventHandler.java | 8 -- .../gravit/utils/event/EventInterface.java | 7 -- .../pro/gravit/utils/event/EventManager.java | 102 ------------------ 17 files changed, 23 insertions(+), 227 deletions(-) delete mode 100644 LauncherCore/src/main/java/pro/gravit/utils/event/EventHandler.java delete mode 100644 LauncherCore/src/main/java/pro/gravit/utils/event/EventInterface.java delete mode 100644 LauncherCore/src/main/java/pro/gravit/utils/event/EventManager.java diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/events/ControlEvent.java b/LauncherAPI/src/main/java/pro/gravit/launcher/events/ControlEvent.java index 2fae8ce7..419619c0 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/events/ControlEvent.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/events/ControlEvent.java @@ -2,10 +2,8 @@ import java.util.UUID; -import pro.gravit.utils.event.EventInterface; - //Набор стандартных событий -public class ControlEvent implements EventInterface { +public class ControlEvent { private static final UUID uuid = UUID.fromString("f1051a64-0cd0-4ed8-8430-d856a196e91f"); public enum ControlCommand { @@ -17,9 +15,4 @@ public ControlEvent(ControlCommand signal) { } public ControlCommand signal; - - @Override - public UUID getUUID() { - return uuid; - } } diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/events/PingEvent.java b/LauncherAPI/src/main/java/pro/gravit/launcher/events/PingEvent.java index da0b3b99..6a26ea14 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/events/PingEvent.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/events/PingEvent.java @@ -1,17 +1,6 @@ package pro.gravit.launcher.events; -import java.util.UUID; - -import pro.gravit.utils.event.EventInterface; - //Пустое событие //Все обработчики обязаны его игнорировать -public final class PingEvent implements EventInterface { - private static final UUID uuid = UUID.fromString("7c8be7e7-82ce-4c99-84cd-ee8fcce1b509"); - - @Override - public UUID getUUID() { - - return uuid; - } +public final class PingEvent { } diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/events/SignalEvent.java b/LauncherAPI/src/main/java/pro/gravit/launcher/events/SignalEvent.java index b0c3c0d3..9f3d026e 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/events/SignalEvent.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/events/SignalEvent.java @@ -1,20 +1,10 @@ package pro.gravit.launcher.events; -import java.util.UUID; - -import pro.gravit.utils.event.EventInterface; - //Используется, что бы послать короткое сообщение, которое вмещается в int -public class SignalEvent implements EventInterface { - private static final UUID uuid = UUID.fromString("edc3afa1-2726-4da3-95c6-7e6994b981e1"); +public class SignalEvent { public int signal; public SignalEvent(int signal) { this.signal = signal; } - - @Override - public UUID getUUID() { - return uuid; - } } diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/events/request/AuthRequestEvent.java b/LauncherAPI/src/main/java/pro/gravit/launcher/events/request/AuthRequestEvent.java index 7665c4f2..4b0a09d4 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/events/request/AuthRequestEvent.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/events/request/AuthRequestEvent.java @@ -6,10 +6,8 @@ import pro.gravit.launcher.LauncherNetworkAPI; import pro.gravit.launcher.events.RequestEvent; import pro.gravit.launcher.profiles.PlayerProfile; -import pro.gravit.utils.event.EventInterface; -public class AuthRequestEvent extends RequestEvent implements EventInterface { - private static final UUID uuid = UUID.fromString("77e1bfd7-adf9-4f5d-87d6-a7dd068deb74"); +public class AuthRequestEvent extends RequestEvent { public AuthRequestEvent() { } @@ -46,11 +44,6 @@ public AuthRequestEvent(ClientPermissions permissions, PlayerProfile playerProfi this.session = session; } - @Override - public UUID getUUID() { - return uuid; - } - @Override public String getType() { return "auth"; diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/events/request/BatchProfileByUsernameRequestEvent.java b/LauncherAPI/src/main/java/pro/gravit/launcher/events/request/BatchProfileByUsernameRequestEvent.java index 21b90e60..2be4e9c7 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/events/request/BatchProfileByUsernameRequestEvent.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/events/request/BatchProfileByUsernameRequestEvent.java @@ -5,10 +5,8 @@ import pro.gravit.launcher.LauncherNetworkAPI; import pro.gravit.launcher.events.RequestEvent; import pro.gravit.launcher.profiles.PlayerProfile; -import pro.gravit.utils.event.EventInterface; -public class BatchProfileByUsernameRequestEvent extends RequestEvent implements EventInterface { - private static final UUID uuid = UUID.fromString("c1d6729e-be2c-48cc-b5ae-af8c012232c3"); +public class BatchProfileByUsernameRequestEvent extends RequestEvent { @LauncherNetworkAPI public String error; @LauncherNetworkAPI @@ -21,11 +19,6 @@ public BatchProfileByUsernameRequestEvent(PlayerProfile[] profiles) { public BatchProfileByUsernameRequestEvent() { } - @Override - public UUID getUUID() { - return uuid; - } - @Override public String getType() { return "batchProfileByUsername"; diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/events/request/CheckServerRequestEvent.java b/LauncherAPI/src/main/java/pro/gravit/launcher/events/request/CheckServerRequestEvent.java index f3c62f77..58492013 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/events/request/CheckServerRequestEvent.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/events/request/CheckServerRequestEvent.java @@ -5,9 +5,9 @@ import pro.gravit.launcher.LauncherNetworkAPI; import pro.gravit.launcher.events.RequestEvent; import pro.gravit.launcher.profiles.PlayerProfile; -import pro.gravit.utils.event.EventInterface; -public class CheckServerRequestEvent extends RequestEvent implements EventInterface { + +public class CheckServerRequestEvent extends RequestEvent { private static final UUID _uuid = UUID.fromString("8801d07c-51ba-4059-b61d-fe1f1510b28a"); @LauncherNetworkAPI public UUID uuid; @@ -21,11 +21,6 @@ public CheckServerRequestEvent(PlayerProfile playerProfile) { public CheckServerRequestEvent() { } - @Override - public UUID getUUID() { - return _uuid; - } - @Override public String getType() { return "checkServer"; diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/events/request/ErrorRequestEvent.java b/LauncherAPI/src/main/java/pro/gravit/launcher/events/request/ErrorRequestEvent.java index bc022eb0..b97e3c28 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/events/request/ErrorRequestEvent.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/events/request/ErrorRequestEvent.java @@ -4,9 +4,9 @@ import pro.gravit.launcher.LauncherNetworkAPI; import pro.gravit.launcher.events.RequestEvent; -import pro.gravit.utils.event.EventInterface; -public class ErrorRequestEvent extends RequestEvent implements EventInterface { + +public class ErrorRequestEvent extends RequestEvent { public static UUID uuid = UUID.fromString("0af22bc7-aa01-4881-bdbb-dc62b3cdac96"); public ErrorRequestEvent(String error) { @@ -20,9 +20,4 @@ public ErrorRequestEvent(String error) { public String getType() { return "error"; } - - @Override - public UUID getUUID() { - return null; - } } diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/events/request/JoinServerRequestEvent.java b/LauncherAPI/src/main/java/pro/gravit/launcher/events/request/JoinServerRequestEvent.java index 788db95f..15060252 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/events/request/JoinServerRequestEvent.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/events/request/JoinServerRequestEvent.java @@ -4,9 +4,9 @@ import pro.gravit.launcher.LauncherNetworkAPI; import pro.gravit.launcher.events.RequestEvent; -import pro.gravit.utils.event.EventInterface; -public class JoinServerRequestEvent extends RequestEvent implements EventInterface { + +public class JoinServerRequestEvent extends RequestEvent { private static final UUID uuid = UUID.fromString("2a12e7b5-3f4a-4891-a2f9-ea141c8e1995"); public JoinServerRequestEvent(boolean allow) { @@ -16,11 +16,6 @@ public JoinServerRequestEvent(boolean allow) { @LauncherNetworkAPI public boolean allow; - @Override - public UUID getUUID() { - return uuid; - } - @Override public String getType() { return "joinServer"; diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/events/request/LauncherRequestEvent.java b/LauncherAPI/src/main/java/pro/gravit/launcher/events/request/LauncherRequestEvent.java index 2118e74f..3548aa0e 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/events/request/LauncherRequestEvent.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/events/request/LauncherRequestEvent.java @@ -4,9 +4,9 @@ import pro.gravit.launcher.LauncherNetworkAPI; import pro.gravit.launcher.events.RequestEvent; -import pro.gravit.utils.event.EventInterface; -public class LauncherRequestEvent extends RequestEvent implements EventInterface { + +public class LauncherRequestEvent extends RequestEvent { private static final UUID uuid = UUID.fromString("d54cc12a-4f59-4f23-9b10-f527fdd2e38f"); @LauncherNetworkAPI public String url; @@ -33,11 +33,6 @@ public LauncherRequestEvent(byte[] binary, byte[] digest) { //Legacy support con this.digest = digest; } - @Override - public UUID getUUID() { - return uuid; - } - @Override public String getType() { return "launcher"; diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/events/request/ProfileByUUIDRequestEvent.java b/LauncherAPI/src/main/java/pro/gravit/launcher/events/request/ProfileByUUIDRequestEvent.java index 303392f3..f945129c 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/events/request/ProfileByUUIDRequestEvent.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/events/request/ProfileByUUIDRequestEvent.java @@ -5,9 +5,9 @@ import pro.gravit.launcher.LauncherNetworkAPI; import pro.gravit.launcher.events.RequestEvent; import pro.gravit.launcher.profiles.PlayerProfile; -import pro.gravit.utils.event.EventInterface; -public class ProfileByUUIDRequestEvent extends RequestEvent implements EventInterface { + +public class ProfileByUUIDRequestEvent extends RequestEvent { private static final UUID uuid = UUID.fromString("b9014cf3-4b95-4d38-8c5f-867f190a18a0"); @LauncherNetworkAPI public String error; @@ -21,11 +21,6 @@ public ProfileByUUIDRequestEvent(PlayerProfile playerProfile) { public ProfileByUUIDRequestEvent() { } - @Override - public UUID getUUID() { - return uuid; - } - @Override public String getType() { return "profileByUUID"; diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/events/request/ProfileByUsernameRequestEvent.java b/LauncherAPI/src/main/java/pro/gravit/launcher/events/request/ProfileByUsernameRequestEvent.java index 2e8981bc..18c80347 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/events/request/ProfileByUsernameRequestEvent.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/events/request/ProfileByUsernameRequestEvent.java @@ -5,9 +5,9 @@ import pro.gravit.launcher.LauncherNetworkAPI; import pro.gravit.launcher.events.RequestEvent; import pro.gravit.launcher.profiles.PlayerProfile; -import pro.gravit.utils.event.EventInterface; -public class ProfileByUsernameRequestEvent extends RequestEvent implements EventInterface { + +public class ProfileByUsernameRequestEvent extends RequestEvent { private static final UUID uuid = UUID.fromString("06204302-ff6b-4779-b97d-541e3bc39aa1"); @LauncherNetworkAPI public String error; @@ -18,11 +18,6 @@ public ProfileByUsernameRequestEvent(PlayerProfile playerProfile) { this.playerProfile = playerProfile; } - @Override - public UUID getUUID() { - return uuid; - } - @Override public String getType() { return "profileByUsername"; diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/events/request/ProfilesRequestEvent.java b/LauncherAPI/src/main/java/pro/gravit/launcher/events/request/ProfilesRequestEvent.java index 3234103e..dedd1581 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/events/request/ProfilesRequestEvent.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/events/request/ProfilesRequestEvent.java @@ -6,9 +6,9 @@ import pro.gravit.launcher.LauncherNetworkAPI; import pro.gravit.launcher.events.RequestEvent; import pro.gravit.launcher.profiles.ClientProfile; -import pro.gravit.utils.event.EventInterface; -public class ProfilesRequestEvent extends RequestEvent implements EventInterface { + +public class ProfilesRequestEvent extends RequestEvent { private static final UUID uuid = UUID.fromString("2f26fbdf-598a-46dd-92fc-1699c0e173b1"); @LauncherNetworkAPI public List profiles; @@ -20,11 +20,6 @@ public ProfilesRequestEvent(List profiles) { public ProfilesRequestEvent() { } - @Override - public UUID getUUID() { - return uuid; - } - @Override public String getType() { return "profiles"; diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/events/request/SetProfileRequestEvent.java b/LauncherAPI/src/main/java/pro/gravit/launcher/events/request/SetProfileRequestEvent.java index 27426406..9cfe2104 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/events/request/SetProfileRequestEvent.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/events/request/SetProfileRequestEvent.java @@ -5,9 +5,9 @@ import pro.gravit.launcher.LauncherNetworkAPI; import pro.gravit.launcher.events.RequestEvent; import pro.gravit.launcher.profiles.ClientProfile; -import pro.gravit.utils.event.EventInterface; -public class SetProfileRequestEvent extends RequestEvent implements EventInterface { + +public class SetProfileRequestEvent extends RequestEvent { private static final UUID uuid = UUID.fromString("08c0de9e-4364-4152-9066-8354a3a48541"); @LauncherNetworkAPI public ClientProfile newProfile; @@ -20,9 +20,4 @@ public SetProfileRequestEvent(ClientProfile newProfile) { public String getType() { return "setProfile"; } - - @Override - public UUID getUUID() { - return uuid; - } } diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/events/request/UpdateListRequestEvent.java b/LauncherAPI/src/main/java/pro/gravit/launcher/events/request/UpdateListRequestEvent.java index 20f159bb..5f99c6af 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/events/request/UpdateListRequestEvent.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/events/request/UpdateListRequestEvent.java @@ -5,9 +5,9 @@ import pro.gravit.launcher.LauncherNetworkAPI; import pro.gravit.launcher.events.RequestEvent; -import pro.gravit.utils.event.EventInterface; -public class UpdateListRequestEvent extends RequestEvent implements EventInterface { + +public class UpdateListRequestEvent extends RequestEvent { private static final UUID uuid = UUID.fromString("5fa836ae-6b61-401c-96ac-d8396f07ec6b"); @LauncherNetworkAPI public final HashSet dirs; @@ -16,11 +16,6 @@ public UpdateListRequestEvent(HashSet dirs) { this.dirs = dirs; } - @Override - public UUID getUUID() { - return uuid; - } - @Override public String getType() { return "updateList"; diff --git a/LauncherCore/src/main/java/pro/gravit/utils/event/EventHandler.java b/LauncherCore/src/main/java/pro/gravit/utils/event/EventHandler.java deleted file mode 100644 index eaef7e9e..00000000 --- a/LauncherCore/src/main/java/pro/gravit/utils/event/EventHandler.java +++ /dev/null @@ -1,8 +0,0 @@ -package pro.gravit.utils.event; - -import java.util.UUID; - -@FunctionalInterface -public interface EventHandler { - void run(UUID uuid, T event); -} diff --git a/LauncherCore/src/main/java/pro/gravit/utils/event/EventInterface.java b/LauncherCore/src/main/java/pro/gravit/utils/event/EventInterface.java deleted file mode 100644 index 35522ed9..00000000 --- a/LauncherCore/src/main/java/pro/gravit/utils/event/EventInterface.java +++ /dev/null @@ -1,7 +0,0 @@ -package pro.gravit.utils.event; - -import java.util.UUID; - -public interface EventInterface { - UUID getUUID(); -} diff --git a/LauncherCore/src/main/java/pro/gravit/utils/event/EventManager.java b/LauncherCore/src/main/java/pro/gravit/utils/event/EventManager.java deleted file mode 100644 index 4de60a27..00000000 --- a/LauncherCore/src/main/java/pro/gravit/utils/event/EventManager.java +++ /dev/null @@ -1,102 +0,0 @@ -package pro.gravit.utils.event; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.UUID; -import java.util.concurrent.BlockingQueue; -import java.util.concurrent.LinkedBlockingQueue; -import java.util.concurrent.atomic.AtomicBoolean; - -import pro.gravit.utils.helper.CommonHelper; -import pro.gravit.utils.helper.LogHelper; - -public class EventManager { - public static final int QUEUE_MAX_SIZE = 2048; - public static final int INITIAL_HANDLERS_SIZE = 16; - - public class Entry { - public Entry(EventHandler func, UUID[] events) { - this.func = func; - this.events = events; - } - - EventHandler func; - UUID[] events; - } - - public class QueueEntry { - public QueueEntry(EventInterface event, UUID key) { - this.event = event; - this.key = key; - } - - EventInterface event; - UUID key; - } - - private EventExecutor executor; - private Thread executorThread; - private AtomicBoolean isStarted = new AtomicBoolean(false); - - public synchronized void start() { - if (isStarted.get()) return; - executor = new EventExecutor(); - isStarted.set(true); - executorThread = CommonHelper.newThread("EventExecutor", true, executor); - executorThread.start(); - } - - public synchronized void stop() { - if (!isStarted.get()) return; - executorThread.interrupt(); - try { - executorThread.join(); - } catch (InterruptedException ignored) { - } - } - - public ArrayList handlers = new ArrayList<>(INITIAL_HANDLERS_SIZE); - public BlockingQueue queue = new LinkedBlockingQueue<>(QUEUE_MAX_SIZE); //Максимальный размер очереди - - public int registerHandler(EventHandler func, UUID[] events) { - if (isStarted.get()) - throw new IllegalThreadStateException("It is forbidden to add a handler during thread operation."); - Arrays.sort(events); - handlers.add(new Entry(func, events)); - return handlers.size(); - } - - public void unregisterHandler(EventHandler func) { - if (isStarted.get()) - throw new IllegalThreadStateException("It is forbidden to remove a handler during thread operation."); - handlers.removeIf(e -> e.func.equals(func)); - } - - public void sendEvent(UUID key, EventInterface event, boolean blocking) { - if (blocking) process(key, event); - else queue.add(new QueueEntry(event, key)); - } - - public void process(UUID key, EventInterface event) { - for (Entry e : handlers) { - if (Arrays.binarySearch(e.events, key) >= 0) e.func.run(key, event); - } - } - - public class EventExecutor implements Runnable { - public boolean enable = true; - - @Override - public void run() { - while (enable && !Thread.interrupted()) { - try { - QueueEntry e = queue.take(); - process(e.key, e.event); - } catch (InterruptedException e) { - LogHelper.error(e); - } - Thread.yield(); - } - } - } -}