Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
68 commits
Select commit Hold shift + click to select a range
95091b9
Rename task dependency accessors to getPredecessors and getSuccessors
Glavo Nov 22, 2026
43461f1
Rename task dependency accessors to predecessor and successor terms
Glavo Nov 22, 2026
1c303a5
Refactor tasks to return results through synchronous execution contexts
Glavo Nov 22, 2026
025e76a
Use a single executor for each task body
Glavo Nov 22, 2026
906370a
Inherit task executors from the parent execution context
Glavo Nov 22, 2026
f3e2f6d
Remove task completion events and scope modpack cleanup to execution
Glavo Nov 22, 2026
ffeba3a
Move task cancellation checks to the execution context
Glavo Nov 22, 2026
9dfeed0
Scope task stages and progress to execution contexts
Glavo Nov 22, 2026
1f759fe
Replace task properties with explicit stage progress counters
Glavo Nov 22, 2026
902018d
Rename task executors to task handles
Glavo Nov 22, 2026
e59418b
Reject repeated task submissions with atomic execution claims
Glavo Nov 22, 2026
1de69fd
Publish task results and exceptions together with terminal state
Glavo Nov 22, 2026
03ed64e
Unify task lifecycle listener callbacks around stage and failure
Glavo Nov 22, 2026
e30ff51
Rename StagesHint to StageHint and clarify stage grouping
Glavo Nov 22, 2026
98cf3e3
Replace string stage identifiers with typed StageId constants
Glavo Nov 22, 2026
56e3dec
Rename StageId to TaskStage and TaskStage to TaskStageInstance
Glavo Nov 22, 2026
d8362f8
Replace TaskStageInstance with nested TaskStage.Scope
Glavo Nov 22, 2026
270a52c
Move task stage hints into TaskStage
Glavo Nov 22, 2026
747adb1
Initialize withStageHints wrapper significance during construction
Glavo Nov 22, 2026
f44b5a7
Create task work change condition lazily
Glavo Nov 22, 2026
c385ebb
Split nullable task composition into optional variants
Glavo Nov 22, 2026
b4104ec
Add TaskProgress reporter to TaskExecutionContext
Glavo Nov 23, 2026
7d0e29e
Defer task progress row creation until JavaFX rendering
Glavo Nov 23, 2026
00249a8
Mark TaskListPane.Node as sealed
Glavo Nov 23, 2026
e68ce84
Remove task progress rate limiting
Glavo Nov 23, 2026
5d28a41
Remove empty-list check before notifying task progress listeners
Glavo Nov 23, 2026
07f231f
Move task listener notification into TaskHandle
Glavo Nov 23, 2026
50b9133
Remove non-atomic listener array write from TaskHandle
Glavo Nov 23, 2026
0efb631
Change TaskHandle.notifyListeners to accept an ExceptionalConsumer
Glavo Nov 23, 2026
2d3b2db
Remove TaskHandleDialogPaneTest
Glavo Nov 23, 2026
148f8e2
Add int overload to MathUtils.clamp and use it for scheduler pool sizing
Glavo Nov 23, 2026
331dcb8
Allow null executors for Task continuations to run on the calling thread
Glavo Nov 23, 2026
ac65238
Remove name parameters from Task factory and continuation methods
Glavo Nov 23, 2026
5c4a0b4
Remove redundant explicit type arguments from Task.of calls
Glavo Nov 23, 2026
98e2ea1
Extract TaskSignificance from Task into a top-level enum
Glavo Nov 23, 2026
de424c6
Replace Schedulers.defaultScheduler() with Schedulers.io() and remove it
Glavo Nov 23, 2026
f1821a7
Represent task failures as Throwable instead of Exception
Glavo Nov 23, 2026
f6352ef
Add tryRun and tryRunAll to TaskExecutionContext for tolerant children
Glavo Nov 23, 2026
d7c1e50
Remove TaskHandle and let Task manage its own execution state
Glavo Nov 23, 2026
d2cc293
Rename root and child claiming to marking tasks ready
Glavo Nov 23, 2026
ef0e5ee
Make Task.getExecutor protected and annotate setSignificance with @Co…
Glavo Nov 23, 2026
8221be4
Remove Task.recover and the Recovery interface
Glavo Nov 23, 2026
34f7745
Reorder the members of Task to group related declarations
Glavo Nov 23, 2026
7666f1d
Annotate Task.setName with @Contract and suppress nullable warnings i…
Glavo Nov 23, 2026
95ac772
Link the state VarHandles to their guarded fields with @see
Glavo Nov 23, 2026
a702656
Move the private constructor of InstallStages below its factory method
Glavo Nov 23, 2026
086b583
Replace the sentinel object for child tasks with a sealed ExecutionRole
Glavo Nov 23, 2026
05e033f
Replace the sealed ExecutionRole with a single ExecutionBinding record
Glavo Nov 23, 2026
9ec44c0
Split cancellation requests from cancelled completion in Task
Glavo Nov 23, 2026
3652be4
Rename Task.TaskState to Task.State
Glavo Nov 23, 2026
975517d
Remove the EXECUTED state and simplify running-state publication in Task
Glavo Nov 23, 2026
f05a835
Add a CANCELLED state to distinguish cancellation from failure in Task
Glavo Nov 23, 2026
16a3184
Consolidate the result and exception fields in Task into a single out…
Glavo Nov 23, 2026
08d37a8
Replace String task names with a TaskName type
Glavo Nov 23, 2026
7fc01c6
Dispatch task decorators on the source's executor
Glavo Nov 23, 2026
ddf56f4
Add a bounded concurrency limit to runAll task batches
Glavo Nov 23, 2026
585c238
Defer work registration until after submission and restrict helping
Glavo Nov 23, 2026
b8f30c9
Introduce UnboundedExecutorService to mark executors with independent…
Glavo Nov 23, 2026
9d6b661
Reduce fallback scheduler parallelism and use 64-bit worker IDs
Glavo Nov 23, 2026
6d3a0f9
Make FakeProgressTask static and pass its source task explicitly
Glavo Nov 23, 2026
cd42b77
Make task display names optional
Glavo Nov 23, 2026
5f00e50
Add a String overload for Task.setName
Glavo Nov 23, 2026
006e60f
Replace private Task.of helpers with direct Task implementations
Glavo Nov 23, 2026
98b7a97
Remove Task.runSequentially
Glavo Nov 23, 2026
35ee55a
Add inline Task continuations and schedule async callbacks by default
Glavo Nov 23, 2026
010b0f8
Add Task.handle and Task.handleAsync continuations
Glavo Nov 23, 2026
a2ce134
Preserve task results through Task.whenComplete
Glavo Nov 23, 2026
678e078
Migrate Task completion callbacks to the new API
Glavo Nov 23, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions HMCL/src/main/java/org/jackhuang/hmcl/Launcher.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
import javafx.util.Duration;
import org.jackhuang.hmcl.game.HMCLCacheRepository;
import org.jackhuang.hmcl.setting.*;
import org.jackhuang.hmcl.task.AsyncTaskExecutor;
import org.jackhuang.hmcl.task.Schedulers;
import org.jackhuang.hmcl.task.Task;
import org.jackhuang.hmcl.ui.Controllers;
import org.jackhuang.hmcl.ui.FXUtils;
import org.jackhuang.hmcl.ui.animation.AnimationUtils;
Expand Down Expand Up @@ -277,7 +277,7 @@ public static void main(String[] args) {
}

