mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2025-07-18 18:23:06 +00:00
Fix closing issues
This commit is contained in:
parent
c95ea19da1
commit
79b3d7359a
@ -43,6 +43,7 @@ import com.volmit.iris.util.format.Form;
|
|||||||
import com.volmit.iris.util.function.NastyRunnable;
|
import com.volmit.iris.util.function.NastyRunnable;
|
||||||
import com.volmit.iris.util.io.FileWatcher;
|
import com.volmit.iris.util.io.FileWatcher;
|
||||||
import com.volmit.iris.util.io.IO;
|
import com.volmit.iris.util.io.IO;
|
||||||
|
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;
|
||||||
@ -74,6 +75,7 @@ import java.io.*;
|
|||||||
import java.lang.annotation.Annotation;
|
import java.lang.annotation.Annotation;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
@SuppressWarnings("CanBeFinal")
|
@SuppressWarnings("CanBeFinal")
|
||||||
public class Iris extends VolmitPlugin implements Listener {
|
public class Iris extends VolmitPlugin implements Listener {
|
||||||
@ -137,6 +139,36 @@ public class Iris extends VolmitPlugin implements Listener {
|
|||||||
splash();
|
splash();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void onDisable() {
|
||||||
|
if (IrisSettings.get().isStudio()) {
|
||||||
|
Iris.debug("Studio Mode Active: Closing Projects");
|
||||||
|
proj.close();
|
||||||
|
|
||||||
|
for (World i : Bukkit.getWorlds()) {
|
||||||
|
if (IrisToolbelt.isIrisWorld(i)) {
|
||||||
|
Iris.debug("Closing Platform Generator " + i.getName());
|
||||||
|
IrisToolbelt.access(i).close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (GroupedExecutor i : executors) {
|
||||||
|
Iris.debug("Closing Executor " + i.toString());
|
||||||
|
i.closeNow();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
executors.clear();
|
||||||
|
board.disable();
|
||||||
|
Iris.debug("Cancelled all tasks");
|
||||||
|
Bukkit.getScheduler().cancelTasks(this);
|
||||||
|
Iris.debug("Unregistered all events");
|
||||||
|
HandlerList.unregisterAll((Plugin) this);
|
||||||
|
Iris.debug("Multiburst Shutting down");
|
||||||
|
MultiBurst.burst.shutdown();
|
||||||
|
Iris.debug("Iris Shutdown");
|
||||||
|
super.onDisable();
|
||||||
|
}
|
||||||
|
|
||||||
public static void callEvent(Event e) {
|
public static void callEvent(Event e) {
|
||||||
J.s(() -> Bukkit.getPluginManager().callEvent(e));
|
J.s(() -> Bukkit.getPluginManager().callEvent(e));
|
||||||
}
|
}
|
||||||
@ -262,29 +294,6 @@ public class Iris extends VolmitPlugin implements Listener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onDisable() {
|
|
||||||
if (IrisSettings.get().isStudio()) {
|
|
||||||
proj.close();
|
|
||||||
|
|
||||||
for (World i : Bukkit.getWorlds()) {
|
|
||||||
if (IrisToolbelt.isIrisWorld(i)) {
|
|
||||||
IrisToolbelt.access(i).close();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (GroupedExecutor i : executors) {
|
|
||||||
i.close();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
executors.clear();
|
|
||||||
board.disable();
|
|
||||||
Bukkit.getScheduler().cancelTasks(this);
|
|
||||||
HandlerList.unregisterAll((Plugin) this);
|
|
||||||
MultiBurst.burst.shutdown();
|
|
||||||
super.onDisable();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void sq(Runnable r) {
|
public static void sq(Runnable r) {
|
||||||
synchronized (syncJobs) {
|
synchronized (syncJobs) {
|
||||||
syncJobs.queue(r);
|
syncJobs.queue(r);
|
||||||
@ -695,4 +704,16 @@ public class Iris extends VolmitPlugin implements Listener {
|
|||||||
Iris.debug("Exception Logged: " + e.getClass().getSimpleName() + ": " + C.RESET + "" + C.LIGHT_PURPLE + e.getMessage());
|
Iris.debug("Exception Logged: " + e.getClass().getSimpleName() + ": " + C.RESET + "" + C.LIGHT_PURPLE + e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static {
|
||||||
|
try
|
||||||
|
{
|
||||||
|
InstanceState.updateInstanceId();
|
||||||
|
}
|
||||||
|
|
||||||
|
catch(Throwable e)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -356,6 +356,7 @@ public class ProjectManager {
|
|||||||
|
|
||||||
public void close() {
|
public void close() {
|
||||||
if (isProjectOpen()) {
|
if (isProjectOpen()) {
|
||||||
|
Iris.debug("Closing Active Project");
|
||||||
activeProject.close();
|
activeProject.close();
|
||||||
activeProject = null;
|
activeProject = null;
|
||||||
}
|
}
|
||||||
|
@ -26,6 +26,7 @@ import com.volmit.iris.core.project.loader.IrisData;
|
|||||||
import com.volmit.iris.core.project.loader.ResourceLoader;
|
import com.volmit.iris.core.project.loader.ResourceLoader;
|
||||||
import com.volmit.iris.core.report.Report;
|
import com.volmit.iris.core.report.Report;
|
||||||
import com.volmit.iris.core.report.ReportType;
|
import com.volmit.iris.core.report.ReportType;
|
||||||
|
import com.volmit.iris.core.tools.IrisToolbelt;
|
||||||
import com.volmit.iris.core.tools.IrisWorldCreator;
|
import com.volmit.iris.core.tools.IrisWorldCreator;
|
||||||
import com.volmit.iris.engine.framework.Engine;
|
import com.volmit.iris.engine.framework.Engine;
|
||||||
import com.volmit.iris.engine.object.biome.IrisBiome;
|
import com.volmit.iris.engine.object.biome.IrisBiome;
|
||||||
@ -238,11 +239,14 @@ public class IrisProject {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void close() {
|
public void close() {
|
||||||
|
Iris.debug("Closing Active Provider");
|
||||||
|
IrisToolbelt.evacuate(activeProvider.getTarget().getWorld().realWorld());
|
||||||
activeProvider.close();
|
activeProvider.close();
|
||||||
File folder = activeProvider.getTarget().getWorld().worldFolder();
|
File folder = activeProvider.getTarget().getWorld().worldFolder();
|
||||||
Iris.linkMultiverseCore.removeFromConfig(activeProvider.getTarget().getWorld().name());
|
Iris.linkMultiverseCore.removeFromConfig(activeProvider.getTarget().getWorld().name());
|
||||||
Bukkit.unloadWorld(activeProvider.getTarget().getWorld().name(), false);
|
Bukkit.unloadWorld(activeProvider.getTarget().getWorld().name(), false);
|
||||||
J.attemptAsync(() -> IO.delete(folder));
|
J.attemptAsync(() -> IO.delete(folder));
|
||||||
|
Iris.debug("Closed Active Provider " + activeProvider.getTarget().getWorld().name());
|
||||||
activeProvider = null;
|
activeProvider = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
53
src/main/java/com/volmit/iris/util/io/InstanceState.java
Normal file
53
src/main/java/com/volmit/iris/util/io/InstanceState.java
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
/*
|
||||||
|
* 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.io;
|
||||||
|
|
||||||
|
import com.volmit.iris.util.math.RNG;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
public class InstanceState {
|
||||||
|
public static int getInstanceId()
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
return Integer.parseInt(IO.readAll(instanceFile()).trim());
|
||||||
|
} catch (Throwable e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void updateInstanceId()
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
IO.writeAll(instanceFile(), RNG.r.imax() + "");
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static File instanceFile()
|
||||||
|
{
|
||||||
|
File f = new File("plugins/Iris/cache/instance");
|
||||||
|
f.getParentFile().mkdirs();
|
||||||
|
return f;
|
||||||
|
}
|
||||||
|
}
|
@ -21,6 +21,7 @@ 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.IrisSettings;
|
||||||
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 com.volmit.iris.util.scheduling.J;
|
||||||
import com.volmit.iris.util.scheduling.Looper;
|
import com.volmit.iris.util.scheduling.Looper;
|
||||||
@ -38,6 +39,7 @@ public class MultiBurst {
|
|||||||
private final String name;
|
private final String name;
|
||||||
private final int tc;
|
private final int tc;
|
||||||
private final int priority;
|
private final int priority;
|
||||||
|
private final int instance;
|
||||||
|
|
||||||
public MultiBurst(int tc) {
|
public MultiBurst(int tc) {
|
||||||
this("Iris", 6, tc);
|
this("Iris", 6, tc);
|
||||||
@ -47,17 +49,24 @@ public class MultiBurst {
|
|||||||
this.name = name;
|
this.name = name;
|
||||||
this.priority = priority;
|
this.priority = priority;
|
||||||
this.tc = tc;
|
this.tc = tc;
|
||||||
|
instance = InstanceState.getInstanceId();
|
||||||
last = new AtomicLong(M.ms());
|
last = new AtomicLong(M.ms());
|
||||||
heartbeat = new Looper() {
|
heartbeat = new Looper() {
|
||||||
@Override
|
@Override
|
||||||
protected long loop() {
|
protected long loop() {
|
||||||
|
if(instance != InstanceState.getInstanceId())
|
||||||
|
{
|
||||||
|
shutdownNow();
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
if (M.ms() - last.get() > TimeUnit.MINUTES.toMillis(1) && service != null) {
|
if (M.ms() - last.get() > TimeUnit.MINUTES.toMillis(1) && service != null) {
|
||||||
service.shutdown();
|
service.shutdown();
|
||||||
service = null;
|
service = null;
|
||||||
Iris.debug("Shutting down MultiBurst Pool " + getName() + " to conserve resources.");
|
Iris.debug("Shutting down MultiBurst Pool " + getName() + " to conserve resources.");
|
||||||
}
|
}
|
||||||
|
|
||||||
return 60000;
|
return 30000;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
heartbeat.setName(name + " Monitor");
|
heartbeat.setName(name + " Monitor");
|
||||||
|
@ -42,7 +42,7 @@ public abstract class Looper extends Thread {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Iris.info("Thread " + getName() + " Shutdown. Pregen stopped / finished.");
|
Iris.debug("Iris Thread " + getName() + " Shutdown.");
|
||||||
}
|
}
|
||||||
|
|
||||||
protected abstract long loop();
|
protected abstract long loop();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user