mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2025-07-03 08:26:11 +00:00
Iris but forkjoin
This commit is contained in:
parent
72b4c9c6ab
commit
d686d07d53
@ -27,7 +27,6 @@ import com.volmit.iris.core.link.MultiverseCoreLink;
|
|||||||
import com.volmit.iris.core.link.MythicMobsLink;
|
import com.volmit.iris.core.link.MythicMobsLink;
|
||||||
import com.volmit.iris.core.link.OraxenLink;
|
import com.volmit.iris.core.link.OraxenLink;
|
||||||
import com.volmit.iris.core.nms.INMS;
|
import com.volmit.iris.core.nms.INMS;
|
||||||
import com.volmit.iris.core.project.IrisProject;
|
|
||||||
import com.volmit.iris.core.project.loader.IrisData;
|
import com.volmit.iris.core.project.loader.IrisData;
|
||||||
import com.volmit.iris.core.service.StudioSVC;
|
import com.volmit.iris.core.service.StudioSVC;
|
||||||
import com.volmit.iris.engine.object.biome.IrisBiome;
|
import com.volmit.iris.engine.object.biome.IrisBiome;
|
||||||
@ -49,6 +48,7 @@ import com.volmit.iris.util.io.InstanceState;
|
|||||||
import com.volmit.iris.util.io.JarScanner;
|
import com.volmit.iris.util.io.JarScanner;
|
||||||
import com.volmit.iris.util.math.M;
|
import com.volmit.iris.util.math.M;
|
||||||
import com.volmit.iris.util.math.RNG;
|
import com.volmit.iris.util.math.RNG;
|
||||||
|
import com.volmit.iris.util.parallel.BurstExecutor;
|
||||||
import com.volmit.iris.util.parallel.MultiBurst;
|
import com.volmit.iris.util.parallel.MultiBurst;
|
||||||
import com.volmit.iris.util.plugin.*;
|
import com.volmit.iris.util.plugin.*;
|
||||||
import com.volmit.iris.util.reflect.ShadeFix;
|
import com.volmit.iris.util.reflect.ShadeFix;
|
||||||
@ -165,6 +165,7 @@ public class Iris extends VolmitPlugin implements Listener {
|
|||||||
HandlerList.unregisterAll((Plugin) this);
|
HandlerList.unregisterAll((Plugin) this);
|
||||||
postShutdown.forEach(Runnable::run);
|
postShutdown.forEach(Runnable::run);
|
||||||
services.clear();
|
services.clear();
|
||||||
|
MultiBurst.burst.close();
|
||||||
super.onDisable();
|
super.onDisable();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -604,14 +605,7 @@ public class Iris extends VolmitPlugin implements Listener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void verbose(String string) {
|
public static void verbose(String string) {
|
||||||
try {
|
debug(string);
|
||||||
if (IrisSettings.get().getGeneral().isVerbose()) {
|
|
||||||
msg(C.GRAY + string);
|
|
||||||
}
|
|
||||||
} catch (Throwable e) {
|
|
||||||
msg(C.GRAY + string);
|
|
||||||
Iris.reportError(e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void success(String string) {
|
public static void success(String string) {
|
||||||
|
@ -66,7 +66,7 @@ public class CommandIrisStudioUpdate extends MortarCommand {
|
|||||||
IrisData data = IrisData.get(Iris.service(StudioSVC.class).getWorkspaceFolder(args[0]));
|
IrisData data = IrisData.get(Iris.service(StudioSVC.class).getWorkspaceFolder(args[0]));
|
||||||
int t = data.getObjectLoader().getPossibleKeys().length;
|
int t = data.getObjectLoader().getPossibleKeys().length;
|
||||||
ChronoLatch cl = new ChronoLatch(250, false);
|
ChronoLatch cl = new ChronoLatch(250, false);
|
||||||
MultiBurst bx = new MultiBurst("Object Rewriter", Thread.MIN_PRIORITY, Runtime.getRuntime().availableProcessors());
|
MultiBurst bx = MultiBurst.burst;
|
||||||
BurstExecutor b = bx.burst();
|
BurstExecutor b = bx.burst();
|
||||||
int g = 0;
|
int g = 0;
|
||||||
for (String f : data.getObjectLoader().getPossibleKeys()) {
|
for (String f : data.getObjectLoader().getPossibleKeys()) {
|
||||||
@ -102,7 +102,6 @@ public class CommandIrisStudioUpdate extends MortarCommand {
|
|||||||
int finalG = g;
|
int finalG = g;
|
||||||
J.a(() -> {
|
J.a(() -> {
|
||||||
b.complete();
|
b.complete();
|
||||||
bx.shutdownNow();
|
|
||||||
sender.sendMessage("Done! Rewrote " + Form.f(finalG) + " Objects!");
|
sender.sendMessage("Done! Rewrote " + Form.f(finalG) + " Objects!");
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -78,6 +78,7 @@ import java.io.File;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.concurrent.CompletableFuture;
|
import java.util.concurrent.CompletableFuture;
|
||||||
import java.util.concurrent.ExecutionException;
|
import java.util.concurrent.ExecutionException;
|
||||||
|
import java.util.concurrent.Future;
|
||||||
import java.util.function.Supplier;
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
@Decree(name = "studio", aliases = {"std", "s"}, description = "Studio Commands", studio = true)
|
@Decree(name = "studio", aliases = {"std", "s"}, description = "Studio Commands", studio = true)
|
||||||
@ -133,7 +134,7 @@ public class DecStudio implements DecreeExecutor {
|
|||||||
KList<Job> jobs = new KList<>();
|
KList<Job> jobs = new KList<>();
|
||||||
KList<File> files = new KList<File>();
|
KList<File> files = new KList<File>();
|
||||||
files(Iris.instance.getDataFolder("packs", project.getLoadKey()), files);
|
files(Iris.instance.getDataFolder("packs", project.getLoadKey()), files);
|
||||||
MultiBurst burst = new MultiBurst("Cleaner", Thread.MIN_PRIORITY, Runtime.getRuntime().availableProcessors() * 2);
|
MultiBurst burst = MultiBurst.burst;
|
||||||
|
|
||||||
jobs.add(new SingleJob("Updating Workspace", () -> {
|
jobs.add(new SingleJob("Updating Workspace", () -> {
|
||||||
if (!new IrisProject(Iris.service(StudioSVC.class).getWorkspaceFolder(project.getLoadKey())).updateWorkspace()) {
|
if (!new IrisProject(Iris.service(StudioSVC.class).getWorkspaceFolder(project.getLoadKey())).updateWorkspace()) {
|
||||||
@ -208,7 +209,7 @@ public class DecStudio implements DecreeExecutor {
|
|||||||
|
|
||||||
IrisData data = IrisData.get(Iris.service(StudioSVC.class).getWorkspaceFolder(project.getLoadKey()));
|
IrisData data = IrisData.get(Iris.service(StudioSVC.class).getWorkspaceFolder(project.getLoadKey()));
|
||||||
for (String f : data.getObjectLoader().getPossibleKeys()) {
|
for (String f : data.getObjectLoader().getPossibleKeys()) {
|
||||||
CompletableFuture<?> gg = burst.complete(() -> {
|
Future<?> gg = burst.complete(() -> {
|
||||||
File ff = data.getObjectLoader().findFile(f);
|
File ff = data.getObjectLoader().findFile(f);
|
||||||
IrisObject oo = new IrisObject(0, 0, 0);
|
IrisObject oo = new IrisObject(0, 0, 0);
|
||||||
try {
|
try {
|
||||||
@ -237,8 +238,6 @@ public class DecStudio implements DecreeExecutor {
|
|||||||
jobs.add(q);
|
jobs.add(q);
|
||||||
}
|
}
|
||||||
|
|
||||||
jobs.add(new SingleJob("Finishing Up", burst::shutdownNow));
|
|
||||||
|
|
||||||
new JobCollection("Cleaning", jobs).execute(sender());
|
new JobCollection("Cleaning", jobs).execute(sender());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -59,7 +59,7 @@ public class NoiseExplorerGUI extends JPanel implements MouseWheelListener, List
|
|||||||
static double ascale = 10;
|
static double ascale = 10;
|
||||||
CNG cng = NoiseStyle.STATIC.create(new RNG(RNG.r.nextLong()));
|
CNG cng = NoiseStyle.STATIC.create(new RNG(RNG.r.nextLong()));
|
||||||
@SuppressWarnings("CanBeFinal")
|
@SuppressWarnings("CanBeFinal")
|
||||||
MultiBurst gx = new MultiBurst("Iris Noise Renderer", Thread.MAX_PRIORITY, Runtime.getRuntime().availableProcessors());
|
MultiBurst gx = MultiBurst.burst;
|
||||||
ReentrantLock l = new ReentrantLock();
|
ReentrantLock l = new ReentrantLock();
|
||||||
BufferedImage img;
|
BufferedImage img;
|
||||||
int w = 0;
|
int w = 0;
|
||||||
@ -299,7 +299,6 @@ public class NoiseExplorerGUI extends JPanel implements MouseWheelListener, List
|
|||||||
frame.addWindowListener(new java.awt.event.WindowAdapter() {
|
frame.addWindowListener(new java.awt.event.WindowAdapter() {
|
||||||
@Override
|
@Override
|
||||||
public void windowClosing(java.awt.event.WindowEvent windowEvent) {
|
public void windowClosing(java.awt.event.WindowEvent windowEvent) {
|
||||||
nv.gx.shutdownLater();
|
|
||||||
Iris.instance.unregisterListener(nv);
|
Iris.instance.unregisterListener(nv);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -29,11 +29,12 @@ import org.bukkit.Chunk;
|
|||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
|
|
||||||
import java.util.concurrent.CompletableFuture;
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
import java.util.concurrent.Future;
|
||||||
|
|
||||||
public class AsyncPregenMethod implements PregeneratorMethod {
|
public class AsyncPregenMethod implements PregeneratorMethod {
|
||||||
private final World world;
|
private final World world;
|
||||||
private final MultiBurst burst;
|
private final MultiBurst burst;
|
||||||
private final KList<CompletableFuture<?>> future;
|
private final KList<Future<?>> future;
|
||||||
|
|
||||||
public AsyncPregenMethod(World world, int threads) {
|
public AsyncPregenMethod(World world, int threads) {
|
||||||
if (!PaperLib.isPaper()) {
|
if (!PaperLib.isPaper()) {
|
||||||
@ -41,7 +42,7 @@ public class AsyncPregenMethod implements PregeneratorMethod {
|
|||||||
}
|
}
|
||||||
|
|
||||||
this.world = world;
|
this.world = world;
|
||||||
burst = new MultiBurst("Iris Async Pregenerator", IrisSettings.get().getConcurrency().getPregenThreadPriority(), threads);
|
burst = MultiBurst.burst;
|
||||||
future = new KList<>(1024);
|
future = new KList<>(1024);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -69,7 +70,7 @@ public class AsyncPregenMethod implements PregeneratorMethod {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void waitForChunks() {
|
private void waitForChunks() {
|
||||||
for (CompletableFuture<?> i : future.copy()) {
|
for (Future<?> i : future.copy()) {
|
||||||
try {
|
try {
|
||||||
i.get();
|
i.get();
|
||||||
future.remove(i);
|
future.remove(i);
|
||||||
@ -92,7 +93,6 @@ public class AsyncPregenMethod implements PregeneratorMethod {
|
|||||||
@Override
|
@Override
|
||||||
public void close() {
|
public void close() {
|
||||||
waitForChunks();
|
waitForChunks();
|
||||||
burst.shutdownAndAwait();
|
|
||||||
unloadAndSaveAllChunks();
|
unloadAndSaveAllChunks();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -31,7 +31,6 @@ import java.util.concurrent.ExecutorService;
|
|||||||
public class PreservationSVC implements IrisService
|
public class PreservationSVC implements IrisService
|
||||||
{
|
{
|
||||||
private KList<Thread> threads = new KList<>();
|
private KList<Thread> threads = new KList<>();
|
||||||
private KList<MultiBurst> bursts = new KList<>();
|
|
||||||
private KList<ExecutorService> services = new KList<>();
|
private KList<ExecutorService> services = new KList<>();
|
||||||
private Looper dereferencer;
|
private Looper dereferencer;
|
||||||
|
|
||||||
@ -42,7 +41,7 @@ public class PreservationSVC implements IrisService
|
|||||||
|
|
||||||
public void register(MultiBurst burst)
|
public void register(MultiBurst burst)
|
||||||
{
|
{
|
||||||
bursts.add(burst);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void register(ExecutorService service)
|
public void register(ExecutorService service)
|
||||||
@ -94,20 +93,6 @@ public class PreservationSVC implements IrisService
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for(MultiBurst i : bursts)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
i.shutdownNow();
|
|
||||||
Iris.info("Shutdown Multiburst " + i);
|
|
||||||
}
|
|
||||||
|
|
||||||
catch(Throwable e)
|
|
||||||
{
|
|
||||||
Iris.reportError(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for(ExecutorService i : services)
|
for(ExecutorService i : services)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
|
@ -132,6 +132,7 @@ public class IrisEngine extends BlockPopulator implements Engine {
|
|||||||
closed = false;
|
closed = false;
|
||||||
art = J.ar(this::tickRandomPlayer, 0);
|
art = J.ar(this::tickRandomPlayer, 0);
|
||||||
setupEngine();
|
setupEngine();
|
||||||
|
Iris.debug("Engine Initialized " + getCacheID());
|
||||||
}
|
}
|
||||||
|
|
||||||
private void tickRandomPlayer() {
|
private void tickRandomPlayer() {
|
||||||
@ -158,20 +159,32 @@ public class IrisEngine extends BlockPopulator implements Engine {
|
|||||||
|
|
||||||
private void setupEngine()
|
private void setupEngine()
|
||||||
{
|
{
|
||||||
cacheId = RNG.r.nextInt();
|
try
|
||||||
worldManager = new IrisWorldManager(this);
|
{
|
||||||
complex = new IrisComplex(this);
|
Iris.debug("Setup Engine " + getCacheID());
|
||||||
execution = new IrisExecutionEnvironment(this);
|
cacheId = RNG.r.nextInt();
|
||||||
terrainNormalActuator = new IrisTerrainNormalActuator(this);
|
worldManager = new IrisWorldManager(this);
|
||||||
terrainIslandActuator = new IrisTerrainIslandActuator(this);
|
complex = new IrisComplex(this);
|
||||||
decorantActuator = new IrisDecorantActuator(this);
|
execution = new IrisExecutionEnvironment(this);
|
||||||
biomeActuator = new IrisBiomeActuator(this);
|
terrainNormalActuator = new IrisTerrainNormalActuator(this);
|
||||||
depositModifier = new IrisDepositModifier(this);
|
terrainIslandActuator = new IrisTerrainIslandActuator(this);
|
||||||
ravineModifier = new IrisRavineModifier(this);
|
decorantActuator = new IrisDecorantActuator(this);
|
||||||
caveModifier = new IrisCaveModifier(this);
|
biomeActuator = new IrisBiomeActuator(this);
|
||||||
postModifier = new IrisPostModifier(this);
|
depositModifier = new IrisDepositModifier(this);
|
||||||
effects = new IrisEngineEffects(this);
|
ravineModifier = new IrisRavineModifier(this);
|
||||||
J.a(this::computeBiomeMaxes);
|
caveModifier = new IrisCaveModifier(this);
|
||||||
|
postModifier = new IrisPostModifier(this);
|
||||||
|
effects = new IrisEngineEffects(this);
|
||||||
|
J.a(this::computeBiomeMaxes);
|
||||||
|
}
|
||||||
|
|
||||||
|
catch(Throwable e)
|
||||||
|
{
|
||||||
|
Iris.error("FAILED TO SETUP ENGINE!");
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
Iris.debug("Engine Setup Complete " + getCacheID());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -18,6 +18,7 @@
|
|||||||
|
|
||||||
package com.volmit.iris.engine;
|
package com.volmit.iris.engine;
|
||||||
|
|
||||||
|
import com.googlecode.concurrentlinkedhashmap.ConcurrentLinkedHashMap;
|
||||||
import com.volmit.iris.Iris;
|
import com.volmit.iris.Iris;
|
||||||
import com.volmit.iris.engine.framework.Engine;
|
import com.volmit.iris.engine.framework.Engine;
|
||||||
import com.volmit.iris.engine.mantle.EngineMantle;
|
import com.volmit.iris.engine.mantle.EngineMantle;
|
||||||
@ -27,6 +28,7 @@ import com.volmit.iris.engine.mantle.components.MantleJigsawComponent;
|
|||||||
import com.volmit.iris.engine.mantle.components.MantleObjectComponent;
|
import com.volmit.iris.engine.mantle.components.MantleObjectComponent;
|
||||||
import com.volmit.iris.engine.object.biome.IrisBiome;
|
import com.volmit.iris.engine.object.biome.IrisBiome;
|
||||||
import com.volmit.iris.engine.object.deposits.IrisDepositGenerator;
|
import com.volmit.iris.engine.object.deposits.IrisDepositGenerator;
|
||||||
|
import com.volmit.iris.engine.object.feature.IrisFeaturePositional;
|
||||||
import com.volmit.iris.engine.object.feature.IrisFeaturePotential;
|
import com.volmit.iris.engine.object.feature.IrisFeaturePotential;
|
||||||
import com.volmit.iris.engine.object.jigsaw.IrisJigsawStructurePlacement;
|
import com.volmit.iris.engine.object.jigsaw.IrisJigsawStructurePlacement;
|
||||||
import com.volmit.iris.engine.object.objects.IrisObject;
|
import com.volmit.iris.engine.object.objects.IrisObject;
|
||||||
@ -36,9 +38,15 @@ import com.volmit.iris.engine.object.regional.IrisRegion;
|
|||||||
import com.volmit.iris.util.collection.KList;
|
import com.volmit.iris.util.collection.KList;
|
||||||
import com.volmit.iris.util.collection.KMap;
|
import com.volmit.iris.util.collection.KMap;
|
||||||
import com.volmit.iris.util.collection.KSet;
|
import com.volmit.iris.util.collection.KSet;
|
||||||
|
import com.volmit.iris.util.documentation.BlockCoordinates;
|
||||||
|
import com.volmit.iris.util.documentation.ChunkCoordinates;
|
||||||
import com.volmit.iris.util.format.Form;
|
import com.volmit.iris.util.format.Form;
|
||||||
import com.volmit.iris.util.mantle.Mantle;
|
import com.volmit.iris.util.mantle.Mantle;
|
||||||
|
import com.volmit.iris.util.mantle.MantleFlag;
|
||||||
import com.volmit.iris.util.parallel.BurstExecutor;
|
import com.volmit.iris.util.parallel.BurstExecutor;
|
||||||
|
import com.volmit.iris.util.stream.ProceduralStream;
|
||||||
|
import com.volmit.iris.util.stream.interpolation.Interpolated;
|
||||||
|
import com.volmit.iris.util.stream.utility.CachedStream2D;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import org.bukkit.util.BlockVector;
|
import org.bukkit.util.BlockVector;
|
||||||
|
|
||||||
@ -46,6 +54,7 @@ import java.io.File;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.concurrent.CompletableFuture;
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
import java.util.concurrent.Future;
|
||||||
import java.util.concurrent.atomic.AtomicInteger;
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
@ -53,7 +62,9 @@ public class IrisEngineMantle implements EngineMantle {
|
|||||||
private final Engine engine;
|
private final Engine engine;
|
||||||
private final Mantle mantle;
|
private final Mantle mantle;
|
||||||
private final KList<MantleComponent> components;
|
private final KList<MantleComponent> components;
|
||||||
private final CompletableFuture<Integer> radius;
|
private final Future<Integer> radius;
|
||||||
|
private ProceduralStream<KList<IrisFeaturePositional>> featureChunkStream;
|
||||||
|
private ProceduralStream<KList<IrisFeaturePositional>> featureStream;
|
||||||
|
|
||||||
public IrisEngineMantle(Engine engine) {
|
public IrisEngineMantle(Engine engine) {
|
||||||
this.engine = engine;
|
this.engine = engine;
|
||||||
@ -63,6 +74,21 @@ public class IrisEngineMantle implements EngineMantle {
|
|||||||
registerComponent(new MantleFeatureComponent(this));
|
registerComponent(new MantleFeatureComponent(this));
|
||||||
registerComponent(new MantleJigsawComponent(this));
|
registerComponent(new MantleJigsawComponent(this));
|
||||||
registerComponent(new MantleObjectComponent(this));
|
registerComponent(new MantleObjectComponent(this));
|
||||||
|
featureChunkStream = ProceduralStream.of((x, z)
|
||||||
|
-> EngineMantle.super.getFeaturesInChunk(x.intValue(), z.intValue()),
|
||||||
|
Interpolated.of((i) -> 0D, (i) -> new KList<IrisFeaturePositional>())).cache2D(2048);
|
||||||
|
featureStream = ProceduralStream.of(EngineMantle.super::forEachFeature,
|
||||||
|
Interpolated.of((i) -> 0D, (i) -> new KList<IrisFeaturePositional>())).cache2D(8192);
|
||||||
|
}
|
||||||
|
|
||||||
|
@ChunkCoordinates
|
||||||
|
public KList<IrisFeaturePositional> getFeaturesInChunk(int x, int z) {
|
||||||
|
return featureChunkStream.get(x, z);
|
||||||
|
}
|
||||||
|
|
||||||
|
@BlockCoordinates
|
||||||
|
public KList<IrisFeaturePositional> forEachFeature(double x, double z) {
|
||||||
|
return featureStream.get(x, z);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -69,7 +69,6 @@ public class IrisBiomeActuator extends EngineAssignedActuator<Biome> {
|
|||||||
public void onActuate(int x, int z, Hunk<Biome> h, boolean multicore) {
|
public void onActuate(int x, int z, Hunk<Biome> h, boolean multicore) {
|
||||||
PrecisionStopwatch p = PrecisionStopwatch.start();
|
PrecisionStopwatch p = PrecisionStopwatch.start();
|
||||||
BurstExecutor burst = burst().burst();
|
BurstExecutor burst = burst().burst();
|
||||||
burst.setMulticore(multicore);
|
|
||||||
|
|
||||||
for (int xf = 0; xf < h.getWidth(); xf++) {
|
for (int xf = 0; xf < h.getWidth(); xf++) {
|
||||||
int finalXf = xf;
|
int finalXf = xf;
|
||||||
|
@ -91,7 +91,6 @@ public class IrisDecorantActuator extends EngineAssignedActuator<BlockData> {
|
|||||||
|
|
||||||
PrecisionStopwatch p = PrecisionStopwatch.start();
|
PrecisionStopwatch p = PrecisionStopwatch.start();
|
||||||
BurstExecutor burst = burst().burst();
|
BurstExecutor burst = burst().burst();
|
||||||
burst.setMulticore(multicore);
|
|
||||||
|
|
||||||
for (int i = 0; i < output.getWidth(); i++) {
|
for (int i = 0; i < output.getWidth(); i++) {
|
||||||
int finalI = i;
|
int finalI = i;
|
||||||
|
@ -56,7 +56,6 @@ public class IrisTerrainNormalActuator extends EngineAssignedActuator<BlockData>
|
|||||||
PrecisionStopwatch p = PrecisionStopwatch.start();
|
PrecisionStopwatch p = PrecisionStopwatch.start();
|
||||||
|
|
||||||
BurstExecutor e = getEngine().burst().burst(h.getWidth());
|
BurstExecutor e = getEngine().burst().burst(h.getWidth());
|
||||||
e.setMulticore(multicore);
|
|
||||||
for (int xf = 0; xf < h.getWidth(); xf++) {
|
for (int xf = 0; xf < h.getWidth(); xf++) {
|
||||||
int finalXf = xf;
|
int finalXf = xf;
|
||||||
e.queue(() -> terrainSliver(x, z, finalXf, h));
|
e.queue(() -> terrainSliver(x, z, finalXf, h));
|
||||||
|
@ -18,6 +18,7 @@
|
|||||||
|
|
||||||
package com.volmit.iris.engine.framework;
|
package com.volmit.iris.engine.framework;
|
||||||
|
|
||||||
|
import com.volmit.iris.Iris;
|
||||||
import com.volmit.iris.util.documentation.BlockCoordinates;
|
import com.volmit.iris.util.documentation.BlockCoordinates;
|
||||||
import com.volmit.iris.util.hunk.Hunk;
|
import com.volmit.iris.util.hunk.Hunk;
|
||||||
|
|
||||||
@ -31,6 +32,7 @@ public abstract class EngineAssignedActuator<T> extends EngineAssignedComponent
|
|||||||
@BlockCoordinates
|
@BlockCoordinates
|
||||||
@Override
|
@Override
|
||||||
public void actuate(int x, int z, Hunk<T> output, boolean multicore) {
|
public void actuate(int x, int z, Hunk<T> output, boolean multicore) {
|
||||||
|
Iris.debug("Engine Actuator[" + getName() + "] " + x + " " + z);
|
||||||
onActuate(x, z, output, multicore);
|
onActuate(x, z, output, multicore);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -18,6 +18,7 @@
|
|||||||
|
|
||||||
package com.volmit.iris.engine.framework;
|
package com.volmit.iris.engine.framework;
|
||||||
|
|
||||||
|
import com.volmit.iris.Iris;
|
||||||
import com.volmit.iris.util.math.RollingSequence;
|
import com.volmit.iris.util.math.RollingSequence;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
@ -28,6 +29,7 @@ public class EngineAssignedComponent implements EngineComponent {
|
|||||||
private final String name;
|
private final String name;
|
||||||
|
|
||||||
public EngineAssignedComponent(Engine engine, String name) {
|
public EngineAssignedComponent(Engine engine, String name) {
|
||||||
|
Iris.debug("Engine: " + engine.getCacheID() + " Starting " + name);
|
||||||
this.engine = engine;
|
this.engine = engine;
|
||||||
this.metrics = new RollingSequence(16);
|
this.metrics = new RollingSequence(16);
|
||||||
this.name = name;
|
this.name = name;
|
||||||
|
@ -18,6 +18,7 @@
|
|||||||
|
|
||||||
package com.volmit.iris.engine.framework;
|
package com.volmit.iris.engine.framework;
|
||||||
|
|
||||||
|
import com.volmit.iris.Iris;
|
||||||
import com.volmit.iris.util.documentation.BlockCoordinates;
|
import com.volmit.iris.util.documentation.BlockCoordinates;
|
||||||
import com.volmit.iris.util.hunk.Hunk;
|
import com.volmit.iris.util.hunk.Hunk;
|
||||||
|
|
||||||
@ -32,6 +33,7 @@ public abstract class EngineAssignedModifier<T> extends EngineAssignedComponent
|
|||||||
@BlockCoordinates
|
@BlockCoordinates
|
||||||
@Override
|
@Override
|
||||||
public void modify(int x, int z, Hunk<T> output, boolean multicore) {
|
public void modify(int x, int z, Hunk<T> output, boolean multicore) {
|
||||||
|
Iris.debug("Engine Modifier[" + getName() + "] " + x + " " + z);
|
||||||
onModify(x, z, output, multicore);
|
onModify(x, z, output, multicore);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -36,9 +36,7 @@ public class EngineTarget {
|
|||||||
this.world = world;
|
this.world = world;
|
||||||
this.dimension = dimension;
|
this.dimension = dimension;
|
||||||
this.data = data;
|
this.data = data;
|
||||||
this.burster = new MultiBurst("Iris Engine " + dimension.getName(),
|
this.burster = MultiBurst.burst;
|
||||||
IrisSettings.get().getConcurrency().getEngineThreadPriority(),
|
|
||||||
IrisSettings.getThreadCount(IrisSettings.get().getConcurrency().getEngineThreadCount()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getHeight() {
|
public int getHeight() {
|
||||||
@ -46,6 +44,6 @@ public class EngineTarget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void close() {
|
public void close() {
|
||||||
burster.shutdownLater();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -36,16 +36,11 @@ import com.volmit.iris.util.mantle.Mantle;
|
|||||||
import com.volmit.iris.util.mantle.MantleFlag;
|
import com.volmit.iris.util.mantle.MantleFlag;
|
||||||
import com.volmit.iris.util.parallel.BurstExecutor;
|
import com.volmit.iris.util.parallel.BurstExecutor;
|
||||||
import com.volmit.iris.util.parallel.MultiBurst;
|
import com.volmit.iris.util.parallel.MultiBurst;
|
||||||
import com.volmit.iris.util.scheduling.PrecisionStopwatch;
|
|
||||||
import org.bukkit.Chunk;
|
import org.bukkit.Chunk;
|
||||||
import org.bukkit.block.TileState;
|
import org.bukkit.block.TileState;
|
||||||
import org.bukkit.block.data.BlockData;
|
import org.bukkit.block.data.BlockData;
|
||||||
|
|
||||||
import java.util.Collections;
|
import java.util.concurrent.*;
|
||||||
import java.util.List;
|
|
||||||
import java.util.concurrent.CompletableFuture;
|
|
||||||
import java.util.concurrent.CopyOnWriteArrayList;
|
|
||||||
import java.util.concurrent.ExecutionException;
|
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
// TODO: MOVE PLACER OUT OF MATTER INTO ITS OWN THING
|
// TODO: MOVE PLACER OUT OF MATTER INTO ITS OWN THING
|
||||||
@ -56,7 +51,7 @@ public interface EngineMantle extends IObjectPlacer {
|
|||||||
|
|
||||||
Engine getEngine();
|
Engine getEngine();
|
||||||
|
|
||||||
CompletableFuture<Integer> getRadius();
|
Future<Integer> getRadius();
|
||||||
|
|
||||||
KList<MantleComponent> getComponents();
|
KList<MantleComponent> getComponents();
|
||||||
|
|
||||||
@ -189,7 +184,6 @@ public interface EngineMantle extends IObjectPlacer {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
PrecisionStopwatch p = PrecisionStopwatch.start();
|
|
||||||
KList<Runnable> post = new KList<>();
|
KList<Runnable> post = new KList<>();
|
||||||
Consumer<Runnable> c = (i) -> {
|
Consumer<Runnable> c = (i) -> {
|
||||||
synchronized (post)
|
synchronized (post)
|
||||||
@ -199,7 +193,6 @@ public interface EngineMantle extends IObjectPlacer {
|
|||||||
};
|
};
|
||||||
int s = getRealRadius();
|
int s = getRealRadius();
|
||||||
BurstExecutor burst = burst().burst();
|
BurstExecutor burst = burst().burst();
|
||||||
burst.setMulticore(multicore);
|
|
||||||
|
|
||||||
for (int i = -s; i <= s; i++) {
|
for (int i = -s; i <= s; i++) {
|
||||||
int xx = i + x;
|
int xx = i + x;
|
||||||
@ -217,16 +210,7 @@ public interface EngineMantle extends IObjectPlacer {
|
|||||||
{
|
{
|
||||||
KList<Runnable> px = post.copy();
|
KList<Runnable> px = post.copy();
|
||||||
post.clear();
|
post.clear();
|
||||||
|
burst().burst(px);
|
||||||
if(multicore)
|
|
||||||
{
|
|
||||||
burst().burst(px);
|
|
||||||
}
|
|
||||||
|
|
||||||
else
|
|
||||||
{
|
|
||||||
burst().sync(px);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -240,6 +224,7 @@ public interface EngineMantle extends IObjectPlacer {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Iris.debug("Engine Matter Insert " + x + " " + z);
|
||||||
getMantle().iterateChunk(x, z, t, blocks::set);
|
getMantle().iterateChunk(x, z, t, blocks::set);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -55,7 +55,7 @@ public class IrisDepositModifier extends EngineAssignedModifier<BlockData> {
|
|||||||
IrisRegion region = getComplex().getRegionStream().get((x * 16) + 7, (z * 16) + 7);
|
IrisRegion region = getComplex().getRegionStream().get((x * 16) + 7, (z * 16) + 7);
|
||||||
IrisBiome biome = getComplex().getTrueBiomeStream().get((x * 16) + 7, (z * 16) + 7);
|
IrisBiome biome = getComplex().getTrueBiomeStream().get((x * 16) + 7, (z * 16) + 7);
|
||||||
BurstExecutor burst = burst().burst();
|
BurstExecutor burst = burst().burst();
|
||||||
burst.setMulticore(multicore);
|
|
||||||
for (IrisDepositGenerator k : getDimension().getDeposits()) {
|
for (IrisDepositGenerator k : getDimension().getDeposits()) {
|
||||||
burst.queue(() -> generate(k, terrain, ro, x, z, false));
|
burst.queue(() -> generate(k, terrain, ro, x, z, false));
|
||||||
}
|
}
|
||||||
|
@ -65,7 +65,6 @@ public class IrisPostModifier extends EngineAssignedModifier<BlockData> {
|
|||||||
AtomicInteger i = new AtomicInteger();
|
AtomicInteger i = new AtomicInteger();
|
||||||
AtomicInteger j = new AtomicInteger();
|
AtomicInteger j = new AtomicInteger();
|
||||||
BurstExecutor burst = burst().burst();
|
BurstExecutor burst = burst().burst();
|
||||||
burst.setMulticore(multicore);
|
|
||||||
Hunk<BlockData> sync = output.synchronize();
|
Hunk<BlockData> sync = output.synchronize();
|
||||||
for (i.set(0); i.get() < output.getWidth(); i.getAndIncrement()) {
|
for (i.set(0); i.get() < output.getWidth(); i.getAndIncrement()) {
|
||||||
burst.queue(() -> {
|
burst.queue(() -> {
|
||||||
|
@ -177,6 +177,7 @@ public class BukkitChunkGenerator extends ChunkGenerator implements PlatformChun
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @NotNull ChunkData generateChunkData(@NotNull World world, @NotNull Random ignored, int x, int z, @NotNull BiomeGrid biome) {
|
public @NotNull ChunkData generateChunkData(@NotNull World world, @NotNull Random ignored, int x, int z, @NotNull BiomeGrid biome) {
|
||||||
|
Iris.debug("Generate Request " + world.getName() + " at: " + x + ", " + z);
|
||||||
try {
|
try {
|
||||||
if(lastSeed != world.getSeed())
|
if(lastSeed != world.getSeed())
|
||||||
{
|
{
|
||||||
@ -187,12 +188,14 @@ public class BukkitChunkGenerator extends ChunkGenerator implements PlatformChun
|
|||||||
Iris.success("Updated Engine seed to " + lastSeed);
|
Iris.success("Updated Engine seed to " + lastSeed);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Iris.debug("Generate Request [LOCKING] at: " + x + ", " + z);
|
||||||
loadLock.acquire();
|
loadLock.acquire();
|
||||||
PrecisionStopwatch ps = PrecisionStopwatch.start();
|
Iris.debug("Generate Request [LOCKED] at: " + x + ", " + z);
|
||||||
TerrainChunk tc = TerrainChunk.create(world, biome);
|
TerrainChunk tc = TerrainChunk.create(world, biome);
|
||||||
Hunk<BlockData> blocks = Hunk.view((ChunkData) tc);
|
Hunk<BlockData> blocks = Hunk.view((ChunkData) tc);
|
||||||
Hunk<Biome> biomes = Hunk.view((BiomeGrid) tc);
|
Hunk<Biome> biomes = Hunk.view((BiomeGrid) tc);
|
||||||
this.world.bind(world);
|
this.world.bind(world);
|
||||||
|
Iris.debug("Generate Request [ENGINE] at: " + x + ", " + z);
|
||||||
getEngine().generate(x * 16, z * 16, blocks, biomes, true);
|
getEngine().generate(x * 16, z * 16, blocks, biomes, true);
|
||||||
ChunkData c = tc.getRaw();
|
ChunkData c = tc.getRaw();
|
||||||
Iris.debug("Generated " + x + " " + z);
|
Iris.debug("Generated " + x + " " + z);
|
||||||
|
@ -58,7 +58,7 @@ public class HeadlessGenerator implements PlatformChunkGenerator {
|
|||||||
|
|
||||||
public HeadlessGenerator(HeadlessWorld world) {
|
public HeadlessGenerator(HeadlessWorld world) {
|
||||||
this.world = world;
|
this.world = world;
|
||||||
burst = new MultiBurst("Iris Headless Generator", 9, IrisSettings.getThreadCount(IrisSettings.get().getConcurrency().getPregenThreadCount()));
|
burst = MultiBurst.burst;
|
||||||
writer = new NBTWorld(world.getWorld().worldFolder());
|
writer = new NBTWorld(world.getWorld().worldFolder());
|
||||||
engine = new IrisEngine(new EngineTarget(world.getWorld(), world.getDimension(), world.getDimension().getLoader()), isStudio());
|
engine = new IrisEngine(new EngineTarget(world.getWorld(), world.getDimension(), world.getDimension().getLoader()), isStudio());
|
||||||
}
|
}
|
||||||
@ -131,7 +131,6 @@ public class HeadlessGenerator implements PlatformChunkGenerator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void close() {
|
public void close() {
|
||||||
burst.shutdownAndAwait();
|
|
||||||
getEngine().close();
|
getEngine().close();
|
||||||
writer.close();
|
writer.close();
|
||||||
}
|
}
|
||||||
|
@ -46,6 +46,7 @@ import java.nio.charset.StandardCharsets;
|
|||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.concurrent.CompletableFuture;
|
import java.util.concurrent.CompletableFuture;
|
||||||
import java.util.concurrent.ExecutionException;
|
import java.util.concurrent.ExecutionException;
|
||||||
|
import java.util.concurrent.Future;
|
||||||
import java.util.concurrent.atomic.AtomicBoolean;
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -386,7 +387,7 @@ public class Mantle {
|
|||||||
* @return the future of a tectonic plate.
|
* @return the future of a tectonic plate.
|
||||||
*/
|
*/
|
||||||
@RegionCoordinates
|
@RegionCoordinates
|
||||||
private CompletableFuture<TectonicPlate> getSafe(int x, int z) {
|
private Future<TectonicPlate> getSafe(int x, int z) {
|
||||||
Long k = key(x, z);
|
Long k = key(x, z);
|
||||||
TectonicPlate p = loadedRegions.get(k);
|
TectonicPlate p = loadedRegions.get(k);
|
||||||
|
|
||||||
@ -449,7 +450,10 @@ public class Mantle {
|
|||||||
public static File fileForRegion(File folder, Long key) {
|
public static File fileForRegion(File folder, Long key) {
|
||||||
String id = UUID.nameUUIDFromBytes(("TectonicPlate:" + key).getBytes(StandardCharsets.UTF_8)).toString();
|
String id = UUID.nameUUIDFromBytes(("TectonicPlate:" + key).getBytes(StandardCharsets.UTF_8)).toString();
|
||||||
File f = new File(folder, id.substring(0, 2) + "/" + id.split("\\Q-\\E")[3] + "/" + id + ".ttp");
|
File f = new File(folder, id.substring(0, 2) + "/" + id.split("\\Q-\\E")[3] + "/" + id + ".ttp");
|
||||||
f.getParentFile().mkdirs();
|
if(!f.getParentFile().exists())
|
||||||
|
{
|
||||||
|
f.getParentFile().mkdirs();
|
||||||
|
}
|
||||||
return f;
|
return f;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -28,45 +28,27 @@ import java.util.concurrent.*;
|
|||||||
@SuppressWarnings("ALL")
|
@SuppressWarnings("ALL")
|
||||||
public class BurstExecutor {
|
public class BurstExecutor {
|
||||||
private final ExecutorService executor;
|
private final ExecutorService executor;
|
||||||
private final KList<CompletableFuture<Void>> futures;
|
private final KList<Future<?>> futures;
|
||||||
@Setter
|
|
||||||
private boolean multicore = true;
|
|
||||||
|
|
||||||
public BurstExecutor(ExecutorService executor, int burstSizeEstimate) {
|
public BurstExecutor(ExecutorService executor, int burstSizeEstimate) {
|
||||||
this.executor = executor;
|
this.executor = executor;
|
||||||
futures = new KList<CompletableFuture<Void>>(burstSizeEstimate);
|
futures = new KList<Future<?>>(burstSizeEstimate);
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("UnusedReturnValue")
|
@SuppressWarnings("UnusedReturnValue")
|
||||||
public CompletableFuture<Void> queue(Runnable r) {
|
public Future<?> queue(Runnable r) {
|
||||||
if(!multicore)
|
|
||||||
{
|
|
||||||
r.run();
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
synchronized (futures) {
|
synchronized (futures) {
|
||||||
CompletableFuture<Void> c = CompletableFuture.runAsync(r, executor);
|
|
||||||
|
Future<?> c = executor.submit(r);
|
||||||
futures.add(c);
|
futures.add(c);
|
||||||
return c;
|
return c;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public BurstExecutor queue(List<Runnable> r) {
|
public BurstExecutor queue(List<Runnable> r) {
|
||||||
if(!multicore)
|
|
||||||
{
|
|
||||||
for(Runnable i : r)
|
|
||||||
{
|
|
||||||
i.run();
|
|
||||||
}
|
|
||||||
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
synchronized (futures) {
|
synchronized (futures) {
|
||||||
for (Runnable i : new KList<>(r)) {
|
for (Runnable i : new KList<>(r)) {
|
||||||
CompletableFuture<Void> c = CompletableFuture.runAsync(i, executor);
|
queue(i);
|
||||||
futures.add(c);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -74,20 +56,9 @@ public class BurstExecutor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public BurstExecutor queue(Runnable[] r) {
|
public BurstExecutor queue(Runnable[] r) {
|
||||||
if(!multicore)
|
|
||||||
{
|
|
||||||
for(Runnable i : r)
|
|
||||||
{
|
|
||||||
i.run();
|
|
||||||
}
|
|
||||||
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
synchronized (futures) {
|
synchronized (futures) {
|
||||||
for (Runnable i : r) {
|
for (Runnable i : r) {
|
||||||
CompletableFuture<Void> c = CompletableFuture.runAsync(i, executor);
|
queue(i);
|
||||||
futures.add(c);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -95,18 +66,17 @@ public class BurstExecutor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void complete() {
|
public void complete() {
|
||||||
if(!multicore)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
synchronized (futures) {
|
synchronized (futures) {
|
||||||
if (futures.isEmpty()) {
|
if (futures.isEmpty()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
CompletableFuture.allOf(futures.toArray(new CompletableFuture[0])).get();
|
for(Future<?> i : futures)
|
||||||
|
{
|
||||||
|
i.get();
|
||||||
|
}
|
||||||
|
|
||||||
futures.clear();
|
futures.clear();
|
||||||
} catch (InterruptedException | ExecutionException e) {
|
} catch (InterruptedException | ExecutionException e) {
|
||||||
Iris.reportError(e);
|
Iris.reportError(e);
|
||||||
@ -115,11 +85,6 @@ public class BurstExecutor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public boolean complete(long maxDur) {
|
public boolean complete(long maxDur) {
|
||||||
if(!multicore)
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
synchronized (futures) {
|
synchronized (futures) {
|
||||||
if (futures.isEmpty()) {
|
if (futures.isEmpty()) {
|
||||||
return true;
|
return true;
|
||||||
|
@ -19,13 +19,10 @@
|
|||||||
package com.volmit.iris.util.parallel;
|
package com.volmit.iris.util.parallel;
|
||||||
|
|
||||||
import com.volmit.iris.Iris;
|
import com.volmit.iris.Iris;
|
||||||
import com.volmit.iris.core.IrisSettings;
|
|
||||||
import com.volmit.iris.core.service.PreservationSVC;
|
import com.volmit.iris.core.service.PreservationSVC;
|
||||||
import com.volmit.iris.util.collection.KList;
|
import com.volmit.iris.util.collection.KList;
|
||||||
import com.volmit.iris.util.io.InstanceState;
|
|
||||||
import com.volmit.iris.util.math.M;
|
import com.volmit.iris.util.math.M;
|
||||||
import com.volmit.iris.util.scheduling.J;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import com.volmit.iris.util.scheduling.Looper;
|
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.concurrent.*;
|
import java.util.concurrent.*;
|
||||||
@ -33,66 +30,39 @@ import java.util.concurrent.atomic.AtomicLong;
|
|||||||
import java.util.function.Supplier;
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
public class MultiBurst {
|
public class MultiBurst {
|
||||||
public static final MultiBurst burst = new MultiBurst("Iris", IrisSettings.get().getConcurrency().getMiscThreadPriority(), IrisSettings.getThreadCount(IrisSettings.get().getConcurrency().getMiscThreadCount()));
|
public static final MultiBurst burst = new MultiBurst();
|
||||||
private ExecutorService service;
|
private ExecutorService service;
|
||||||
private final Looper heartbeat;
|
|
||||||
private final AtomicLong last;
|
private final AtomicLong last;
|
||||||
private int tid;
|
|
||||||
private final String name;
|
private final String name;
|
||||||
private final int tc;
|
|
||||||
private final int priority;
|
private final int priority;
|
||||||
private final int instance;
|
|
||||||
|
|
||||||
public MultiBurst(int tc) {
|
public MultiBurst() {
|
||||||
this("Iris", 6, tc);
|
this("Iris", Thread.MIN_PRIORITY);
|
||||||
}
|
}
|
||||||
|
|
||||||
public MultiBurst(String name, int priority, int tc) {
|
public MultiBurst(String name, int priority) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.priority = priority;
|
this.priority = priority;
|
||||||
this.tc = tc;
|
|
||||||
instance = InstanceState.getInstanceId();
|
|
||||||
last = new AtomicLong(M.ms());
|
last = new AtomicLong(M.ms());
|
||||||
heartbeat = new Looper() {
|
|
||||||
@Override
|
|
||||||
protected long loop() {
|
|
||||||
if (instance != InstanceState.getInstanceId()) {
|
|
||||||
shutdownNow();
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (M.ms() - last.get() > TimeUnit.MINUTES.toMillis(1) && service != null) {
|
|
||||||
service.shutdown();
|
|
||||||
service = null;
|
|
||||||
Iris.debug("Shutting down MultiBurst Pool " + getName() + " to conserve resources.");
|
|
||||||
}
|
|
||||||
|
|
||||||
return 30000;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
heartbeat.setName(name + " Monitor");
|
|
||||||
heartbeat.start();
|
|
||||||
Iris.service(PreservationSVC.class).register(this);
|
Iris.service(PreservationSVC.class).register(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
private synchronized ExecutorService getService() {
|
private synchronized ExecutorService getService() {
|
||||||
last.set(M.ms());
|
last.set(M.ms());
|
||||||
if (service == null || service.isShutdown()) {
|
if (service == null || service.isShutdown()) {
|
||||||
service = Executors.newFixedThreadPool(Math.max(tc, 1), r -> {
|
service = new ForkJoinPool(Runtime.getRuntime().availableProcessors(),
|
||||||
tid++;
|
new ForkJoinPool.ForkJoinWorkerThreadFactory() {
|
||||||
Thread t = new Thread(r);
|
int m = 0;
|
||||||
t.setName(name + " " + tid);
|
|
||||||
t.setPriority(priority);
|
|
||||||
t.setUncaughtExceptionHandler((et, e) ->
|
|
||||||
{
|
|
||||||
Iris.info("Exception encountered in " + et.getName());
|
|
||||||
e.printStackTrace();
|
|
||||||
});
|
|
||||||
|
|
||||||
return t;
|
@Override
|
||||||
});
|
public ForkJoinWorkerThread newThread(ForkJoinPool pool) {
|
||||||
Iris.service(PreservationSVC.class).register(service);
|
final ForkJoinWorkerThread worker = ForkJoinPool.defaultForkJoinWorkerThreadFactory.newThread(pool);
|
||||||
Iris.debug("Started MultiBurst Pool " + name + " with " + tc + " threads at " + priority + " priority.");
|
worker.setPriority(priority);
|
||||||
|
worker.setName(name + " " + ++m);
|
||||||
|
return worker;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
(t, e) -> e.printStackTrace(), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
return service;
|
return service;
|
||||||
@ -138,64 +108,15 @@ public class MultiBurst {
|
|||||||
return getService().submit(o);
|
return getService().submit(o);
|
||||||
}
|
}
|
||||||
|
|
||||||
public CompletableFuture<?> complete(Runnable o) {
|
public Future<?> complete(Runnable o) {
|
||||||
return CompletableFuture.runAsync(o, getService());
|
return getService().submit(o);
|
||||||
}
|
}
|
||||||
|
|
||||||
public <T> CompletableFuture<T> completeValue(Supplier<T> o) {
|
public <T> Future<T> completeValue(Callable<T> o) {
|
||||||
return CompletableFuture.supplyAsync(o, getService());
|
return getService().submit(o);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void shutdownNow() {
|
public void close() {
|
||||||
Iris.debug("Shutting down MultiBurst Pool " + heartbeat.getName() + ".");
|
|
||||||
heartbeat.interrupt();
|
|
||||||
|
|
||||||
if (service != null) {
|
|
||||||
service.shutdownNow().forEach(Runnable::run);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void shutdown() {
|
|
||||||
Iris.debug("Shutting down MultiBurst Pool " + heartbeat.getName() + ".");
|
|
||||||
heartbeat.interrupt();
|
|
||||||
|
|
||||||
if (service != null) {
|
|
||||||
service.shutdown();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void shutdownLater() {
|
|
||||||
if (service != null) {
|
|
||||||
try
|
|
||||||
{
|
|
||||||
service.submit(() -> {
|
|
||||||
J.sleep(3000);
|
|
||||||
Iris.debug("Shutting down MultiBurst Pool " + heartbeat.getName() + ".");
|
|
||||||
|
|
||||||
if (service != null) {
|
|
||||||
service.shutdown();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
heartbeat.interrupt();
|
|
||||||
}
|
|
||||||
|
|
||||||
catch(Throwable e)
|
|
||||||
{
|
|
||||||
Iris.debug("Shutting down MultiBurst Pool " + heartbeat.getName() + ".");
|
|
||||||
|
|
||||||
if (service != null) {
|
|
||||||
service.shutdown();
|
|
||||||
}
|
|
||||||
|
|
||||||
heartbeat.interrupt();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void shutdownAndAwait() {
|
|
||||||
Iris.debug("Shutting down MultiBurst Pool " + heartbeat.getName() + ".");
|
|
||||||
heartbeat.interrupt();
|
|
||||||
if (service != null) {
|
if (service != null) {
|
||||||
service.shutdown();
|
service.shutdown();
|
||||||
try {
|
try {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user