[FEATURE] Поддержка множества WebSocket соеденений

This commit is contained in:
Gravit 2019-05-03 20:21:10 +07:00
parent b5014175d0
commit 32e8065f4c
No known key found for this signature in database
GPG key ID: 061981E1E85D3216
4 changed files with 15 additions and 5 deletions

View file

@ -1,9 +1,11 @@
package ru.gravit.launcher.request;
import ru.gravit.launcher.request.websockets.StandartClientWebSocketService;
public final class PingRequest extends Request<ResultInterface> {
@Override
protected ResultInterface requestDo() throws Exception {
protected ResultInterface requestDo(StandartClientWebSocketService service) throws Exception {
return null;
}

View file

@ -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);
}

View file

@ -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;

View file

@ -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");