Thread.setDefaultUncaughtExceptionHandler(CRASH_REPORTER);
AsyncTaskExecutor.setUncaughtExceptionHandler(new CrashReporter(false));
Task.setUncaughtExceptionHandler(new CrashReporter(false));

try {
LOG.info("*** " + Metadata.TITLE + " ***");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,12 @@
import org.jackhuang.hmcl.download.DownloadProvider;
import org.jackhuang.hmcl.addon.LocalAddonFile;
import org.jackhuang.hmcl.addon.RemoteAddon;
import org.jackhuang.hmcl.task.FetchTask;
import org.jackhuang.hmcl.task.Schedulers;
import org.jackhuang.hmcl.task.Task;
import org.jackhuang.hmcl.task.TaskExecutionContext;
import org.jackhuang.hmcl.task.TaskSignificance;
import org.jackhuang.hmcl.task.TaskStage;
import org.jackhuang.hmcl.util.Pair;
import org.jetbrains.annotations.Nullable;

Expand All @@ -15,14 +19,19 @@
import java.util.Collection;
import java.util.List;
import java.util.Objects;
import java.util.concurrent.CancellationException;

import static org.jackhuang.hmcl.util.logging.Logger.LOG;

public class AddonCheckUpdatesTask extends Task<AddonUpdates> {
private final List<Task<Pair<AddonUpdate, @Nullable AddonUpdate>>> dependents;
/// The stage shared by add-on update checks and their progress dialogs.
public static final TaskStage STAGE = new TaskStage("update.checking");

/// One update check per installed add-on.
private final List<Task<@Nullable Pair<AddonUpdate, @Nullable AddonUpdate>>> checks;

public AddonCheckUpdatesTask(DownloadProvider downloadProvider, String gameVersion, Collection<? extends LocalAddonFile<?>> addons) {
dependents = addons.stream().map(addon ->
checks = addons.stream().map(addon ->
Task.supplyAsync(Schedulers.io(), () -> {
AddonUpdate candidate = null;
AddonUpdate candidateRelease = null;
Expand All @@ -49,41 +58,36 @@ public AddonCheckUpdatesTask(DownloadProvider downloadProvider, String gameVersi

if (candidate == null) return null; // If there's no candidate for all channels, then no candidate for release channel
return Pair.pair(candidate, candidateRelease);
}).setName(addon.getFileName()).setSignificance(TaskSignificance.MAJOR).withCounter("update.checking")
}).setName(addon.getFileName()).setSignificance(TaskSignificance.MAJOR).withCounter()
).toList();

setStage("update.checking");
getProperties().put("total", dependents.size());
}

@Override
public boolean doPreExecute() {
return true;
}

/// Returns the stage for addon update checks.
@Override
public void preExecute() {
notifyPropertiesChanged();
public TaskStage getStage() {
return STAGE;
}

/// Collects available updates from all checks that completed successfully.
@Override
public Collection<? extends Task<?>> getDependents() {
return dependents;
}
public AddonUpdates execute(TaskExecutionContext context) throws Exception {
context.addStageItems(checks.size());
try {
context.runAll(checks, FetchTask.getDownloadExecutorConcurrency());
} catch (Exception failure) {
if (context.isCancelled() || failure instanceof InterruptedException || failure instanceof CancellationException)
throw failure;
// Other add-ons can still contribute updates after a failed check.
}

@Override
public boolean isRelyingOnDependents() {
return false;
}

@Override
public void execute() throws Exception {
List<AddonUpdate> commonUpdates = new ArrayList<>(), releaseUpdates = new ArrayList<>();
dependents.stream().map(Task::getResult).filter(Objects::nonNull)
checks.stream()
.map(Task::resultNowOrNull)
.filter(Objects::nonNull)
.forEachOrdered(pair -> {
commonUpdates.add(pair.key());
if (pair.value() != null) releaseUpdates.add(pair.value());
});
setResult(new AddonUpdates(commonUpdates, releaseUpdates));
return new AddonUpdates(commonUpdates, releaseUpdates);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,14 @@
import org.jackhuang.hmcl.addon.LocalAddonManager;
import org.jackhuang.hmcl.addon.RemoteAddon;
import org.jackhuang.hmcl.download.DownloadProvider;
import org.jackhuang.hmcl.task.FetchTask;
import org.jackhuang.hmcl.task.FileDownloadTask;
import org.jackhuang.hmcl.task.Schedulers;
import org.jackhuang.hmcl.task.Task;
import org.jackhuang.hmcl.task.TaskExecutionContext;
import org.jackhuang.hmcl.task.TaskStage;
import org.jackhuang.hmcl.util.StringUtils;
import org.jetbrains.annotations.Nullable;

import java.io.IOException;
import java.nio.file.Files;
Expand All @@ -20,14 +24,12 @@

import static org.jackhuang.hmcl.util.logging.Logger.LOG;

public class AddonUpdateTask extends Task<Void> {
private final Collection<Task<?>> dependents = new ArrayList<>();
public class AddonUpdateTask extends Task<@Nullable Void> {
/// Independent per-add-on update tasks.
private final Collection<Task<?>> updates = new ArrayList<>();
private final List<LocalAddonFile<?>> failedAddons = new ArrayList<>();

public AddonUpdateTask(DownloadProvider downloadProvider, Path addonDirectory, List<AddonUpdate> addons) {
setStage("addon.check_update.confirm");
getProperties().put("total", addons.size());

for (AddonUpdate addon : addons) {
LocalAddonFile<?> local = addon.localAddonFile();
RemoteAddon.Version remote = addon.targetVersion();
Expand All @@ -38,14 +40,14 @@ public AddonUpdateTask(DownloadProvider downloadProvider, Path addonDirectory, L
String newFileName = fileName;
Path targetFile = addonDirectory.resolve(newFileName);

dependents.add(Task
updates.add(Task
.supplyAsync(Schedulers.io(), () -> Files.createTempFile("hmcl-addon-update-", ".tmp"))
.thenComposeAsync(tempFile ->
new FileDownloadTask(downloadProvider.getDownloadCandidates(remote.file().url()), tempFile)
.setName(remote.name())
.thenRunAsync(Schedulers.javafx(), () -> local.setOld(true))
.thenRunAsync(Schedulers.io(), () -> Files.move(tempFile, targetFile))
.whenComplete(Schedulers.javafx(), exception -> {
.whenCompleteAsync(Schedulers.javafx(), (ignored, exception) -> {
try {
Files.deleteIfExists(tempFile);
} catch (Exception e) {
Expand All @@ -67,42 +69,30 @@ public AddonUpdateTask(DownloadProvider downloadProvider, Path addonDirectory, L
}
}
})
).whenComplete(Schedulers.javafx(), exception -> {
).whenCompleteAsync(Schedulers.javafx(), (ignored, exception) -> {
if (exception != null) {
LOG.warning("Failed to update addon", exception);
failedAddons.add(local);
}
}).withCounter("addon.check_update.confirm"));
}).withCounter());
}
}

public List<LocalAddonFile<?>> getFailedAddons() {
return failedAddons;
}

/// Returns the stage for addon updates.
@Override
public Collection<Task<?>> getDependents() {
return dependents;
}

@Override
public boolean doPreExecute() {
return true;
}

@Override
public void preExecute() {
notifyPropertiesChanged();
}

@Override
public boolean isRelyingOnDependents() {
return false;
public TaskStage getStage() {
return new TaskStage("addon.check_update.confirm");
}

/// Downloads the selected updates and waits for each addon's cleanup to finish.
@Override
public void execute() throws Exception {
if (!isDependentsSucceeded())
throw getException();
public @Nullable Void execute(TaskExecutionContext context) throws Exception {
context.addStageItems(updates.size());
context.runAll(updates, FetchTask.getDownloadExecutorConcurrency());
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,14 @@
import org.jackhuang.hmcl.game.HMCLCacheRepository;
import org.jackhuang.hmcl.setting.DownloadSource;
import org.jackhuang.hmcl.task.Task;
import org.jackhuang.hmcl.task.TaskExecutionContext;
import org.jackhuang.hmcl.util.RegionUtils;
import org.jackhuang.hmcl.util.versioning.GameVersionNumber;
import org.jetbrains.annotations.NotNullByDefault;
import org.jetbrains.annotations.Nullable;

import java.util.*;
import java.util.concurrent.CancellationException;

/// @author Glavo
@NotNullByDefault
Expand Down Expand Up @@ -259,37 +261,22 @@ private static final class FallbackTask<T> extends Task<T> {
private final Task<? extends T> task;
private final Task<? extends T> fallback;

private List<Task<?>> dependencies = List.of();

public FallbackTask(Task<? extends T> task, Task<? extends T> fallback) {
this.task = task;
this.fallback = fallback;
}

/// Tries the alternate source if the primary source fails.
@Override
public Collection<? extends Task<?>> getDependents() {
return List.of(task);
}

@Override
public boolean isRelyingOnDependents() {
return false;
}

@Override
public void execute() throws Exception {
if (isDependentsSucceeded()) {
setResult(task.getResult());
} else {
dependencies = List.of(fallback);
fallback.storeTo(this::setResult);
public T execute(TaskExecutionContext context) throws Exception {
try {
return context.run(task);
} catch (Exception failure) {
if (context.isCancelled() || failure instanceof InterruptedException || failure instanceof CancellationException)
throw failure;
return context.run(fallback);
}
}

@Override
public List<Task<?>> getDependencies() {
return dependencies;
}
}

@NotNullByDefault
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@

import com.google.gson.JsonParseException;
import org.jackhuang.hmcl.download.DefaultDependencyManager;
import org.jackhuang.hmcl.download.GameBuilder;
import org.jackhuang.hmcl.download.InstallStages;
import org.jackhuang.hmcl.modpack.MinecraftInstanceTask;
import org.jackhuang.hmcl.modpack.Modpack;
import org.jackhuang.hmcl.modpack.ModpackConfiguration;
import org.jackhuang.hmcl.modpack.ModpackInstallTask;
import org.jackhuang.hmcl.task.Task;
import org.jackhuang.hmcl.task.TaskExecutionContext;
import org.jackhuang.hmcl.util.gson.JsonUtils;
import org.jackhuang.hmcl.util.io.CompressingUtils;
import org.jetbrains.annotations.NotNullByDefault;
Expand All @@ -24,18 +25,17 @@

/// Installs or updates an HMCL modpack by rebuilding its recognized game components.
@NotNullByDefault
public final class HMCLModpackInstallTask extends Task<Void> {
public final class HMCLModpackInstallTask extends Task<@Nullable Void> {
private final Path zipFile;
private final GameInstanceID instanceId;

/// Existing instance selecting update mode, or `null` for a new installation.
private final @Nullable DefaultGameInstance updateTarget;

private final HMCLGameRepository repository;
private final DefaultDependencyManager dependency;
private final Modpack modpack;
private final List<Task<?>> dependencies = new ArrayList<>(1);
private final List<Task<?>> dependents = new ArrayList<>(4);
/// The tasks that install the instance and prepare its modpack files.
private final List<Task<?>> preparation = new ArrayList<>(4);

/// Creates a task that installs a new HMCL modpack instance.
///
Expand Down Expand Up @@ -82,7 +82,6 @@ private HMCLModpackInstallTask(
Modpack modpack,
GameInstanceID instanceId,
@Nullable DefaultGameInstance updateTarget) {
this.repository = repository;
this.dependency = repository.getDependency();
this.zipFile = zipFile;
this.instanceId = instanceId;
Expand All @@ -108,41 +107,23 @@ private HMCLModpackInstallTask(
} catch (JsonParseException | IOException ignore) {
}

onDone().register(event -> {
if (this.updateTarget == null && event.isFailed()) {
repository.removeInstanceFromDisk(this.instanceId);
}
});

dependents.add(new ModpackInstallTask<>(zipFile, run, List.of("/minecraft"), it -> !"pack.json".equals(it), config));
dependents.add(new MinecraftInstanceTask<>(zipFile, List.of("/minecraft"), modpack, HMCLModpackProvider.INSTANCE, modpack.getName(), modpack.getVersion(), repository.getLayout().getModpackConfigurationFile(this.instanceId)).withStage("hmcl.modpack"));
}

@Override
public List<Task<?>> getDependencies() {
return dependencies;
preparation.add(new ModpackInstallTask<>(zipFile, run, List.of("/minecraft"), it -> !"pack.json".equals(it), config));
preparation.add(new MinecraftInstanceTask<>(zipFile, List.of("/minecraft"), modpack, HMCLModpackProvider.INSTANCE, modpack.getName(), modpack.getVersion(), repository.getLayout().getModpackConfigurationFile(this.instanceId)).withStage(InstallStages.MODPACK));
}

@Override
public List<Task<?>> getDependents() {
return dependents;
}

/// Reads the legacy pack manifest and schedules one builder for all recognized components.
/// Reserves the target before extracting the pack and installs its recognized components.
///
/// The pack manifest is used only for component detection. The builder creates a new
/// patch-structured manifest instead of attempting to mutate the legacy flattened manifest.
@Override
public void execute() throws Exception {
String json = CompressingUtils.readTextZipEntry(zipFile, "minecraft/pack.json");
GameInstanceManifest originalManifest = JsonUtils.fromNonNullJson(json, GameInstanceManifest.class)
.withId(instanceId)
.withJar(null);
GameComponentAnalyzer analyzer = GameComponentAnalyzer.analyze(originalManifest, null);

try (GameBuilder builder = updateTarget == null
? dependency.newGameBuilder(instanceId)
: dependency.newGameBuilder(updateTarget)) {
public @Nullable Void execute(TaskExecutionContext context) throws Exception {
Modpack.installWithGameBuilder(dependency, instanceId, updateTarget, false, builder -> {
context.runAll(preparation);
String json = CompressingUtils.readTextZipEntry(zipFile, "minecraft/pack.json");
GameInstanceManifest originalManifest = JsonUtils.fromNonNullJson(json, GameInstanceManifest.class)
.withId(instanceId)
.withJar(null);
GameComponentAnalyzer analyzer = GameComponentAnalyzer.analyze(originalManifest, null);
builder.enableIsolation();

String gameVersion = modpack.getGameVersion();
Expand All @@ -163,8 +144,9 @@ public void execute() throws Exception {
builder.component(mark.componentType(), componentVersion);
}
}
dependencies.add(builder.buildAsync());
}
context.run(builder.buildAsync());
});
return null;
}

}
Loading
Loading