From 0d804a0558dcab54dc785801146660a632a04ede Mon Sep 17 00:00:00 2001 From: Gravit Date: Mon, 28 Jan 2019 23:29:54 +0700 Subject: [PATCH] =?UTF-8?q?[FEATURE]=20=D0=9C=D0=BE=D1=81=D1=82=20=D0=B4?= =?UTF-8?q?=D0=BB=D1=8F=20=D1=81=D1=82=D0=B0=D1=80=D1=8B=D1=85=20Request?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../websockets/LegacyRequestBridge.java | 23 +++++++++++++++++++ .../request/websockets/WaitEventHandler.java | 2 +- 2 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 LauncherAPI/src/main/java/ru/gravit/launcher/request/websockets/LegacyRequestBridge.java diff --git a/LauncherAPI/src/main/java/ru/gravit/launcher/request/websockets/LegacyRequestBridge.java b/LauncherAPI/src/main/java/ru/gravit/launcher/request/websockets/LegacyRequestBridge.java new file mode 100644 index 00000000..03659c42 --- /dev/null +++ b/LauncherAPI/src/main/java/ru/gravit/launcher/request/websockets/LegacyRequestBridge.java @@ -0,0 +1,23 @@ +package ru.gravit.launcher.request.websockets; + +import ru.gravit.launcher.request.ResultInterface; + +import java.io.IOException; + +public class LegacyRequestBridge { + public static WaitEventHandler waitEventHandler = new WaitEventHandler(); + public static ClientWebSocketService service; + public static ResultInterface sendRequest(RequestInterface request) throws IOException, InterruptedException { + WaitEventHandler.ResultEvent e = new WaitEventHandler.ResultEvent(); + e.type = request.getType(); + waitEventHandler.requests.add(e); + service.sendObject(request); + while(!e.ready) + { + e.wait(); + } + ResultInterface result = e.result; + waitEventHandler.requests.remove(e); + return result; + } +} 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 4dd1fc61..45aa9f78 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 @@ -21,7 +21,7 @@ public void process(ResultInterface result) { } } } - public class ResultEvent + public static class ResultEvent { public ResultInterface result; public String type;