forked from StarOpenSource/Engine
Add Engine#shutdown method and shutdown events
This commit is contained in:
parent
95446a2562
commit
bd8b7818da
3 changed files with 96 additions and 0 deletions
|
@ -20,6 +20,8 @@
|
|||
package de.staropensource.sosengine.base;
|
||||
|
||||
import de.staropensource.sosengine.base.data.info.EngineInformation;
|
||||
import de.staropensource.sosengine.base.events.EngineShutdownEvent;
|
||||
import de.staropensource.sosengine.base.events.internal.InternalEngineShutdownEvent;
|
||||
import de.staropensource.sosengine.base.logging.CrashHandler;
|
||||
import de.staropensource.sosengine.base.logging.LoggerInstance;
|
||||
import de.staropensource.sosengine.base.types.CodePart;
|
||||
|
@ -27,6 +29,7 @@ import de.staropensource.sosengine.base.types.LogIssuer;
|
|||
import de.staropensource.sosengine.base.utility.*;
|
||||
import lombok.Getter;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Range;
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
|
@ -164,4 +167,25 @@ public final class Engine {
|
|||
CrashHandler.getCrashContent().put("Operating system", crashContentOS);
|
||||
CrashHandler.getCrashContent().put("Stacktrace", "%stacktrace%");
|
||||
}
|
||||
|
||||
/**
|
||||
* Shuts the engine and JVM down.
|
||||
*
|
||||
* @param exitCode the code to exit with, from 0-255
|
||||
* @since 1-alpha0
|
||||
*/
|
||||
public void shutdown(@Range(from = 0, to = 255) int exitCode) {
|
||||
new EngineShutdownEvent().callEvent();
|
||||
new InternalEngineShutdownEvent().callEvent();
|
||||
Runtime.getRuntime().exit(exitCode);
|
||||
}
|
||||
|
||||
/**
|
||||
* Shuts the engine and JVM down.
|
||||
*
|
||||
* @since 1-alpha0
|
||||
*/
|
||||
public void shutdown() {
|
||||
shutdown(0);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,36 @@
|
|||
/*
|
||||
STAROPENSOURCE ENGINE SOURCE FILE
|
||||
Copyright (c) 2024 The StarOpenSource Engine Contributors
|
||||
Licensed under the GNU Affero General Public License v3
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero 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 Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.staropensource.sosengine.base.events;
|
||||
|
||||
import de.staropensource.sosengine.base.classes.Event;
|
||||
import de.staropensource.sosengine.base.classes.helpers.EventHelper;
|
||||
|
||||
/**
|
||||
* Called when the engine and JVM are about to shutdown.
|
||||
*
|
||||
* @since 1-alpha0
|
||||
*/
|
||||
public class EngineShutdownEvent implements Event {
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
public void callEvent() {
|
||||
EventHelper.invokeAnnotatedMethods(getClass());
|
||||
}
|
||||
}
|
|
@ -0,0 +1,36 @@
|
|||
/*
|
||||
STAROPENSOURCE ENGINE SOURCE FILE
|
||||
Copyright (c) 2024 The StarOpenSource Engine Contributors
|
||||
Licensed under the GNU Affero General Public License v3
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero 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 Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.staropensource.sosengine.base.events.internal;
|
||||
|
||||
import de.staropensource.sosengine.base.classes.Event;
|
||||
import de.staropensource.sosengine.base.classes.helpers.EventHelper;
|
||||
|
||||
/**
|
||||
* Called when the engine and JVM are about to shutdown, after {@link de.staropensource.sosengine.base.events.EngineShutdownEvent}.
|
||||
*
|
||||
* @since 1-alpha0
|
||||
*/
|
||||
public class InternalEngineShutdownEvent implements Event {
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
public void callEvent() {
|
||||
EventHelper.invokeAnnotatedMethods(getClass());
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue