From 4de0891dcc15db128fae28b85319e2f312786a5c Mon Sep 17 00:00:00 2001 From: Gravit Date: Sat, 20 Apr 2019 03:31:56 +0700 Subject: [PATCH] =?UTF-8?q?[FEATURE]=20=D0=9F=D0=BE=D0=B4=D0=B4=D0=B5?= =?UTF-8?q?=D1=80=D0=B6=D0=BA=D0=B0=20requestUUID=20=D0=BD=D0=B0=20=D1=81?= =?UTF-8?q?=D1=82=D0=BE=D1=80=D0=BE=D0=BD=D0=B5=20=D0=BA=D0=BB=D0=B8=D0=B5?= =?UTF-8?q?=D0=BD=D1=82=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/ru/gravit/launcher/request/Request.java | 4 ++++ .../websockets/StandartClientWebSocketService.java | 5 +++++ .../request/websockets/WaitEventHandler.java | 12 +++++++++++- 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/LauncherAPI/src/main/java/ru/gravit/launcher/request/Request.java b/LauncherAPI/src/main/java/ru/gravit/launcher/request/Request.java index 7567d4f7..6f1ad51e 100644 --- a/LauncherAPI/src/main/java/ru/gravit/launcher/request/Request.java +++ b/LauncherAPI/src/main/java/ru/gravit/launcher/request/Request.java @@ -2,14 +2,18 @@ import ru.gravit.launcher.Launcher; import ru.gravit.launcher.LauncherAPI; +import ru.gravit.launcher.LauncherNetworkAPI; import ru.gravit.launcher.request.websockets.RequestInterface; import ru.gravit.launcher.request.websockets.StandartClientWebSocketService; import ru.gravit.utils.helper.SecurityHelper; +import java.util.UUID; import java.util.concurrent.atomic.AtomicBoolean; public abstract class Request implements RequestInterface { private static long session = SecurityHelper.secureRandom.nextLong(); + @LauncherNetworkAPI + public UUID requestUUID = UUID.randomUUID(); public static StandartClientWebSocketService service; public static void setSession(long session) { diff --git a/LauncherAPI/src/main/java/ru/gravit/launcher/request/websockets/StandartClientWebSocketService.java b/LauncherAPI/src/main/java/ru/gravit/launcher/request/websockets/StandartClientWebSocketService.java index 4ed7284d..5564d6f3 100644 --- a/LauncherAPI/src/main/java/ru/gravit/launcher/request/websockets/StandartClientWebSocketService.java +++ b/LauncherAPI/src/main/java/ru/gravit/launcher/request/websockets/StandartClientWebSocketService.java @@ -2,6 +2,7 @@ import com.google.gson.GsonBuilder; import ru.gravit.launcher.events.request.ErrorRequestEvent; +import ru.gravit.launcher.request.Request; import ru.gravit.launcher.request.RequestException; import ru.gravit.launcher.request.ResultInterface; import ru.gravit.utils.helper.JVMHelper; @@ -23,6 +24,10 @@ public class RequestFuture implements Future public RequestFuture(RequestInterface request) throws IOException { event = new WaitEventHandler.ResultEvent(); event.type = request.getType(); + if(request instanceof Request) + { + event.uuid = ((Request) request).requestUUID; + } waitEventHandler.requests.add(event); sendObject(request); } diff --git a/LauncherAPI/src/main/java/ru/gravit/launcher/request/websockets/WaitEventHandler.java b/LauncherAPI/src/main/java/ru/gravit/launcher/request/websockets/WaitEventHandler.java index 72211e20..5eab8915 100644 --- a/LauncherAPI/src/main/java/ru/gravit/launcher/request/websockets/WaitEventHandler.java +++ b/LauncherAPI/src/main/java/ru/gravit/launcher/request/websockets/WaitEventHandler.java @@ -1,9 +1,11 @@ package ru.gravit.launcher.request.websockets; +import ru.gravit.launcher.events.RequestEvent; import ru.gravit.launcher.request.ResultInterface; import ru.gravit.utils.helper.LogHelper; import java.util.HashSet; +import java.util.UUID; public class WaitEventHandler implements ClientWebSocketService.EventHandler { public HashSet requests = new HashSet<>(); @@ -11,9 +13,16 @@ public class WaitEventHandler implements ClientWebSocketService.EventHandler { @Override public void process(ResultInterface result) { LogHelper.debug("Processing event %s type", result.getType()); + UUID checkUUID = null; + if(result instanceof RequestEvent) + { + RequestEvent event = (RequestEvent) result; + checkUUID = event.requestUUID; + } for (ResultEvent r : requests) { - if (r.type.equals(result.getType()) || result.getType().equals("error")) { + if( (r.uuid != null && r.uuid.equals(checkUUID)) || ( r.uuid == null && (r.type.equals(result.getType()) || result.getType().equals("error") )) ) { LogHelper.debug("Event %s type", r.type); + LogHelper.debug("Event UUID contains: %s", (r.uuid != null && r.uuid.equals(checkUUID)) ? "true" : "false"); synchronized (r) { r.result = result; r.ready = true; @@ -25,6 +34,7 @@ public void process(ResultInterface result) { public static class ResultEvent { public ResultInterface result; + public UUID uuid; public String type; public boolean ready; }