mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-04-10 17:56:08 +00:00
Cleanup
This commit is contained in:
@@ -1,23 +0,0 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
||||
* Copyright (c) 2021 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.volmit.iris.util.scheduling;
|
||||
|
||||
public interface CallbackCV<T> {
|
||||
void run(T t);
|
||||
}
|
||||
@@ -1,71 +0,0 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
||||
* Copyright (c) 2021 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.volmit.iris.util.scheduling;
|
||||
|
||||
import com.volmit.iris.util.collection.KList;
|
||||
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public class Chunker<T> {
|
||||
private ExecutorService executor;
|
||||
private int threads;
|
||||
private int workload;
|
||||
private final KList<T> q;
|
||||
|
||||
public Chunker(KList<T> q) {
|
||||
this.q = q;
|
||||
}
|
||||
|
||||
public Chunker<T> threads(int threads) {
|
||||
this.threads = threads;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Chunker<T> workload(int workload) {
|
||||
this.workload = workload;
|
||||
return this;
|
||||
}
|
||||
|
||||
public void execute(Consumer<T> consumer, Callback<Double> progress, int progressInterval) {
|
||||
ChronoLatch cl = new ChronoLatch(progressInterval);
|
||||
Contained<Integer> consumed = new Contained<>(0);
|
||||
executor = Executors.newFixedThreadPool(threads);
|
||||
int length = q.size();
|
||||
int remaining = length;
|
||||
|
||||
while (remaining > 0) {
|
||||
int at = remaining;
|
||||
remaining -= (Math.min(remaining, workload));
|
||||
int to = remaining;
|
||||
|
||||
executor.submit(() ->
|
||||
{
|
||||
J.dofor(at, (i) -> i >= to, -1, (i) -> J.attempt(() -> consumer.accept(q.get(i))));
|
||||
consumed.mod((c) -> c += workload);
|
||||
J.doif(() -> progress != null && cl.flip(), () -> progress.run((double) consumed.get() / (double) length));
|
||||
});
|
||||
}
|
||||
|
||||
executor.shutdown();
|
||||
J.attempt(() -> executor.awaitTermination(100, TimeUnit.HOURS));
|
||||
}
|
||||
}
|
||||
@@ -23,14 +23,6 @@ import java.util.function.Function;
|
||||
public class Contained<T> {
|
||||
private T t;
|
||||
|
||||
public Contained(T t) {
|
||||
set(t);
|
||||
}
|
||||
|
||||
public Contained() {
|
||||
this(null);
|
||||
}
|
||||
|
||||
public void mod(Function<T, T> x) {
|
||||
set(x.apply(t));
|
||||
}
|
||||
|
||||
@@ -21,7 +21,6 @@ package com.volmit.iris.util.scheduling;
|
||||
import com.volmit.iris.Iris;
|
||||
import com.volmit.iris.util.collection.KMap;
|
||||
import com.volmit.iris.util.function.NastyRunnable;
|
||||
import com.volmit.iris.util.scheduling.J;
|
||||
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
|
||||
@@ -63,7 +63,8 @@ public class J {
|
||||
g.run();
|
||||
return true;
|
||||
}
|
||||
} catch (NullPointerException e) {Iris.reportError(e);
|
||||
} catch (NullPointerException e) {
|
||||
Iris.reportError(e);
|
||||
// TODO: Fix this because this is just a suppression for an NPE on g
|
||||
return false;
|
||||
}
|
||||
@@ -75,7 +76,8 @@ public class J {
|
||||
e.submit(() -> {
|
||||
try {
|
||||
a.run();
|
||||
} catch (Throwable e) {Iris.reportError(e);
|
||||
} catch (Throwable e) {
|
||||
Iris.reportError(e);
|
||||
System.out.println("Failed to run async task");
|
||||
e.printStackTrace();
|
||||
}
|
||||
@@ -86,7 +88,8 @@ public class J {
|
||||
e.submit(() -> {
|
||||
try {
|
||||
a.run();
|
||||
} catch (Throwable e) {Iris.reportError(e);
|
||||
} catch (Throwable e) {
|
||||
Iris.reportError(e);
|
||||
System.out.println("Failed to run async task");
|
||||
e.printStackTrace();
|
||||
}
|
||||
@@ -104,7 +107,8 @@ public class J {
|
||||
public static <R> R attemptResult(NastyFuture<R> r, R onError) {
|
||||
try {
|
||||
return r.run();
|
||||
} catch (Throwable e) {Iris.reportError(e);
|
||||
} catch (Throwable e) {
|
||||
Iris.reportError(e);
|
||||
|
||||
}
|
||||
|
||||
@@ -114,7 +118,8 @@ public class J {
|
||||
public static <T, R> R attemptFunction(NastyFunction<T, R> r, T param, R onError) {
|
||||
try {
|
||||
return r.run(param);
|
||||
} catch (Throwable e) {Iris.reportError(e);
|
||||
} catch (Throwable e) {
|
||||
Iris.reportError(e);
|
||||
|
||||
}
|
||||
|
||||
@@ -132,7 +137,8 @@ public class J {
|
||||
public static Throwable attemptCatch(NastyRunnable r) {
|
||||
try {
|
||||
r.run();
|
||||
} catch (Throwable e) {Iris.reportError(e);
|
||||
} catch (Throwable e) {
|
||||
Iris.reportError(e);
|
||||
return e;
|
||||
}
|
||||
|
||||
@@ -142,7 +148,8 @@ public class J {
|
||||
public static <T> T attempt(Supplier<T> t, T i) {
|
||||
try {
|
||||
return t.get();
|
||||
} catch (Throwable e) {Iris.reportError(e);
|
||||
} catch (Throwable e) {
|
||||
Iris.reportError(e);
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,9 +33,11 @@ public abstract class Looper extends Thread {
|
||||
|
||||
//noinspection BusyWait
|
||||
Thread.sleep(m);
|
||||
} catch (InterruptedException e) {Iris.reportError(e);
|
||||
} catch (InterruptedException e) {
|
||||
Iris.reportError(e);
|
||||
break;
|
||||
} catch (Throwable e) {Iris.reportError(e);
|
||||
} catch (Throwable e) {
|
||||
Iris.reportError(e);
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -195,7 +195,8 @@ public class TaskExecutor {
|
||||
try {
|
||||
task.run();
|
||||
state = TaskState.COMPLETED;
|
||||
} catch (Throwable ex) {Iris.reportError(ex);
|
||||
} catch (Throwable ex) {
|
||||
Iris.reportError(ex);
|
||||
ex.printStackTrace();
|
||||
Iris.reportError(ex);
|
||||
state = TaskState.FAILED;
|
||||
|
||||
@@ -62,7 +62,8 @@ public class ThreadMonitor extends Thread {
|
||||
if (cl.flip()) {
|
||||
Iris.info("Cycles: " + Form.f(cycles) + " (" + Form.duration(sq.getAverage(), 2) + ")");
|
||||
}
|
||||
} catch (Throwable e) {Iris.reportError(e);
|
||||
} catch (Throwable e) {
|
||||
Iris.reportError(e);
|
||||
running = false;
|
||||
break;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user