mirror of
https://github.com/MovingBlocks/Terasology
synced 2026-05-24 09:28:22 +00:00
* rename docs to docs-pre-merge * add wiki content based on commit e4d4b10424f24eed6583ea0e998da8aa32a27a3f * replace wikilinks with markdown links in _sidebar * use sidebar link text as title via ` autoHeader: true` * rename files with `:` or `,` in the name * use the wiki Home page as entry point instead of the repo README
2.6 KiB
2.6 KiB
Migrating to Project Reactor
Motivation
The two main reasons we are adopting Reactor for our concurrent operations:
- Using a consistent API helps with thread management, making it easier to allocate the right amount of threads and clean them up when we need to.
- The Flux API offered by Project Reactor provides better ways to define and schedule asynchronous operations than the standard Java API does.
Deprecations
- The creation of threads and threadpools is something that should be mediated by the engine.
Modules should not be using
new Thread()directly. - o.t.e.utilites.concurrency.TaskMaster and its related
Taskclass.
New Interfaces
Most Project Reactor classes (from Reactor Core, Reactor Extra, and Reactor Test) are available to modules. The Reactor Reference Guide includes an introduction to them. (It occasionally assumes familiarity with the Reactive Streams specification, but its examples are complete on their own.)
The o.t.e.core.GameScheduler class provides methods for scheduling work or obtaining a Scheduler instance.
Migration Guide
TaskMaster
Replacements for TaskMaster methods:
TaskMaster.create*(name, threads): UseGameSchedulerto use an existingSchedulerinstance. We do not expect modules need to create new Schedulers.Task: Runnable. (Runnable is a Functional Interface in Java; any zero-argument method may be passed anywhere a Runnable is expected.)task.getName(): Pass a name toGameScheduler.scheduleParallel(name, task).tm.offer(task):GameScheduler.scheduleParallel(name, task).tm.put(task): This is a blocking method; no direct replacement is offered. Replace it with an asynchronous method, perhaps using Reactor's Mono to schedule work to continue after its completion.
The above methods are only the ones that most directly correspond to the old TaskMaster interface. You will likely want to take advantage of other Flux operations to use the results of asynchronous methods and handle errors.