mirror of
https://github.com/GravitLauncher/Launcher
synced 2024-12-23 09:01:08 +03:00
Экспериментальная фитча: RequestWorker
This commit is contained in:
parent
4300aafc38
commit
f21572879e
4 changed files with 46 additions and 2 deletions
|
@ -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) {
|
||||||
|
|
|
@ -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);
|
||||||
|
|
|
@ -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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue