[FIX] Удалён EventManager

This commit is contained in:
Gravit 2019-07-01 17:41:56 +07:00
parent 25ccda7ae2
commit 955020005a
No known key found for this signature in database
GPG key ID: 061981E1E85D3216
17 changed files with 23 additions and 227 deletions

View file

@ -2,10 +2,8 @@
import java.util.UUID; 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"); private static final UUID uuid = UUID.fromString("f1051a64-0cd0-4ed8-8430-d856a196e91f");
public enum ControlCommand { public enum ControlCommand {
@ -17,9 +15,4 @@ public ControlEvent(ControlCommand signal) {
} }
public ControlCommand signal; public ControlCommand signal;
@Override
public UUID getUUID() {
return uuid;
}
} }

View file

@ -1,17 +1,6 @@
package pro.gravit.launcher.events; package pro.gravit.launcher.events;
import java.util.UUID;
import pro.gravit.utils.event.EventInterface;
//Пустое событие //Пустое событие
//Все обработчики обязаны его игнорировать //Все обработчики обязаны его игнорировать
public final class PingEvent implements EventInterface { public final class PingEvent {
private static final UUID uuid = UUID.fromString("7c8be7e7-82ce-4c99-84cd-ee8fcce1b509");
@Override
public UUID getUUID() {
return uuid;
}
} }

View file

@ -1,20 +1,10 @@
package pro.gravit.launcher.events; package pro.gravit.launcher.events;
import java.util.UUID;
import pro.gravit.utils.event.EventInterface;
//Используется, что бы послать короткое сообщение, которое вмещается в int //Используется, что бы послать короткое сообщение, которое вмещается в int
public class SignalEvent implements EventInterface { public class SignalEvent {
private static final UUID uuid = UUID.fromString("edc3afa1-2726-4da3-95c6-7e6994b981e1");
public int signal; public int signal;
public SignalEvent(int signal) { public SignalEvent(int signal) {
this.signal = signal; this.signal = signal;
} }
@Override
public UUID getUUID() {
return uuid;
}
} }

View file

