[FEATURE] Поддержка requestUUID на стороне клиента

This commit is contained in:
Gravit 2019-04-20 03:31:56 +07:00
parent 58858a0290
commit 4de0891dcc
3 changed files with 20 additions and 1 deletions

View file

@ -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<R extends ResultInterface> 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) {

View file

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

View file

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