From 32e8065f4caf86d1c1373d6b6736285cf68e704a Mon Sep 17 00:00:00 2001 From: Gravit Date: Fri, 3 May 2019 20:21:10 +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=20=D0=BC=D0=BD=D0=BE=D0=B6=D0=B5=D1=81?= =?UTF-8?q?=D1=82=D0=B2=D0=B0=20WebSocket=20=D1=81=D0=BE=D0=B5=D0=B4=D0=B5?= =?UTF-8?q?=D0=BD=D0=B5=D0=BD=D0=B8=D0=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/ru/gravit/launcher/request/PingRequest.java | 4 +++- .../main/java/ru/gravit/launcher/request/Request.java | 10 ++++++++-- .../launcher/request/update/LauncherRequest.java | 3 ++- .../gravit/launcher/request/update/UpdateRequest.java | 3 ++- 4 files changed, 15 insertions(+), 5 deletions(-) diff --git a/LauncherAPI/src/main/java/ru/gravit/launcher/request/PingRequest.java b/LauncherAPI/src/main/java/ru/gravit/launcher/request/PingRequest.java index ae3c8ea7..d620530a 100644 --- a/LauncherAPI/src/main/java/ru/gravit/launcher/request/PingRequest.java +++ b/LauncherAPI/src/main/java/ru/gravit/launcher/request/PingRequest.java @@ -1,9 +1,11 @@ package ru.gravit.launcher.request; +import ru.gravit.launcher.request.websockets.StandartClientWebSocketService; + public final class PingRequest extends Request { @Override - protected ResultInterface requestDo() throws Exception { + protected ResultInterface requestDo(StandartClientWebSocketService service) throws Exception { return null; } 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 4469ad4b..eb98f3a7 100644 --- a/LauncherAPI/src/main/java/ru/gravit/launcher/request/Request.java +++ b/LauncherAPI/src/main/java/ru/gravit/launcher/request/Request.java @@ -36,11 +36,17 @@ public R request() throws Exception { if (!started.compareAndSet(false, true)) throw new IllegalStateException("Request already started"); if(service == null) service = StandartClientWebSocketService.initWebSockets(Launcher.getConfig().address, false); - return requestDo(); + return requestDo(service); + } + @LauncherAPI + public R request(StandartClientWebSocketService service) throws Exception { + if (!started.compareAndSet(false, true)) + throw new IllegalStateException("Request already started"); + return requestDo(service); } @SuppressWarnings("unchecked") - protected R requestDo() throws Exception + protected R requestDo(StandartClientWebSocketService service) throws Exception { return (R) service.sendRequest(this); } diff --git a/LauncherAPI/src/main/java/ru/gravit/launcher/request/update/LauncherRequest.java b/LauncherAPI/src/main/java/ru/gravit/launcher/request/update/LauncherRequest.java index 3c0be801..8980d008 100644 --- a/LauncherAPI/src/main/java/ru/gravit/launcher/request/update/LauncherRequest.java +++ b/LauncherAPI/src/main/java/ru/gravit/launcher/request/update/LauncherRequest.java @@ -7,6 +7,7 @@ import ru.gravit.launcher.events.request.LauncherRequestEvent; import ru.gravit.launcher.request.Request; import ru.gravit.launcher.request.websockets.RequestInterface; +import ru.gravit.launcher.request.websockets.StandartClientWebSocketService; import ru.gravit.utils.helper.IOHelper; import ru.gravit.utils.helper.JVMHelper; import ru.gravit.utils.helper.LogHelper; @@ -65,7 +66,7 @@ public static void update(LauncherRequestEvent result) throws IOException { } @Override - public LauncherRequestEvent requestDo() throws Exception { + public LauncherRequestEvent requestDo(StandartClientWebSocketService service) throws Exception { LauncherRequestEvent result = (LauncherRequestEvent) service.sendRequest(this); if (result.needUpdate) update(result); return result; diff --git a/LauncherAPI/src/main/java/ru/gravit/launcher/request/update/UpdateRequest.java b/LauncherAPI/src/main/java/ru/gravit/launcher/request/update/UpdateRequest.java index a39c21f2..c12c4ab9 100644 --- a/LauncherAPI/src/main/java/ru/gravit/launcher/request/update/UpdateRequest.java +++ b/LauncherAPI/src/main/java/ru/gravit/launcher/request/update/UpdateRequest.java @@ -12,6 +12,7 @@ import ru.gravit.launcher.request.Request; import ru.gravit.launcher.request.update.UpdateRequest.State.Callback; import ru.gravit.launcher.request.websockets.RequestInterface; +import ru.gravit.launcher.request.websockets.StandartClientWebSocketService; import ru.gravit.utils.helper.IOHelper; import ru.gravit.utils.helper.LogHelper; @@ -166,7 +167,7 @@ public double getTotalSizeMiB() { } @Override - public UpdateRequestEvent requestDo() throws Exception { + public UpdateRequestEvent requestDo(StandartClientWebSocketService service) throws Exception { LogHelper.debug("Start update request"); UpdateRequestEvent e = (UpdateRequestEvent) service.sendRequest(this); LogHelper.debug("Start update");