@ -6,10 +6,8 @@
import pro.gravit.launcher.LauncherNetworkAPI; import pro.gravit.launcher.LauncherNetworkAPI;
import pro.gravit.launcher.events.RequestEvent; import pro.gravit.launcher.events.RequestEvent;
import pro.gravit.launcher.profiles.PlayerProfile; import pro.gravit.launcher.profiles.PlayerProfile;
import pro.gravit.utils.event.EventInterface;
public class AuthRequestEvent extends RequestEvent implements EventInterface { public class AuthRequestEvent extends RequestEvent {
private static final UUID uuid = UUID.fromString("77e1bfd7-adf9-4f5d-87d6-a7dd068deb74");
public AuthRequestEvent() { public AuthRequestEvent() {
} }
@ -46,11 +44,6 @@ public AuthRequestEvent(ClientPermissions permissions, PlayerProfile playerProfi
this.session = session; this.session = session;
} }
@Override
public UUID getUUID() {
return uuid;
}
@Override @Override
public String getType() { public String getType() {
return "auth"; return "auth";

View file

@ -5,10 +5,8 @@
import pro.gravit.launcher.LauncherNetworkAPI; import pro.gravit.launcher.LauncherNetworkAPI;
import pro.gravit.launcher.events.RequestEvent; import pro.gravit.launcher.events.RequestEvent;
import pro.gravit.launcher.profiles.PlayerProfile; import pro.gravit.launcher.profiles.PlayerProfile;
import pro.gravit.utils.event.EventInterface;
public class BatchProfileByUsernameRequestEvent extends RequestEvent implements EventInterface { public class BatchProfileByUsernameRequestEvent extends RequestEvent {
private static final UUID uuid = UUID.fromString("c1d6729e-be2c-48cc-b5ae-af8c012232c3");
@LauncherNetworkAPI @LauncherNetworkAPI
public String error; public String error;
@LauncherNetworkAPI @LauncherNetworkAPI
@ -21,11 +19,6 @@ public BatchProfileByUsernameRequestEvent(PlayerProfile[] profiles) {
public BatchProfileByUsernameRequestEvent() { public BatchProfileByUsernameRequestEvent() {
} }
@Override
public UUID getUUID() {
return uuid;
}
@Override @Override
public String getType() { public String getType() {
return "batchProfileByUsername"; return "batchProfileByUsername";

View file

@ -5,9 +5,9 @@
import pro.gravit.launcher.LauncherNetworkAPI; import pro.gravit.launcher.LauncherNetworkAPI;
import pro.gravit.launcher.events.RequestEvent; import pro.gravit.launcher.events.RequestEvent;
import pro.gravit.launcher.profiles.PlayerProfile; 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"); private static final UUID _uuid = UUID.fromString("8801d07c-51ba-4059-b61d-fe1f1510b28a");
@LauncherNetworkAPI @LauncherNetworkAPI
public UUID uuid; public UUID uuid;
@ -21,11 +21,6 @@ public CheckServerRequestEvent(PlayerProfile playerProfile) {
public CheckServerRequestEvent() { public CheckServerRequestEvent() {
} }
@Override
public UUID getUUID() {
return _uuid;
}
@Override @Override
public String getType() { public String getType() {
return "checkServer"; return "checkServer";

View file

@ -4,9 +4,9 @@
import pro.gravit.launcher.LauncherNetworkAPI; import pro.gravit.launcher.LauncherNetworkAPI;
import pro.gravit.launcher.events.RequestEvent; 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 static UUID uuid = UUID.fromString("0af22bc7-aa01-4881-bdbb-dc62b3cdac96");
public ErrorRequestEvent(String error) { public ErrorRequestEvent(String error) {
@ -20,9 +20,4 @@ public ErrorRequestEvent(String error) {
public String getType() { public String getType() {
return "error"; return "error";
} }
@Override
public UUID getUUID() {
return null;
}
} }

View file

@ -4,9 +4,9 @@
import pro.gravit.launcher.LauncherNetworkAPI; import pro.gravit.launcher.LauncherNetworkAPI;
import pro.gravit.launcher.events.RequestEvent; 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"); private static final UUID uuid = UUID.fromString("2a12e7b5-3f4a-4891-a2f9-ea141c8e1995");
public JoinServerRequestEvent(boolean allow) { public JoinServerRequestEvent(boolean allow) {
@ -16,11 +16,6 @@ public JoinServerRequestEvent(boolean allow) {
@LauncherNetworkAPI @LauncherNetworkAPI
public boolean allow; public boolean allow;
@Override
public UUID getUUID() {
return uuid;
}
@Override @Override
public String getType() { public String getType() {
return "joinServer"; return "joinServer";

View file

@ -4,9 +4,9 @@
import pro.gravit.launcher.LauncherNetworkAPI; import pro.gravit.launcher.LauncherNetworkAPI;
import pro.gravit.launcher.events.RequestEvent; 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"); private static final UUID uuid = UUID.fromString("d54cc12a-4f59-4f23-9b10-f527fdd2e38f");
@LauncherNetworkAPI @LauncherNetworkAPI
public String url; public String url;
@ -33,11 +33,6 @@ public LauncherRequestEvent(byte[] binary, byte[] digest) { //Legacy support con
this.digest = digest; this.digest = digest;
} }
@Override
public UUID getUUID() {
return uuid;
}
@Override @Override
public String getType() { public String getType() {
return "launcher"; return "launcher";

View file

@ -5,9 +5,9 @@
import pro.gravit.launcher.LauncherNetworkAPI; import pro.gravit.launcher.LauncherNetworkAPI;
import pro.gravit.launcher.events.RequestEvent; import pro.gravit.launcher.events.RequestEvent;
import pro.gravit.launcher.profiles.PlayerProfile; 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"); private static final UUID uuid = UUID.fromString("b9014cf3-4b95-4d38-8c5f-867f190a18a0");
@LauncherNetworkAPI @LauncherNetworkAPI
public String error; public String error;
@ -21,11 +21,6 @@ public ProfileByUUIDRequestEvent(PlayerProfile playerProfile) {
public ProfileByUUIDRequestEvent() { public ProfileByUUIDRequestEvent() {
} }
@Override
public UUID getUUID() {
return uuid;
}
@Override @Override
public String getType() { public String getType() {
return "profileByUUID"; return "profileByUUID";

View file

@ -5,9 +5,9 @@
import pro.gravit.launcher.LauncherNetworkAPI; import pro.gravit.launcher.LauncherNetworkAPI;
import pro.gravit.launcher.events.RequestEvent; import pro.gravit.launcher.events.RequestEvent;
import pro.gravit.launcher.profiles.PlayerProfile; 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"); private static final UUID uuid = UUID.fromString("06204302-ff6b-4779-b97d-541e3bc39aa1");
@LauncherNetworkAPI @LauncherNetworkAPI
public String error; public String error;
@ -18,11 +18,6 @@ public ProfileByUsernameRequestEvent(PlayerProfile playerProfile) {
this.playerProfile = playerProfile; this.playerProfile = playerProfile;
} }
@Override
public UUID getUUID() {
return uuid;
}
@Override @Override
public String getType() { public String getType() {
return "profileByUsername"; return "profileByUsername";

View file

@ -6,9 +6,9 @@
import pro.gravit.launcher.LauncherNetworkAPI; import pro.gravit.launcher.LauncherNetworkAPI;
import pro.gravit.launcher.events.RequestEvent; import pro.gravit.launcher.events.RequestEvent;
import pro.gravit.launcher.profiles.ClientProfile; 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"); private static final UUID uuid = UUID.fromString("2f26fbdf-598a-46dd-92fc-1699c0e173b1");
@LauncherNetworkAPI @LauncherNetworkAPI
public List<ClientProfile> profiles; public List<ClientProfile> profiles;
@ -20,11 +20,6 @@ public ProfilesRequestEvent(List<ClientProfile> profiles) {
public ProfilesRequestEvent() { public ProfilesRequestEvent() {
} }
@Override
public UUID getUUID() {
return uuid;
}
@Override @Override
public String getType() { public String getType() {
return "profiles"; return "profiles";

View file

@ -5,9 +5,9 @@
import pro.gravit.launcher.LauncherNetworkAPI; import pro.gravit.launcher.LauncherNetworkAPI;
import pro.gravit.launcher.events.RequestEvent; import pro.gravit.launcher.events.RequestEvent;
import pro.gravit.launcher.profiles.ClientProfile; 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"); private static final UUID uuid = UUID.fromString("08c0de9e-4364-4152-9066-8354a3a48541");
@LauncherNetworkAPI @LauncherNetworkAPI
public ClientProfile newProfile; public ClientProfile newProfile;
@ -20,9 +20,4 @@ public SetProfileRequestEvent(ClientProfile newProfile) {
public String getType() { public String getType() {
return "setProfile"; return "setProfile";
} }
@Override
public UUID getUUID() {
return uuid;
}
} }

View file

@ -5,9 +5,9 @@
import pro.gravit.launcher.LauncherNetworkAPI; import pro.gravit.launcher.LauncherNetworkAPI;
import pro.gravit.launcher.events.RequestEvent; 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"); private static final UUID uuid = UUID.fromString("5fa836ae-6b61-401c-96ac-d8396f07ec6b");
@LauncherNetworkAPI @LauncherNetworkAPI
public final HashSet<String> dirs; public final HashSet<String> dirs;
@ -16,11 +16,6 @@ public UpdateListRequestEvent(HashSet<String> dirs) {
this.dirs = dirs; this.dirs = dirs;
} }
@Override
public UUID getUUID() {
return uuid;
}
@Override @Override
public String getType() { public String getType() {
return "updateList"; return "updateList";

View file

@ -1,8 +0,0 @@
package pro.gravit.utils.event;
import java.util.UUID;
@FunctionalInterface
public interface EventHandler<T extends EventInterface> {
void run(UUID uuid, T event);
}

View file

@ -1,7 +0,0 @@
package pro.gravit.utils.event;
import java.util.UUID;
public interface EventInterface {
UUID getUUID();
}

View file

@ -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<EventInterface> func, UUID[] events) {
this.func = func;
this.events = events;
}
EventHandler<EventInterface> 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<Entry> handlers = new ArrayList<>(INITIAL_HANDLERS_SIZE);
public BlockingQueue<QueueEntry> queue = new LinkedBlockingQueue<>(QUEUE_MAX_SIZE); //Максимальный размер очереди
public int registerHandler(EventHandler<EventInterface> 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<EventInterface> 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();
}
}
}
}