WebServer now initialized inside WebServerSystem

This commit is contained in:
Rsl1122 2017-12-12 14:05:48 +02:00
parent be21756611
commit c1229385c4
4 changed files with 77 additions and 29 deletions

View File

@ -60,6 +60,7 @@ import main.java.com.djrapitops.plan.systems.store.config.ConfigSystem;
import main.java.com.djrapitops.plan.systems.store.database.DBSystem;
import main.java.com.djrapitops.plan.systems.tasks.TPSCountTimer;
import main.java.com.djrapitops.plan.systems.webserver.WebServer;
import main.java.com.djrapitops.plan.systems.webserver.WebServerSystem;
import main.java.com.djrapitops.plan.systems.webserver.pagecache.PageCache;
import main.java.com.djrapitops.plan.utilities.file.export.HtmlExport;
import main.java.com.djrapitops.plan.utilities.metrics.BStats;
@ -91,8 +92,6 @@ public class Plan extends BukkitPlugin implements IPlan {
private ProcessingQueue processingQueue;
private HookHandler hookHandler; // Manages 3rd party data sources
private WebServer webServer;
private BukkitInformationManager infoManager;
private BukkitServerInfoManager serverInfoManager;
@ -185,15 +184,13 @@ public class Plan extends BukkitPlugin implements IPlan {
DBSystem.getInstance().init();
Benchmark.start("WebServer Initialization");
webServer = new WebServer(this);
processingQueue = new ProcessingQueue();
serverInfoManager = new BukkitServerInfoManager(this);
infoManager = new BukkitInformationManager(this);
webServer.initServer();
if (!webServer.isEnabled()) {
WebServerSystem.getInstance().init();
if (!WebServerSystem.isWebServerEnabled()) {
if (Settings.WEBSERVER_DISABLED.isTrue()) {
Log.warn("WebServer was not initialized. (WebServer.DisableWebServer: true)");
} else {
@ -316,11 +313,6 @@ public class Plan extends BukkitPlugin implements IPlan {
//Clears the page cache
PageCache.clearCache();
// Stop the UI Server
if (webServer != null) {
webServer.stop();
}
// Processes unprocessed processors
if (processingQueue != null) {
List<Processor> processors = processingQueue.stopAndReturnLeftovers();
@ -394,7 +386,7 @@ public class Plan extends BukkitPlugin implements IPlan {
* @return the WebServer
*/
public WebServer getWebServer() {
return webServer;
return WebServerSystem.getInstance().getWebServer();
}
/**

View File

@ -35,6 +35,7 @@ import main.java.com.djrapitops.plan.systems.store.config.ConfigSystem;
import main.java.com.djrapitops.plan.systems.store.database.DBSystem;
import main.java.com.djrapitops.plan.systems.tasks.TPSCountTimer;
import main.java.com.djrapitops.plan.systems.webserver.WebServer;
import main.java.com.djrapitops.plan.systems.webserver.WebServerSystem;
import main.java.com.djrapitops.plan.utilities.file.export.HtmlExport;
import net.md_5.bungee.api.ChatColor;
@ -53,7 +54,6 @@ public class PlanBungee extends BungeePlugin implements IPlan {
private Systems systems;
private WebServer webServer;
private BungeeServerInfoManager serverInfoManager;
private BungeeInformationManager infoManager;
private ServerVariableHolder variableHolder;
@ -103,20 +103,13 @@ public class PlanBungee extends BungeePlugin implements IPlan {
}
Benchmark.start("WebServer Initialization");
webServer = new WebServer(this);
serverInfoManager = new BungeeServerInfoManager(this);
infoManager = new BungeeInformationManager(this);
webServer.initServer();
WebServerSystem.getInstance().init();
serverInfoManager.loadServerInfo();
if (!webServer.isEnabled()) {
Log.error("WebServer was not successfully initialized.");
onDisable();
return;
}
RunnableFactory.createNew("Enable Bukkit Connection Task", new AbsRunnable() {
@Override
public void run() {
@ -162,9 +155,6 @@ public class PlanBungee extends BungeePlugin implements IPlan {
/*ignored*/
}
}
if (webServer != null) {
webServer.stop();
}
systems.close();
Log.info(Locale.get(Msg.DISABLED).toString());
super.onDisable();
@ -197,7 +187,7 @@ public class PlanBungee extends BungeePlugin implements IPlan {
@Override
public WebServer getWebServer() {
return webServer;
return WebServerSystem.getInstance().getWebServer();
}

View File

@ -4,6 +4,7 @@
*/
package main.java.com.djrapitops.plan.systems;
import com.djrapitops.plugin.api.utility.log.Log;
import main.java.com.djrapitops.plan.Plan;
import main.java.com.djrapitops.plan.PlanBungee;
import main.java.com.djrapitops.plan.systems.store.FileSystem;
@ -13,6 +14,7 @@ import main.java.com.djrapitops.plan.systems.store.config.PlanConfigSystem;
import main.java.com.djrapitops.plan.systems.store.database.DBSystem;
import main.java.com.djrapitops.plan.systems.store.database.PlanBungeeDBSystem;
import main.java.com.djrapitops.plan.systems.store.database.PlanDBSystem;
import main.java.com.djrapitops.plan.systems.webserver.WebServerSystem;
import main.java.com.djrapitops.plan.utilities.MiscUtils;
import org.apache.commons.lang3.ArrayUtils;
@ -24,8 +26,10 @@ import org.apache.commons.lang3.ArrayUtils;
public class Systems {
private FileSystem fileSystem;
private DBSystem databaseSystem;
private ConfigSystem configSystem;
private DBSystem databaseSystem;
private WebServerSystem webServerSystem;
/**
* Constructor for Bukkit version.
@ -37,6 +41,7 @@ public class Systems {
configSystem = new PlanConfigSystem();
databaseSystem = new PlanDBSystem();
webServerSystem = new WebServerSystem(plugin);
}
/**
@ -48,13 +53,16 @@ public class Systems {
fileSystem = new FileSystem(plugin);
configSystem = new PlanBungeeConfigSystem();
databaseSystem = new PlanBungeeDBSystem();
webServerSystem = new WebServerSystem(plugin);
}
private SubSystem[] getSubSystems() {
return new SubSystem[]{
fileSystem,
configSystem,
databaseSystem
databaseSystem,
webServerSystem
};
}
@ -62,7 +70,11 @@ public class Systems {
SubSystem[] subSystems = getSubSystems();
ArrayUtils.reverse(subSystems);
for (SubSystem subSystem : subSystems) {
subSystem.close();
try {
subSystem.close();
} catch (Exception e) {
Log.toLog(Systems.class, e);
}
}
}
@ -81,4 +93,8 @@ public class Systems {
public ConfigSystem getConfigSystem() {
return configSystem;
}
public WebServerSystem getWebServerSystem() {
return webServerSystem;
}
}

View File

@ -0,0 +1,50 @@
/*
* Licence is provided in the jar as license.yml also here:
* https://github.com/Rsl1122/Plan-PlayerAnalytics/blob/master/Plan/src/main/resources/license.yml
*/
package main.java.com.djrapitops.plan.systems.webserver;
import com.djrapitops.plugin.api.Check;
import main.java.com.djrapitops.plan.api.IPlan;
import main.java.com.djrapitops.plan.api.exceptions.PlanEnableException;
import main.java.com.djrapitops.plan.systems.SubSystem;
import main.java.com.djrapitops.plan.systems.Systems;
/**
* //TODO Class Javadoc Comment
*
* @author Rsl1122
*/
public class WebServerSystem implements SubSystem {
private WebServer webServer;
public WebServerSystem(IPlan plugin) {
webServer = new WebServer(plugin);
}
public static WebServerSystem getInstance() {
return Systems.getInstance().getWebServerSystem();
}
@Override
public void init() throws PlanEnableException {
webServer.initServer();
if (Check.isBungeeAvailable() && !webServer.isEnabled()) {
throw new PlanEnableException("WebServer did not initialize!");
}
}
@Override
public void close() {
webServer.stop();
}
public static boolean isWebServerEnabled() {
return getInstance().webServer.isEnabled();
}
public WebServer getWebServer() {
return webServer;
}
}