Экспериментальная фитча: RequestWorker

This commit is contained in:
Gravit 2018-11-11 16:13:14 +07:00
parent 4300aafc38
commit f21572879e
No known key found for this signature in database
GPG key ID: 061981E1E85D3216
4 changed files with 46 additions and 2 deletions

View file

@ -95,11 +95,11 @@ function newTask(r) {
} }
function newRequestTask(request) { function newRequestTask(request) {
return newTask(function() request.request()); FunctionalBridge.makeRequest(request,)
} }
function startTask(task) { function startTask(task) {
CommonHelper.newThread("FX Task Thread", true, task).start(); FunctionalBridge.startTask(task);
} }
function openURL(url) { function openURL(url) {

View file

@ -212,6 +212,8 @@ public void start(String... args) throws Throwable {
throw new IllegalStateException("Launcher has been already started"); throw new IllegalStateException("Launcher has been already started");
Launcher.modulesManager.initModules(); Launcher.modulesManager.initModules();
// Load init.js script // Load init.js script
FunctionalBridge.worker = new RequestWorker();
CommonHelper.newThread("FX Task Worker", true, FunctionalBridge.worker);
loadScript(Launcher.API_SCRIPT_FILE); loadScript(Launcher.API_SCRIPT_FILE);
loadScript(Launcher.CONFIG_SCRIPT_FILE); loadScript(Launcher.CONFIG_SCRIPT_FILE);
loadScript(Launcher.INIT_SCRIPT_FILE); loadScript(Launcher.INIT_SCRIPT_FILE);

View file

@ -1,11 +1,14 @@
package ru.gravit.launcher.client; package ru.gravit.launcher.client;
import javafx.concurrent.Task;
import ru.gravit.launcher.LauncherAPI; import ru.gravit.launcher.LauncherAPI;
import ru.gravit.launcher.hasher.FileNameMatcher; import ru.gravit.launcher.hasher.FileNameMatcher;
import ru.gravit.launcher.hasher.HashedDir; import ru.gravit.launcher.hasher.HashedDir;
import ru.gravit.launcher.request.Request; import ru.gravit.launcher.request.Request;
import ru.gravit.launcher.request.update.LegacyLauncherRequest; import ru.gravit.launcher.request.update.LegacyLauncherRequest;
import ru.gravit.launcher.request.websockets.RequestInterface;
import ru.gravit.launcher.serialize.signed.SignedObjectHolder; import ru.gravit.launcher.serialize.signed.SignedObjectHolder;
import ru.gravit.utils.helper.CommonHelper;
import java.io.IOException; import java.io.IOException;
import java.nio.file.Path; import java.nio.file.Path;
@ -14,6 +17,8 @@
public class FunctionalBridge { public class FunctionalBridge {
@LauncherAPI @LauncherAPI
public static LauncherSettings settings; public static LauncherSettings settings;
@LauncherAPI
public static RequestWorker worker;
@LauncherAPI @LauncherAPI
public HashedDirRunnable offlineUpdateRequest(String dirName, Path dir, SignedObjectHolder<HashedDir> hdir, FileNameMatcher matcher, boolean digest) throws Exception { public HashedDirRunnable offlineUpdateRequest(String dirName, Path dir, SignedObjectHolder<HashedDir> hdir, FileNameMatcher matcher, boolean digest) throws Exception {
@ -45,4 +50,14 @@ public LegacyLauncherRequest.Result offlineLauncherRequest() throws IOException,
public interface HashedDirRunnable { public interface HashedDirRunnable {
SignedObjectHolder<HashedDir> run() throws Exception; SignedObjectHolder<HashedDir> run() throws Exception;
} }
@LauncherAPI
public void makeJsonRequest(RequestInterface request, Runnable callback)
{
}
@LauncherAPI
public void startTask(Task task)
{
worker.queue.offer(task);
}
} }

View file

@ -0,0 +1,27 @@
package ru.gravit.launcher.client;
import javafx.concurrent.Task;
import ru.gravit.launcher.LauncherAPI;
import ru.gravit.launcher.request.Request;
import ru.gravit.utils.helper.LogHelper;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;
public class RequestWorker implements Runnable {
public RequestWorker()
{
queue = new LinkedBlockingQueue<>(64);
}
public BlockingQueue<Task> queue;
@Override
public void run() {
while (!Thread.interrupted())
{
Task task = queue.poll();
if (task != null) {
task.run();
}
}
}
}