Introduced World Save Thread and some refractoring
This commit is contained in:
parent
a5b10b36ab
commit
98f4f02f55
@ -35,7 +35,7 @@
|
||||
import org.apache.commons.lang3.Validate;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
@@ -80,18 +86,54 @@
|
||||
@@ -80,28 +86,64 @@
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.event.world.WorldEvent;
|
||||
|
||||
@ -93,7 +93,19 @@
|
||||
private final ServerStatusResponse field_147147_p = new ServerStatusResponse();
|
||||
private final Random field_147146_q = new Random();
|
||||
@SideOnly(Side.SERVER)
|
||||
@@ -135,8 +177,40 @@
|
||||
private String hostname;
|
||||
private int serverPort = -1;
|
||||
public WorldServer[] worldServers = new WorldServer[0];
|
||||
- private ServerConfigurationManager serverConfigManager;
|
||||
+ public ServerConfigurationManager serverConfigManager;
|
||||
private boolean serverRunning = true;
|
||||
private boolean serverStopped;
|
||||
- private int tickCounter;
|
||||
+ public int tickCounter;
|
||||
protected final Proxy serverProxy;
|
||||
public String currentTask;
|
||||
public int percentDone;
|
||||
@@ -135,8 +177,41 @@
|
||||
private long field_147142_T = 0L;
|
||||
private final GameProfileRepository field_152365_W;
|
||||
private final PlayerProfileCache field_152366_X;
|
||||
@ -115,6 +127,7 @@
|
||||
+ public final double[] recentTps = new double[ 3 ];
|
||||
+ // Spigot end
|
||||
+ // Cauldron start
|
||||
+ public kcauldron.KCauldronWorldSaveThread saveThread;
|
||||
+ public static CauldronConfig cauldronConfig;
|
||||
+ public static KCauldronConfig kcauldronConfig;
|
||||
+ public static TileEntityConfig tileEntityConfig;
|
||||
@ -134,7 +147,7 @@
|
||||
public MinecraftServer(File p_i45281_1_, Proxy p_i45281_2_)
|
||||
{
|
||||
this.field_152366_X = new PlayerProfileCache(this, field_152367_a);
|
||||
@@ -149,10 +223,70 @@
|
||||
@@ -149,10 +224,70 @@
|
||||
this.field_152364_T = new YggdrasilAuthenticationService(p_i45281_2_, UUID.randomUUID().toString());
|
||||
this.field_147143_S = this.field_152364_T.createMinecraftSessionService();
|
||||
this.field_152365_W = this.field_152364_T.createProfileRepository();
|
||||
@ -206,7 +219,7 @@
|
||||
protected void convertMapIfNeeded(String p_71237_1_)
|
||||
{
|
||||
if (this.getActiveAnvilConverter().isOldMapFormat(p_71237_1_))
|
||||
@@ -172,6 +306,7 @@
|
||||
@@ -172,6 +307,7 @@
|
||||
MinecraftServer.logger.info("Converting... " + p_73718_1_ + "%");
|
||||
}
|
||||
}
|
||||
@ -214,7 +227,7 @@
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void resetProgressAndMessage(String p_73721_1_) {}
|
||||
@SideOnly(Side.CLIENT)
|
||||
@@ -195,10 +330,17 @@
|
||||
@@ -195,10 +331,17 @@
|
||||
|
||||
protected void loadAllWorlds(String p_71247_1_, String p_71247_2_, long p_71247_3_, WorldType p_71247_5_, String p_71247_6_)
|
||||
{
|
||||
@ -234,7 +247,7 @@
|
||||
WorldSettings worldsettings;
|
||||
|
||||
if (worldinfo == null)
|
||||
@@ -215,11 +357,79 @@
|
||||
@@ -215,11 +358,79 @@
|
||||
{
|
||||
worldsettings.enableBonusChest();
|
||||
}
|
||||
@ -317,7 +330,7 @@
|
||||
world.addWorldAccess(new WorldManager(this, world));
|
||||
|
||||
if (!this.isSinglePlayer())
|
||||
@@ -227,12 +437,14 @@
|
||||
@@ -227,12 +438,14 @@
|
||||
world.getWorldInfo().setGameType(this.getGameType());
|
||||
}
|
||||
|
||||
@ -335,7 +348,7 @@
|
||||
}
|
||||
|
||||
protected void initialWorldChunkLoad()
|
||||
@@ -244,9 +456,12 @@
|
||||
@@ -244,9 +457,12 @@
|
||||
int i = 0;
|
||||
this.setUserMessage("menu.generatingTerrain");
|
||||
byte b0 = 0;
|
||||
@ -348,7 +361,7 @@
|
||||
long j = getSystemTimeMillis();
|
||||
|
||||
for (int k = -192; k <= 192 && this.isServerRunning(); k += 16)
|
||||
@@ -265,7 +480,8 @@
|
||||
@@ -265,7 +481,8 @@
|
||||
worldserver.theChunkProviderServer.loadChunk(chunkcoordinates.posX + k >> 4, chunkcoordinates.posZ + l >> 4);
|
||||
}
|
||||
}
|
||||
@ -358,7 +371,7 @@
|
||||
this.clearCurrentTask();
|
||||
}
|
||||
|
||||
@@ -292,19 +508,17 @@
|
||||
@@ -292,19 +509,17 @@
|
||||
{
|
||||
this.currentTask = null;
|
||||
this.percentDone = 0;
|
||||
@ -366,7 +379,7 @@
|
||||
}
|
||||
|
||||
- protected void saveAllWorlds(boolean p_71267_1_)
|
||||
+ protected void saveAllWorlds(boolean p_71267_1_) throws MinecraftException // CraftBukkit - added throws
|
||||
+ public void saveAllWorlds(boolean p_71267_1_) throws MinecraftException // CraftBukkit - added throws
|
||||
{
|
||||
if (!this.worldIsBeingDeleted)
|
||||
{
|
||||
@ -383,7 +396,7 @@
|
||||
|
||||
if (worldserver != null)
|
||||
{
|
||||
@@ -313,25 +527,41 @@
|
||||
@@ -313,25 +528,42 @@
|
||||
logger.info("Saving chunks for level \'" + worldserver.getWorldInfo().getWorldName() + "\'/" + worldserver.provider.getDimensionName());
|
||||
}
|
||||
|
||||
@ -415,6 +428,7 @@
|
||||
- public void stopServer()
|
||||
+ public void stopServer() throws MinecraftException // CraftBukkit - added throws
|
||||
{
|
||||
+ if (saveThread != null) saveThread.stopServer();
|
||||
if (!this.worldIsBeingDeleted && Loader.instance().hasReachedState(LoaderState.SERVER_STARTED) && !serverStopped) // make sure the save is valid and we don't save twice
|
||||
{
|
||||
logger.info("Stopping server");
|
||||
@ -430,7 +444,7 @@
|
||||
if (this.func_147137_ag() != null)
|
||||
{
|
||||
this.func_147137_ag().terminateEndpoints();
|
||||
@@ -347,7 +577,14 @@
|
||||
@@ -347,7 +579,14 @@
|
||||
if (this.worldServers != null)
|
||||
{
|
||||
logger.info("Saving worlds");
|
||||
@ -446,7 +460,7 @@
|
||||
|
||||
for (int i = 0; i < this.worldServers.length; ++i)
|
||||
{
|
||||
@@ -380,6 +617,13 @@
|
||||
@@ -380,6 +619,13 @@
|
||||
this.serverRunning = false;
|
||||
}
|
||||
|
||||
@ -460,7 +474,7 @@
|
||||
public void run()
|
||||
{
|
||||
try
|
||||
@@ -392,45 +636,41 @@
|
||||
@@ -392,45 +638,41 @@
|
||||
this.field_147147_p.func_151315_a(new ChatComponentText(this.motd));
|
||||
this.field_147147_p.func_151321_a(new ServerStatusResponse.MinecraftProtocolVersionIdentifier("1.7.10", 5));
|
||||
this.func_147138_a(this.field_147147_p);
|
||||
@ -527,7 +541,7 @@
|
||||
FMLCommonHandler.instance().handleServerStopping();
|
||||
FMLCommonHandler.instance().expectServerStopped(); // has to come before finalTick to avoid race conditions
|
||||
}
|
||||
@@ -448,6 +688,14 @@
|
||||
@@ -448,6 +690,14 @@
|
||||
catch (Throwable throwable1)
|
||||
{
|
||||
logger.error("Encountered an unexpected exception", throwable1);
|
||||
@ -542,7 +556,7 @@
|
||||
CrashReport crashreport = null;
|
||||
|
||||
if (throwable1 instanceof ReportedException)
|
||||
@@ -477,6 +725,7 @@
|
||||
@@ -477,6 +727,7 @@
|
||||
{
|
||||
try
|
||||
{
|
||||
@ -550,7 +564,7 @@
|
||||
this.stopServer();
|
||||
this.serverStopped = true;
|
||||
}
|
||||
@@ -486,6 +735,16 @@
|
||||
@@ -486,6 +737,16 @@
|
||||
}
|
||||
finally
|
||||
{
|
||||
@ -567,7 +581,7 @@
|
||||
FMLCommonHandler.instance().handleServerStopped();
|
||||
this.serverStopped = true;
|
||||
this.systemExitNow();
|
||||
@@ -532,8 +791,11 @@
|
||||
@@ -532,8 +793,11 @@
|
||||
|
||||
public void tick()
|
||||
{
|
||||
@ -579,31 +593,20 @@
|
||||
++this.tickCounter;
|
||||
|
||||
if (this.startProfiling)
|
||||
@@ -562,12 +824,21 @@
|
||||
@@ -562,38 +826,62 @@
|
||||
this.field_147147_p.func_151318_b().func_151330_a(agameprofile);
|
||||
}
|
||||
|
||||
- if (this.tickCounter % 900 == 0)
|
||||
+ if ((this.autosavePeriod > 0) && ((this.tickCounter % this.autosavePeriod) == 0)) // CraftBukkit
|
||||
{
|
||||
+ SpigotTimings.worldSaveTimer.startTiming(); // Spigot
|
||||
this.theProfiler.startSection("save");
|
||||
this.serverConfigManager.saveAllPlayerData();
|
||||
- {
|
||||
- this.theProfiler.startSection("save");
|
||||
- this.serverConfigManager.saveAllPlayerData();
|
||||
- this.saveAllWorlds(true);
|
||||
+ try
|
||||
+ {
|
||||
+ this.saveAllWorlds(true);
|
||||
+ }
|
||||
+ catch (MinecraftException e)
|
||||
+ {
|
||||
+ e.printStackTrace();
|
||||
+ }
|
||||
this.theProfiler.endSection();
|
||||
+ SpigotTimings.worldSaveTimer.stopTiming(); // Spigot
|
||||
}
|
||||
|
||||
- this.theProfiler.endSection();
|
||||
- }
|
||||
-
|
||||
this.theProfiler.startSection("tallying");
|
||||
@@ -575,25 +846,57 @@
|
||||
this.tickTimeArray[this.tickCounter % 100] = System.nanoTime() - i;
|
||||
this.theProfiler.endSection();
|
||||
this.theProfiler.startSection("snooper");
|
||||
|
||||
@ -663,7 +666,7 @@
|
||||
int i;
|
||||
|
||||
Integer[] ids = DimensionManager.getIDs(this.tickCounter % 200 == 0);
|
||||
@@ -602,19 +905,22 @@
|
||||
@@ -602,19 +890,22 @@
|
||||
int id = ids[x];
|
||||
long j = System.nanoTime();
|
||||
|
||||
@ -689,7 +692,7 @@
|
||||
|
||||
this.theProfiler.startSection("tick");
|
||||
FMLCommonHandler.instance().onPreWorldTick(worldserver);
|
||||
@@ -622,22 +928,46 @@
|
||||
@@ -622,22 +913,46 @@
|
||||
|
||||
try
|
||||
{
|
||||
@ -738,7 +741,7 @@
|
||||
worldserver.addWorldInfoToCrashReport(crashreport);
|
||||
throw new ReportedException(crashreport);
|
||||
}
|
||||
@@ -645,10 +975,13 @@
|
||||
@@ -645,10 +960,13 @@
|
||||
FMLCommonHandler.instance().onPostWorldTick(worldserver);
|
||||
this.theProfiler.endSection();
|
||||
this.theProfiler.startSection("tracker");
|
||||
@ -753,7 +756,7 @@
|
||||
|
||||
worldTickTimes.get(id)[this.tickCounter % 100] = System.nanoTime() - j;
|
||||
}
|
||||
@@ -656,15 +989,21 @@
|
||||
@@ -656,15 +974,21 @@
|
||||
this.theProfiler.endStartSection("dim_unloading");
|
||||
DimensionManager.unloadWorlds(worldTickTimes);
|
||||
this.theProfiler.endStartSection("connection");
|
||||
@ -775,7 +778,7 @@
|
||||
|
||||
this.theProfiler.endSection();
|
||||
}
|
||||
@@ -699,6 +1038,13 @@
|
||||
@@ -699,6 +1023,13 @@
|
||||
|
||||
public WorldServer worldServerForDimension(int p_71218_1_)
|
||||
{
|
||||
@ -789,7 +792,7 @@
|
||||
WorldServer ret = DimensionManager.getWorld(p_71218_1_);
|
||||
if (ret == null)
|
||||
{
|
||||
@@ -784,13 +1130,14 @@
|
||||
@@ -784,13 +1115,14 @@
|
||||
|
||||
public List getPossibleCompletions(ICommandSender p_71248_1_, String p_71248_2_)
|
||||
{
|
||||
@ -808,7 +811,7 @@
|
||||
|
||||
if (list != null)
|
||||
{
|
||||
@@ -798,40 +1145,25 @@
|
||||
@@ -798,40 +1130,25 @@
|
||||
|
||||
while (iterator.hasNext())
|
||||
{
|
||||
@ -857,7 +860,7 @@
|
||||
}
|
||||
|
||||
public static MinecraftServer getServer()
|
||||
@@ -1034,7 +1366,7 @@
|
||||
@@ -1034,7 +1351,7 @@
|
||||
|
||||
public boolean isServerInOnlineMode()
|
||||
{
|
||||
@ -866,7 +869,7 @@
|
||||
}
|
||||
|
||||
public void setOnlineMode(boolean p_71229_1_)
|
||||
@@ -1124,7 +1456,7 @@
|
||||
@@ -1124,7 +1441,7 @@
|
||||
|
||||
public NetworkSystem func_147137_ag()
|
||||
{
|
||||
@ -875,7 +878,7 @@
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
@@ -1259,8 +1591,11 @@
|
||||
@@ -1259,8 +1576,11 @@
|
||||
{
|
||||
Bootstrap.func_151354_b();
|
||||
|
||||
@ -887,7 +890,7 @@
|
||||
boolean flag = true;
|
||||
String s = null;
|
||||
String s1 = ".";
|
||||
@@ -1356,16 +1691,34 @@
|
||||
@@ -1356,16 +1676,34 @@
|
||||
{
|
||||
dedicatedserver.setGuiEnabled();
|
||||
}
|
||||
@ -928,7 +931,7 @@
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
@@ -1400,15 +1753,70 @@
|
||||
@@ -1400,15 +1738,70 @@
|
||||
@SideOnly(Side.SERVER)
|
||||
public String getPlugins()
|
||||
{
|
||||
@ -1004,7 +1007,7 @@
|
||||
}
|
||||
|
||||
@SideOnly(Side.SERVER)
|
||||
@@ -1455,9 +1863,213 @@
|
||||
@@ -1455,9 +1848,226 @@
|
||||
return this.serverStopped;
|
||||
}
|
||||
|
||||
@ -1217,4 +1220,17 @@
|
||||
+ return logger;
|
||||
+ }
|
||||
+ // CraftBukkit end
|
||||
+
|
||||
+ public void invalidateWorldSaver() {
|
||||
+ if (saveThread != null) {
|
||||
+ saveThread.interrupt();
|
||||
+ saveThread = null;
|
||||
+ }
|
||||
+ if (autosavePeriod > 0) {
|
||||
+ saveThread = new kcauldron.KCauldronWorldSaveThread(this);
|
||||
+ saveThread.start();
|
||||
+ } else {
|
||||
+ kcauldron.KLog.get().info("No valid autosave period is setted, assumed plugin-induved world saving!");
|
||||
+ }
|
||||
+ }
|
||||
}
|
||||
|
@ -13,6 +13,8 @@ import cpw.mods.fml.common.FMLCommonHandler;
|
||||
import cpw.mods.fml.common.FMLLog;
|
||||
|
||||
public class KCauldron {
|
||||
public static final ThreadGroup sKCauldronThreadGroup = new ThreadGroup("KCauldron");
|
||||
|
||||
private static boolean sManifestParsed = false;
|
||||
|
||||
private static void parseManifest() {
|
||||
|
57
src/main/java/kcauldron/KCauldronWorldSaveThread.java
Normal file
57
src/main/java/kcauldron/KCauldronWorldSaveThread.java
Normal file
@ -0,0 +1,57 @@
|
||||
package kcauldron;
|
||||
|
||||
import org.bukkit.craftbukkit.SpigotTimings;
|
||||
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.world.MinecraftException;
|
||||
|
||||
public class KCauldronWorldSaveThread extends Thread {
|
||||
private final MinecraftServer mServer;
|
||||
private int mLastSaveTick = -1;
|
||||
private int mNextSaveTick = -1;
|
||||
|
||||
public KCauldronWorldSaveThread(MinecraftServer server) {
|
||||
super(KCauldron.sKCauldronThreadGroup, "KCauldron World Save");
|
||||
mServer = server;
|
||||
setPriority(Thread.MIN_PRIORITY);
|
||||
setDaemon(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
KLog.get().info("Starting KCauldron World Saver thread...");
|
||||
try {
|
||||
while (!isInterrupted()) {
|
||||
if (mLastSaveTick < 0) {
|
||||
mLastSaveTick = mServer.tickCounter;
|
||||
}
|
||||
mNextSaveTick = mLastSaveTick + mServer.autosavePeriod;
|
||||
while (mNextSaveTick > mServer.tickCounter) {
|
||||
try {
|
||||
sleep((mNextSaveTick - mServer.tickCounter) * 50);
|
||||
} catch (InterruptedException e) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
SpigotTimings.worldSaveTimer.startTiming();
|
||||
try {
|
||||
mServer.serverConfigManager.saveAllPlayerData();
|
||||
mServer.saveAllWorlds(true);
|
||||
} catch (MinecraftException e) {
|
||||
new RuntimeException("Error occurred during save world", e).printStackTrace();
|
||||
}
|
||||
SpigotTimings.worldSaveTimer.stopTiming();
|
||||
mLastSaveTick = mServer.tickCounter;
|
||||
}
|
||||
} finally {
|
||||
KLog.get().info("Stopping KCauldron World Saver thread...");
|
||||
}
|
||||
}
|
||||
|
||||
public void stopServer() {
|
||||
interrupt();
|
||||
while(isAlive()) {
|
||||
Thread.yield();
|
||||
}
|
||||
}
|
||||
}
|
@ -86,8 +86,7 @@ public class KCauldronUpdater implements Runnable, IVersionCheckCallback {
|
||||
public KCauldronUpdater(CommandSender sender, String version) {
|
||||
mSender = sender;
|
||||
mVersion = version;
|
||||
mThread = new Thread(this);
|
||||
mThread.setName("KCauldron updater");
|
||||
mThread = new Thread(KCauldron.sKCauldronThreadGroup, this, "KCauldron updated");
|
||||
mThread.setPriority(Thread.MIN_PRIORITY);
|
||||
mThread.start();
|
||||
}
|
||||
|
@ -56,8 +56,7 @@ public class KVersionRetriever implements Runnable, UncaughtExceptionHandler {
|
||||
mUpToDateSupport = upToDateSupport;
|
||||
mGroup = group;
|
||||
mName = name;
|
||||
mThread = new Thread(this);
|
||||
mThread.setName("KCauldron version retrievier");
|
||||
mThread = new Thread(KCauldron.sKCauldronThreadGroup, this, "KCauldron version retrievier");
|
||||
mThread.setPriority(Thread.MIN_PRIORITY);
|
||||
mThread.setDaemon(true);
|
||||
mThread.setUncaughtExceptionHandler(this);
|
||||
|
@ -263,6 +263,7 @@ public final class CraftServer implements Server {
|
||||
waterAnimalSpawn = configuration.getInt("spawn-limits.water-animals");
|
||||
ambientSpawn = configuration.getInt("spawn-limits.ambient");
|
||||
console.autosavePeriod = configuration.getInt("ticks-per.autosave");
|
||||
console.invalidateWorldSaver();
|
||||
warningState = WarningState.value(configuration.getString("settings.deprecated-verbose"));
|
||||
loadIcon();
|
||||
chunkGCEnabled = configuration.getBoolean("chunk-gc.enabled"); // Cauldron
|
||||
@ -764,6 +765,7 @@ public final class CraftServer implements Server {
|
||||
warningState = WarningState.value(configuration.getString("settings.deprecated-verbose"));
|
||||
printSaveWarning = false;
|
||||
console.autosavePeriod = configuration.getInt("ticks-per.autosave");
|
||||
console.invalidateWorldSaver();
|
||||
chunkGCPeriod = configuration.getInt("chunk-gc.period-in-ticks");
|
||||
chunkGCLoadThresh = configuration.getInt("chunk-gc.load-threshold");
|
||||
loadIcon();
|
||||
|
Loading…
Reference in New Issue
Block a user