Removed all getInstance method calls related to InfoSystem.

This commit is contained in:
Rsl1122 2018-08-29 10:13:37 +03:00
parent ff02eefb20
commit c0f1dfc8c5
27 changed files with 191 additions and 208 deletions

View File

@ -97,7 +97,11 @@ public class PlanBungee extends BungeePlugin implements PlanPlugin {
locale = system.getLocaleSystem().getLocale(); locale = system.getLocaleSystem().getLocale();
system.enable(); system.enable();
new BStatsBungee(this).registerMetrics(); new BStatsBungee(
this,
system.getDatabaseSystem().getActiveDatabase(),
system.getInfoSystem().getConnectionSystem()
).registerMetrics();
logger.info(locale.getString(PluginLang.ENABLED)); logger.info(locale.getString(PluginLang.ENABLED));
} catch (AbstractMethodError e) { } catch (AbstractMethodError e) {

View File

@ -120,7 +120,10 @@ public class PlanSponge extends SpongePlugin implements PlanPlugin {
locale = system.getLocaleSystem().getLocale(); locale = system.getLocaleSystem().getLocale();
system.enable(); system.enable();
new BStatsSponge(metrics).registerMetrics(); new BStatsSponge(
metrics,
system.getDatabaseSystem().getActiveDatabase()
).registerMetrics();
logger.info(locale.getString(PluginLang.ENABLED)); logger.info(locale.getString(PluginLang.ENABLED));
} catch (AbstractMethodError e) { } catch (AbstractMethodError e) {

View File

@ -2,6 +2,7 @@ package com.djrapitops.plan.command.commands;
import com.djrapitops.plan.api.exceptions.database.DBOpException; import com.djrapitops.plan.api.exceptions.database.DBOpException;
import com.djrapitops.plan.system.database.databases.Database; import com.djrapitops.plan.system.database.databases.Database;
import com.djrapitops.plan.system.info.connection.ConnectionSystem;
import com.djrapitops.plan.system.locale.Locale; import com.djrapitops.plan.system.locale.Locale;
import com.djrapitops.plan.system.locale.lang.CmdHelpLang; import com.djrapitops.plan.system.locale.lang.CmdHelpLang;
import com.djrapitops.plan.system.locale.lang.CommandLang; import com.djrapitops.plan.system.locale.lang.CommandLang;
@ -33,7 +34,8 @@ public class InspectCommand extends CommandNode {
private final Locale locale; private final Locale locale;
private final Database database; private final Database database;
private final WebServer webServer; private final WebServer webServer;
private UUIDUtility uuidUtility; private final ConnectionSystem connectionSystem;
private final UUIDUtility uuidUtility;
private final ErrorHandler errorHandler; private final ErrorHandler errorHandler;
@Inject @Inject
@ -41,10 +43,12 @@ public class InspectCommand extends CommandNode {
Locale locale, Locale locale,
Database database, Database database,
WebServer webServer, WebServer webServer,
ConnectionSystem connectionSystem,
UUIDUtility uuidUtility, UUIDUtility uuidUtility,
ErrorHandler errorHandler ErrorHandler errorHandler
) { ) {
super("inspect", Permissions.INSPECT.getPermission(), CommandType.PLAYER_OR_ARGS); super("inspect", Permissions.INSPECT.getPermission(), CommandType.PLAYER_OR_ARGS);
this.connectionSystem = connectionSystem;
setArguments("<player>"); setArguments("<player>");
this.locale = locale; this.locale = locale;
@ -83,7 +87,7 @@ public class InspectCommand extends CommandNode {
} }
checkWebUserAndNotify(sender); checkWebUserAndNotify(sender);
Processing.submit(new InspectCacheRequestProcessor(uuid, sender, playerName, locale)); Processing.submit(new InspectCacheRequestProcessor(uuid, sender, playerName, this::sendInspectMsg));
} catch (DBOpException e) { } catch (DBOpException e) {
sender.sendMessage("§eDatabase exception occurred: " + e.getMessage()); sender.sendMessage("§eDatabase exception occurred: " + e.getMessage());
errorHandler.log(L.ERROR, this.getClass(), e); errorHandler.log(L.ERROR, this.getClass(), e);
@ -100,4 +104,21 @@ public class InspectCommand extends CommandNode {
} }
} }
} }
private void sendInspectMsg(ISender sender, String playerName) {
sender.sendMessage(locale.getString(CommandLang.HEADER_INSPECT, playerName));
String url = connectionSystem.getMainAddress() + "/player/" + playerName;
String linkPrefix = locale.getString(CommandLang.LINK_PREFIX);
boolean console = !CommandUtils.isPlayer(sender);
if (console) {
sender.sendMessage(linkPrefix + url);
} else {
sender.sendMessage(linkPrefix);
sender.sendLink(" ", locale.getString(CommandLang.LINK_CLICK_ME), url);
}
sender.sendMessage(">");
}
} }

View File

@ -0,0 +1,11 @@
package com.djrapitops.plan.system;
/**
* Identifiers for different Debug channels.
*
* @author Rsl1122
*/
public class DebugChannels {
public static final String INFO_REQUESTS = "InfoRequests";
public static final String CONNECTIONS = "Connections";
}

View File

@ -13,10 +13,12 @@ import com.djrapitops.plan.system.info.request.GenerateInspectPageRequest;
import com.djrapitops.plan.system.info.request.InfoRequest; import com.djrapitops.plan.system.info.request.InfoRequest;
import com.djrapitops.plan.system.info.request.InfoRequestFactory; import com.djrapitops.plan.system.info.request.InfoRequestFactory;
import com.djrapitops.plan.system.info.server.ServerInfo; import com.djrapitops.plan.system.info.server.ServerInfo;
import com.djrapitops.plan.system.webserver.WebServer;
import com.djrapitops.plan.system.webserver.cache.PageId; import com.djrapitops.plan.system.webserver.cache.PageId;
import com.djrapitops.plan.system.webserver.cache.ResponseCache; import com.djrapitops.plan.system.webserver.cache.ResponseCache;
import com.djrapitops.plan.system.webserver.response.errors.InternalErrorResponse; import com.djrapitops.plan.system.webserver.response.errors.InternalErrorResponse;
import com.djrapitops.plan.system.webserver.response.pages.NetworkPageResponse; import com.djrapitops.plan.system.webserver.response.pages.NetworkPageResponse;
import com.djrapitops.plugin.logging.console.PluginLogger;
import javax.inject.Inject; import javax.inject.Inject;
import javax.inject.Singleton; import javax.inject.Singleton;
@ -32,16 +34,22 @@ public class BungeeInfoSystem extends InfoSystem {
private final ServerInfo serverInfo; private final ServerInfo serverInfo;
@Inject @Inject
public BungeeInfoSystem(InfoRequestFactory infoRequestFactory, ConnectionSystem connectionSystem, ServerInfo serverInfo) { public BungeeInfoSystem(
super(infoRequestFactory, connectionSystem); InfoRequestFactory infoRequestFactory,
ConnectionSystem connectionSystem,
ServerInfo serverInfo,
WebServer webServer,
PluginLogger logger
) {
super(infoRequestFactory, connectionSystem, serverInfo, webServer, logger);
this.serverInfo = serverInfo; this.serverInfo = serverInfo;
} }
@Override @Override
public void runLocally(InfoRequest infoRequest) throws WebException { public void runLocally(InfoRequest infoRequest) throws WebException {
if (infoRequest instanceof CacheRequest || if (infoRequest instanceof CacheRequest
infoRequest instanceof GenerateInspectPageRequest) { || infoRequest instanceof GenerateInspectPageRequest) {
infoRequest.runLocally(); infoRequest.runLocally();
} else { } else {
// runLocally is called when ConnectionSystem has no servers. // runLocally is called when ConnectionSystem has no servers.

View File

@ -9,7 +9,7 @@ import com.djrapitops.plan.api.exceptions.connection.BadRequestException;
import com.djrapitops.plan.api.exceptions.connection.ConnectionFailException; import com.djrapitops.plan.api.exceptions.connection.ConnectionFailException;
import com.djrapitops.plan.api.exceptions.connection.NoServersException; import com.djrapitops.plan.api.exceptions.connection.NoServersException;
import com.djrapitops.plan.api.exceptions.connection.WebException; import com.djrapitops.plan.api.exceptions.connection.WebException;
import com.djrapitops.plan.system.PlanSystem; import com.djrapitops.plan.system.DebugChannels;
import com.djrapitops.plan.system.SubSystem; import com.djrapitops.plan.system.SubSystem;
import com.djrapitops.plan.system.info.connection.ConnectionSystem; import com.djrapitops.plan.system.info.connection.ConnectionSystem;
import com.djrapitops.plan.system.info.request.GenerateRequest; import com.djrapitops.plan.system.info.request.GenerateRequest;
@ -17,10 +17,9 @@ import com.djrapitops.plan.system.info.request.InfoRequest;
import com.djrapitops.plan.system.info.request.InfoRequestFactory; import com.djrapitops.plan.system.info.request.InfoRequestFactory;
import com.djrapitops.plan.system.info.server.Server; import com.djrapitops.plan.system.info.server.Server;
import com.djrapitops.plan.system.info.server.ServerInfo; import com.djrapitops.plan.system.info.server.ServerInfo;
import com.djrapitops.plan.system.webserver.WebServerSystem; import com.djrapitops.plan.system.webserver.WebServer;
import com.djrapitops.plugin.api.Check; import com.djrapitops.plugin.api.Check;
import com.djrapitops.plugin.api.utility.log.Log; import com.djrapitops.plugin.logging.console.PluginLogger;
import com.djrapitops.plugin.utilities.Verify;
import java.util.UUID; import java.util.UUID;
@ -37,17 +36,22 @@ public abstract class InfoSystem implements SubSystem {
protected final InfoRequestFactory infoRequestFactory; protected final InfoRequestFactory infoRequestFactory;
protected final ConnectionSystem connectionSystem; protected final ConnectionSystem connectionSystem;
protected final ServerInfo serverInfo;
protected final WebServer webServer;
protected final PluginLogger logger;
protected InfoSystem(InfoRequestFactory infoRequestFactory, ConnectionSystem connectionSystem) { protected InfoSystem(
InfoRequestFactory infoRequestFactory,
ConnectionSystem connectionSystem,
ServerInfo serverInfo,
WebServer webServer,
PluginLogger logger
) {
this.infoRequestFactory = infoRequestFactory; this.infoRequestFactory = infoRequestFactory;
this.connectionSystem = connectionSystem; this.connectionSystem = connectionSystem;
} this.serverInfo = serverInfo;
this.webServer = webServer;
@Deprecated this.logger = logger;
public static InfoSystem getInstance() {
InfoSystem infoSystem = PlanSystem.getInstance().getInfoSystem();
Verify.nullCheck(infoSystem, () -> new IllegalStateException("Info System was not initialized."));
return infoSystem;
} }
/** /**
@ -77,7 +81,7 @@ public abstract class InfoSystem implements SubSystem {
*/ */
public void generateAnalysisPage(UUID serverUUID) throws WebException { public void generateAnalysisPage(UUID serverUUID) throws WebException {
GenerateRequest request = infoRequestFactory.generateAnalysisPageRequest(serverUUID); GenerateRequest request = infoRequestFactory.generateAnalysisPageRequest(serverUUID);
if (ServerInfo.getServerUUID_Old().equals(serverUUID)) { if (serverInfo.getServerUUID().equals(serverUUID)) {
runLocally(request); runLocally(request);
} else { } else {
sendRequest(request); sendRequest(request);
@ -95,14 +99,14 @@ public abstract class InfoSystem implements SubSystem {
public void sendRequest(InfoRequest infoRequest) throws WebException { public void sendRequest(InfoRequest infoRequest) throws WebException {
try { try {
if (!connectionSystem.isServerAvailable()) { if (!connectionSystem.isServerAvailable()) {
Log.debug("Main server unavailable, running locally."); logger.debug(DebugChannels.INFO_REQUESTS, "Main server unavailable, running locally.");
runLocally(infoRequest); runLocally(infoRequest);
return; return;
} }
connectionSystem.sendInfoRequest(infoRequest); connectionSystem.sendInfoRequest(infoRequest);
} catch (WebException original) { } catch (WebException original) {
try { try {
Log.debug("Exception during request: " + original.toString() + ", running locally."); logger.debug(DebugChannels.INFO_REQUESTS, "Exception during request: " + original.toString() + ", running locally.");
runLocally(infoRequest); runLocally(infoRequest);
} catch (NoServersException e2) { } catch (NoServersException e2) {
throw original; throw original;
@ -156,7 +160,7 @@ public abstract class InfoSystem implements SubSystem {
throw new BadRequestException("Method not available on Bungee."); throw new BadRequestException("Method not available on Bungee.");
} }
Server bungee = new Server(-1, null, "Bungee", addressToRequestServer, -1); Server bungee = new Server(-1, null, "Bungee", addressToRequestServer, -1);
String addressOfThisServer = WebServerSystem.getInstance().getWebServer().getAccessAddress(); String addressOfThisServer = webServer.getAccessAddress();
connectionSystem.setSetupAllowed(true); connectionSystem.setSetupAllowed(true);
connectionSystem.sendInfoRequest(infoRequestFactory.sendDBSettingsRequest(addressOfThisServer), bungee); connectionSystem.sendInfoRequest(infoRequestFactory.sendDBSettingsRequest(addressOfThisServer), bungee);

View File

@ -11,6 +11,7 @@ import com.djrapitops.plan.system.info.request.InfoRequest;
import com.djrapitops.plan.system.info.request.InfoRequestFactory; import com.djrapitops.plan.system.info.request.InfoRequestFactory;
import com.djrapitops.plan.system.info.request.SetupRequest; import com.djrapitops.plan.system.info.request.SetupRequest;
import com.djrapitops.plan.system.info.server.ServerInfo; import com.djrapitops.plan.system.info.server.ServerInfo;
import com.djrapitops.plan.system.webserver.WebServer;
import com.djrapitops.plan.utilities.html.HtmlStructure; import com.djrapitops.plan.utilities.html.HtmlStructure;
import com.djrapitops.plugin.logging.console.PluginLogger; import com.djrapitops.plugin.logging.console.PluginLogger;
@ -33,9 +34,10 @@ public class ServerInfoSystem extends InfoSystem {
ConnectionSystem connectionSystem, ConnectionSystem connectionSystem,
ServerInfo serverInfo, ServerInfo serverInfo,
InfoRequestFactory infoRequestFactory, InfoRequestFactory infoRequestFactory,
WebServer webServer,
PluginLogger logger PluginLogger logger
) { ) {
super(infoRequestFactory, connectionSystem); super(infoRequestFactory, connectionSystem, serverInfo, webServer, logger);
this.serverInfo = serverInfo; this.serverInfo = serverInfo;
this.logger = logger; this.logger = logger;
} }

View File

@ -31,7 +31,8 @@ public class BungeeConnectionSystem extends ConnectionSystem {
private final Database database; private final Database database;
private final WebServer webServer; private final WebServer webServer;
private ErrorHandler errorHandler; private final ErrorHandler errorHandler;
private final WebExceptionLogger webExceptionLogger;
private long latestServerMapRefresh; private long latestServerMapRefresh;
@ -43,12 +44,14 @@ public class BungeeConnectionSystem extends ConnectionSystem {
InfoRequests infoRequests, InfoRequests infoRequests,
Lazy<InfoSystem> infoSystem, Lazy<InfoSystem> infoSystem,
ServerInfo serverInfo, ServerInfo serverInfo,
ErrorHandler errorHandler ErrorHandler errorHandler,
WebExceptionLogger webExceptionLogger
) { ) {
super(connectionLog, infoRequests, infoSystem, serverInfo); super(connectionLog, infoRequests, infoSystem, serverInfo);
this.database = database; this.database = database;
this.webServer = webServer; this.webServer = webServer;
this.errorHandler = errorHandler; this.errorHandler = errorHandler;
this.webExceptionLogger = webExceptionLogger;
latestServerMapRefresh = 0; latestServerMapRefresh = 0;
} }
@ -88,7 +91,7 @@ public class BungeeConnectionSystem extends ConnectionSystem {
throw new NoServersException("No Servers available to make wide-request: " + infoRequest.getClass().getSimpleName()); throw new NoServersException("No Servers available to make wide-request: " + infoRequest.getClass().getSimpleName());
} }
for (Server server : bukkitServers.values()) { for (Server server : bukkitServers.values()) {
WebExceptionLogger.logIfOccurs(this.getClass(), () -> sendInfoRequest(infoRequest, server)); webExceptionLogger.logIfOccurs(this.getClass(), () -> sendInfoRequest(infoRequest, server));
} }
} }

View File

@ -5,11 +5,13 @@
package com.djrapitops.plan.system.info.connection; package com.djrapitops.plan.system.info.connection;
import com.djrapitops.plan.data.store.objects.DateHolder; import com.djrapitops.plan.data.store.objects.DateHolder;
import com.djrapitops.plan.system.DebugChannels;
import com.djrapitops.plan.system.info.request.InfoRequest; import com.djrapitops.plan.system.info.request.InfoRequest;
import com.djrapitops.plan.system.info.server.Server; import com.djrapitops.plan.system.info.server.Server;
import com.djrapitops.plugin.logging.debug.DebugLogger; import com.djrapitops.plugin.logging.debug.DebugLogger;
import javax.inject.Inject; import javax.inject.Inject;
import javax.inject.Singleton;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.Objects; import java.util.Objects;
@ -19,6 +21,7 @@ import java.util.Objects;
* *
* @author Rsl1122 * @author Rsl1122
*/ */
@Singleton
public class ConnectionLog { public class ConnectionLog {
private final DebugLogger debugLogger; private final DebugLogger debugLogger;
@ -31,41 +34,16 @@ public class ConnectionLog {
log = new HashMap<>(); log = new HashMap<>();
} }
/**
* Get a map sorted by Addresses, then Requests and then Log entries.
*
* @return {@code Map<"In: "/"Out: "+Address, Map<InfoRequestClassname, ConnectionLog.Entry>>}
*/
@Deprecated
public static Map<String, Map<String, Entry>> getLogEntries_Old() {
return getInstance().getLogEntries();
}
@Deprecated
public static void logConnectionTo_Old(Server server, InfoRequest request, int responseCode) {
getInstance().logConnectionTo(server, request, responseCode);
}
@Deprecated
public static void logConnectionFrom_Old(String server, String requestTarget, int responseCode) {
getInstance().logConnectionFrom(server, requestTarget, responseCode);
}
@Deprecated
private static ConnectionLog getInstance() {
return ConnectionSystem.getInstance().getConnectionLog();
}
public void logConnectionTo(Server server, InfoRequest request, int responseCode) { public void logConnectionTo(Server server, InfoRequest request, int responseCode) {
String requestName = request.getClass().getSimpleName(); String requestName = request.getClass().getSimpleName();
String address = server.getWebAddress(); String address = server.getWebAddress();
logConnection(address, "Out: " + requestName, responseCode); logConnection(address, "Out: " + requestName, responseCode);
debugLogger.logOn("Connections", "ConnectionOut: " + requestName + " to " + address); debugLogger.logOn(DebugChannels.CONNECTIONS, "ConnectionOut: " + requestName + " to " + address);
} }
public void logConnectionFrom(String server, String requestTarget, int responseCode) { public void logConnectionFrom(String server, String requestTarget, int responseCode) {
logConnection(server, "In: " + requestTarget, responseCode); logConnection(server, "In: " + requestTarget, responseCode);
debugLogger.logOn("Connections", "ConnectionIn: " + requestTarget + " from " + server); debugLogger.logOn(DebugChannels.CONNECTIONS, "ConnectionIn: " + requestTarget + " from " + server);
} }
private void logConnection(String address, String infoRequestName, int responseCode) { private void logConnection(String address, String infoRequestName, int responseCode) {

View File

@ -12,7 +12,6 @@ import com.djrapitops.plan.system.info.request.InfoRequest;
import com.djrapitops.plan.system.info.request.WideRequest; import com.djrapitops.plan.system.info.request.WideRequest;
import com.djrapitops.plan.system.info.server.Server; import com.djrapitops.plan.system.info.server.Server;
import com.djrapitops.plan.system.info.server.ServerInfo; import com.djrapitops.plan.system.info.server.ServerInfo;
import com.djrapitops.plugin.utilities.Verify;
import dagger.Lazy; import dagger.Lazy;
import java.util.*; import java.util.*;
@ -48,13 +47,6 @@ public abstract class ConnectionSystem implements SubSystem {
this.dataRequests = dataRequests; this.dataRequests = dataRequests;
} }
@Deprecated
public static ConnectionSystem getInstance() {
ConnectionSystem connectionSystem = InfoSystem.getInstance().getConnectionSystem();
Verify.nullCheck(connectionSystem, () -> new IllegalStateException("Connection System was not initialized"));
return connectionSystem;
}
public InfoRequest getInfoRequest(String name) { public InfoRequest getInfoRequest(String name) {
return dataRequests.get(name.toLowerCase()); return dataRequests.get(name.toLowerCase());
} }

View File

@ -72,7 +72,7 @@ public class InfoRequestPageHandler implements PageHandler {
responseCode = getResponseCodeFor(e); responseCode = getResponseCodeFor(e);
throw e; throw e;
} finally { } finally {
ConnectionLog.logConnectionFrom_Old(request.getRemoteAddress(), request.getTarget(), responseCode); connectionSystem.getConnectionLog().logConnectionFrom(request.getRemoteAddress(), request.getTarget(), responseCode);
} }
} }

View File

@ -40,6 +40,7 @@ public class ServerConnectionSystem extends ConnectionSystem {
private final Database database; private final Database database;
private final WebServer webServer; private final WebServer webServer;
private final PluginLogger pluginLogger; private final PluginLogger pluginLogger;
private final WebExceptionLogger webExceptionLogger;
private long latestServerMapRefresh; private long latestServerMapRefresh;
@ -55,7 +56,8 @@ public class ServerConnectionSystem extends ConnectionSystem {
InfoRequests infoRequests, InfoRequests infoRequests,
Lazy<InfoSystem> infoSystem, Lazy<InfoSystem> infoSystem,
ServerInfo serverInfo, ServerInfo serverInfo,
PluginLogger pluginLogger PluginLogger pluginLogger,
WebExceptionLogger webExceptionLogger
) { ) {
super(connectionLog, infoRequests, infoSystem, serverInfo); super(connectionLog, infoRequests, infoSystem, serverInfo);
this.locale = locale; this.locale = locale;
@ -63,6 +65,7 @@ public class ServerConnectionSystem extends ConnectionSystem {
this.database = database; this.database = database;
this.webServer = webServer; this.webServer = webServer;
this.pluginLogger = pluginLogger; this.pluginLogger = pluginLogger;
this.webExceptionLogger = webExceptionLogger;
latestServerMapRefresh = 0; latestServerMapRefresh = 0;
} }
@ -105,7 +108,7 @@ public class ServerConnectionSystem extends ConnectionSystem {
throw new NoServersException("No Servers available to make wide-request: " + infoRequest.getClass().getSimpleName()); throw new NoServersException("No Servers available to make wide-request: " + infoRequest.getClass().getSimpleName());
} }
for (Server server : bukkitServers.values()) { for (Server server : bukkitServers.values()) {
WebExceptionLogger.logIfOccurs(this.getClass(), () -> { webExceptionLogger.logIfOccurs(this.getClass(), () -> {
try { try {
sendInfoRequest(infoRequest, server); sendInfoRequest(infoRequest, server);
} catch (ConnectionFailException ignored) { } catch (ConnectionFailException ignored) {

View File

@ -6,8 +6,12 @@ package com.djrapitops.plan.system.info.connection;
import com.djrapitops.plan.api.exceptions.connection.*; import com.djrapitops.plan.api.exceptions.connection.*;
import com.djrapitops.plan.utilities.java.ThrowingVoidFunction; import com.djrapitops.plan.utilities.java.ThrowingVoidFunction;
import com.djrapitops.plugin.api.utility.log.Log; import com.djrapitops.plugin.logging.L;
import com.djrapitops.plugin.logging.console.PluginLogger;
import com.djrapitops.plugin.logging.error.ErrorHandler;
import javax.inject.Inject;
import javax.inject.Singleton;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
@ -18,31 +22,45 @@ import java.util.Map;
* *
* @author Rsl1122 * @author Rsl1122
*/ */
@Singleton
public class WebExceptionLogger { public class WebExceptionLogger {
@Deprecated private final ConnectionLog connectionLog;
public static void logIfOccurs(Class c, ThrowingVoidFunction<WebException> function) { private final PluginLogger logger;
private final ErrorHandler errorHandler;
@Inject
public WebExceptionLogger(
ConnectionLog connectionLog,
PluginLogger logger,
ErrorHandler errorHandler
) {
this.connectionLog = connectionLog;
this.logger = logger;
this.errorHandler = errorHandler;
}
public void logIfOccurs(Class definingClass, ThrowingVoidFunction<WebException> function) {
try { try {
function.apply(); function.apply();
} catch (ConnectionFailException e) { } catch (ConnectionFailException e) {
if (shouldLog(e)) { if (shouldLog(e)) {
Log.debug(e.getMessage()); logger.debug(e.getMessage());
} }
} catch (UnsupportedTransferDatabaseException | UnauthorizedServerException } catch (UnsupportedTransferDatabaseException | UnauthorizedServerException
| NotFoundException | NoServersException e) { | NotFoundException | NoServersException e) {
Log.debug(e.getMessage()); logger.debug(e.getMessage());
} catch (WebException e) { } catch (WebException e) {
Log.toLog(c, e); errorHandler.log(L.WARN, definingClass, e);
} }
} }
@Deprecated private boolean shouldLog(ConnectionFailException e) {
private static boolean shouldLog(ConnectionFailException e) {
String address = getAddress(e); String address = getAddress(e);
if (address == null) { if (address == null) {
return true; return true;
} }
Map<String, Map<String, ConnectionLog.Entry>> logEntries = ConnectionLog.getLogEntries_Old(); Map<String, Map<String, ConnectionLog.Entry>> logEntries = connectionLog.getLogEntries();
Map<String, ConnectionLog.Entry> entries = logEntries.get("Out: " + address); Map<String, ConnectionLog.Entry> entries = logEntries.get("Out: " + address);
if (entries != null) { if (entries != null) {
List<ConnectionLog.Entry> connections = new ArrayList<>(entries.values()); List<ConnectionLog.Entry> connections = new ArrayList<>(entries.values());
@ -64,8 +82,4 @@ public class WebExceptionLogger {
} }
return null; return null;
} }
private WebExceptionLogger() {
// Static method class.
}
} }

View File

@ -7,14 +7,11 @@ package com.djrapitops.plan.system.processing.processors.info;
import com.djrapitops.plan.api.exceptions.connection.*; import com.djrapitops.plan.api.exceptions.connection.*;
import com.djrapitops.plan.system.cache.SessionCache; import com.djrapitops.plan.system.cache.SessionCache;
import com.djrapitops.plan.system.info.InfoSystem; import com.djrapitops.plan.system.info.InfoSystem;
import com.djrapitops.plan.system.info.connection.ConnectionSystem;
import com.djrapitops.plan.system.locale.Locale;
import com.djrapitops.plan.system.locale.lang.CommandLang;
import com.djrapitops.plugin.api.utility.log.Log; import com.djrapitops.plugin.api.utility.log.Log;
import com.djrapitops.plugin.command.CommandUtils;
import com.djrapitops.plugin.command.ISender; import com.djrapitops.plugin.command.ISender;
import java.util.UUID; import java.util.UUID;
import java.util.function.BiConsumer;
/** /**
* Sends a request to cache players inspect page to the ResponseCache on the appropriate WebServer. * Sends a request to cache players inspect page to the ResponseCache on the appropriate WebServer.
@ -26,21 +23,28 @@ public class InspectCacheRequestProcessor implements Runnable {
private final UUID uuid; private final UUID uuid;
private final ISender sender; private final ISender sender;
private final String playerName; private final String playerName;
private final Locale locale; private final BiConsumer<ISender, String> msgSender;
public InspectCacheRequestProcessor(UUID uuid, ISender sender, String playerName, Locale locale) { private InfoSystem infoSystem;
public InspectCacheRequestProcessor(
UUID uuid,
ISender sender,
String playerName,
BiConsumer<ISender, String> msgSender
) {
this.uuid = uuid; this.uuid = uuid;
this.sender = sender; this.sender = sender;
this.playerName = playerName; this.playerName = playerName;
this.locale = locale; this.msgSender = msgSender;
} }
@Override @Override
public void run() { public void run() {
SessionCache.refreshActiveSessionsState(); SessionCache.refreshActiveSessionsState();
try { try {
InfoSystem.getInstance().generateAndCachePlayerPage(uuid); infoSystem.generateAndCachePlayerPage(uuid);
sendInspectMsg(sender, playerName); msgSender.accept(sender, playerName);
} catch (ConnectionFailException | UnsupportedTransferDatabaseException | UnauthorizedServerException } catch (ConnectionFailException | UnsupportedTransferDatabaseException | UnauthorizedServerException
| NotFoundException | NoServersException e) { | NotFoundException | NoServersException e) {
sender.sendMessage("§c" + e.getMessage()); sender.sendMessage("§c" + e.getMessage());
@ -48,21 +52,4 @@ public class InspectCacheRequestProcessor implements Runnable {
Log.toLog(this.getClass(), e); Log.toLog(this.getClass(), e);
} }
} }
// TODO Move to InspectCommand somehow.
private void sendInspectMsg(ISender sender, String playerName) {
sender.sendMessage(locale.getString(CommandLang.HEADER_INSPECT, playerName));
// Link
String url = ConnectionSystem.getInstance().getMainAddress() + "/player/" + playerName;
String linkPrefix = locale.getString(CommandLang.LINK_PREFIX);
boolean console = !CommandUtils.isPlayer(sender);
if (console) {
sender.sendMessage(linkPrefix + url);
} else {
sender.sendMessage(linkPrefix);
sender.sendLink(" ", locale.getString(CommandLang.LINK_CLICK_ME), url);
}
sender.sendMessage(">");
}
} }

View File

@ -15,10 +15,12 @@ import com.djrapitops.plugin.api.utility.log.Log;
*/ */
public class NetworkPageUpdateProcessor implements Runnable { public class NetworkPageUpdateProcessor implements Runnable {
private InfoSystem infoSystem;
@Override @Override
public void run() { public void run() {
try { try {
InfoSystem.getInstance().updateNetworkPage(); infoSystem.updateNetworkPage();
} catch (WebException e) { } catch (WebException e) {
Log.toLog(this.getClass(), e); Log.toLog(this.getClass(), e);
} }

View File

@ -13,20 +13,23 @@ public class PlayerPageUpdateProcessor implements Runnable {
private final UUID uuid; private final UUID uuid;
private InfoSystem infoSystem;
private WebExceptionLogger webExceptionLogger;
public PlayerPageUpdateProcessor(UUID uuid) { public PlayerPageUpdateProcessor(UUID uuid) {
this.uuid = uuid; this.uuid = uuid;
} }
@Override @Override
public void run() { public void run() {
if (!InfoSystem.getInstance().getConnectionSystem().isServerAvailable() || Check.isBungeeAvailable()) { if (!infoSystem.getConnectionSystem().isServerAvailable() || Check.isBungeeAvailable()) {
RunnableFactory.createNew("Generate Inspect page: " + uuid, new AbsRunnable() { RunnableFactory.createNew("Generate Inspect page: " + uuid, new AbsRunnable() {
@Override @Override
public void run() { public void run() {
try { try {
WebExceptionLogger.logIfOccurs(PlayerPageUpdateProcessor.class, webExceptionLogger.logIfOccurs(PlayerPageUpdateProcessor.class,
() -> InfoSystem.getInstance().generateAndCachePlayerPage(uuid) () -> infoSystem.generateAndCachePlayerPage(uuid)
); );
} finally { } finally {
cancel(); cancel();

View File

@ -1,55 +0,0 @@
/*
* License is provided in the jar as LICENSE also here:
* https://github.com/Rsl1122/Plan-PlayerAnalytics/blob/master/Plan/src/main/resources/LICENSE
*/
package com.djrapitops.plan.system.settings;
import com.djrapitops.plan.system.webserver.WebServer;
import com.djrapitops.plan.system.webserver.WebServerSystem;
import com.djrapitops.plugin.api.Check;
import com.djrapitops.plugin.api.utility.log.ErrorLogger;
import com.djrapitops.plugin.api.utility.log.Log;
import com.djrapitops.plugin.api.utility.log.errormanager.ErrorManager;
import java.io.File;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
* Abstract Plugin Framework ErrorManager for logging Errors properly instead of a vague message.
*
* @author Rsl1122
*/
public class PlanErrorManager implements ErrorManager {
@Override
public void toLog(String source, Throwable e, Class callingPlugin) {
try {
File logsFolder = Log.getLogsFolder(callingPlugin);
Log.warn(source + " Caught: " + e, callingPlugin);
if (WebServerSystem.isWebServerEnabled()) {
Log.warn("Exception can be viewed at " + WebServer.getInstance().getAccessAddress() + "/debug");
} else {
Log.warn("It has been logged to ErrorLog.txt");
}
logGlobally(source, e);
ErrorLogger.logThrowable(e, logsFolder);
} catch (Exception exception) {
System.out.println("Failed to log error to file because of " + exception);
System.out.println("Error:");
// Fallback
System.out.println("Fail Reason:");
Logger.getGlobal().log(Level.WARNING, source, e);
}
}
private void logGlobally(String source, Throwable e) {
try {
if ((Check.isBukkitAvailable() && Check.isBungeeAvailable()) || Settings.DEV_MODE.isTrue()) {
Logger.getGlobal().log(Level.WARNING, source, e);
}
} catch (IllegalStateException ignored) {
/* Config system not initialized */
}
}
}

View File

@ -6,24 +6,29 @@ import com.djrapitops.plan.system.info.request.InfoRequestFactory;
import com.djrapitops.plugin.task.AbsRunnable; import com.djrapitops.plugin.task.AbsRunnable;
import javax.inject.Inject; import javax.inject.Inject;
import javax.inject.Singleton;
@Singleton
public class EnableConnectionTask extends AbsRunnable { public class EnableConnectionTask extends AbsRunnable {
private ConnectionSystem connectionSystem; private ConnectionSystem connectionSystem;
private final InfoRequestFactory infoRequestFactory; private final InfoRequestFactory infoRequestFactory;
private final WebExceptionLogger webExceptionLogger;
@Inject @Inject
public EnableConnectionTask( public EnableConnectionTask(
ConnectionSystem connectionSystem, ConnectionSystem connectionSystem,
InfoRequestFactory infoRequestFactory InfoRequestFactory infoRequestFactory,
WebExceptionLogger webExceptionLogger
) { ) {
this.connectionSystem = connectionSystem; this.connectionSystem = connectionSystem;
this.infoRequestFactory = infoRequestFactory; this.infoRequestFactory = infoRequestFactory;
this.webExceptionLogger = webExceptionLogger;
} }
@Override @Override
public void run() { public void run() {
WebExceptionLogger.logIfOccurs(this.getClass(), webExceptionLogger.logIfOccurs(this.getClass(),
() -> connectionSystem.sendWideInfoRequest(infoRequestFactory.generateNetworkPageContentRequest()) () -> connectionSystem.sendWideInfoRequest(infoRequestFactory.generateNetworkPageContentRequest())
); );
cancel(); cancel();

View File

@ -7,28 +7,33 @@ import com.djrapitops.plan.system.info.server.ServerInfo;
import com.djrapitops.plugin.task.AbsRunnable; import com.djrapitops.plugin.task.AbsRunnable;
import javax.inject.Inject; import javax.inject.Inject;
import javax.inject.Singleton;
@Singleton
public class BootAnalysisTask extends AbsRunnable { public class BootAnalysisTask extends AbsRunnable {
private final InfoSystem infoSystem; private final InfoSystem infoSystem;
private final InfoRequestFactory infoRequestFactory; private final InfoRequestFactory infoRequestFactory;
private final ServerInfo serverInfo; private final ServerInfo serverInfo;
private final WebExceptionLogger webExceptionLogger;
@Inject @Inject
public BootAnalysisTask( public BootAnalysisTask(
InfoSystem infoSystem, InfoSystem infoSystem,
InfoRequestFactory infoRequestFactory, InfoRequestFactory infoRequestFactory,
ServerInfo serverInfo ServerInfo serverInfo,
WebExceptionLogger webExceptionLogger
) { ) {
this.infoSystem = infoSystem; this.infoSystem = infoSystem;
this.infoRequestFactory = infoRequestFactory; this.infoRequestFactory = infoRequestFactory;
this.serverInfo = serverInfo; this.serverInfo = serverInfo;
this.webExceptionLogger = webExceptionLogger;
} }
@Override @Override
public void run() { public void run() {
try { try {
WebExceptionLogger.logIfOccurs(this.getClass(), () -> webExceptionLogger.logIfOccurs(this.getClass(), () ->
infoSystem.sendRequest(infoRequestFactory.generateAnalysisPageRequest(serverInfo.getServerUUID())) infoSystem.sendRequest(infoRequestFactory.generateAnalysisPageRequest(serverInfo.getServerUUID()))
); );
} catch (IllegalStateException ignore) { } catch (IllegalStateException ignore) {

View File

@ -5,18 +5,25 @@ import com.djrapitops.plan.system.info.connection.WebExceptionLogger;
import com.djrapitops.plugin.task.AbsRunnable; import com.djrapitops.plugin.task.AbsRunnable;
import javax.inject.Inject; import javax.inject.Inject;
import javax.inject.Singleton;
@Singleton
public class NetworkPageRefreshTask extends AbsRunnable { public class NetworkPageRefreshTask extends AbsRunnable {
private InfoSystem infoSystem; private InfoSystem infoSystem;
private final WebExceptionLogger webExceptionLogger;
@Inject @Inject
public NetworkPageRefreshTask(InfoSystem infoSystem) { public NetworkPageRefreshTask(
InfoSystem infoSystem,
WebExceptionLogger webExceptionLogger
) {
this.infoSystem = infoSystem; this.infoSystem = infoSystem;
this.webExceptionLogger = webExceptionLogger;
} }
@Override @Override
public void run() { public void run() {
WebExceptionLogger.logIfOccurs(this.getClass(), () -> infoSystem.updateNetworkPage()); webExceptionLogger.logIfOccurs(this.getClass(), () -> infoSystem.updateNetworkPage());
} }
} }

View File

@ -10,7 +10,9 @@ import com.djrapitops.plugin.logging.error.ErrorHandler;
import com.djrapitops.plugin.task.AbsRunnable; import com.djrapitops.plugin.task.AbsRunnable;
import javax.inject.Inject; import javax.inject.Inject;
import javax.inject.Singleton;
@Singleton
public class PeriodicAnalysisTask extends AbsRunnable { public class PeriodicAnalysisTask extends AbsRunnable {
private final InfoSystem infoSystem; private final InfoSystem infoSystem;
@ -18,25 +20,28 @@ public class PeriodicAnalysisTask extends AbsRunnable {
private final ServerInfo serverInfo; private final ServerInfo serverInfo;
private final PluginLogger logger; private final PluginLogger logger;
private final ErrorHandler errorHandler; private final ErrorHandler errorHandler;
private final WebExceptionLogger webExceptionLogger;
@Inject @Inject
public PeriodicAnalysisTask( public PeriodicAnalysisTask(
InfoSystem infoSystem, InfoSystem infoSystem,
InfoRequestFactory infoRequestFactory, ServerInfo serverInfo, InfoRequestFactory infoRequestFactory, ServerInfo serverInfo,
PluginLogger logger, PluginLogger logger,
ErrorHandler errorHandler ErrorHandler errorHandler,
WebExceptionLogger webExceptionLogger
) { ) {
this.infoSystem = infoSystem; this.infoSystem = infoSystem;
this.infoRequestFactory = infoRequestFactory; this.infoRequestFactory = infoRequestFactory;
this.serverInfo = serverInfo; this.serverInfo = serverInfo;
this.logger = logger; this.logger = logger;
this.errorHandler = errorHandler; this.errorHandler = errorHandler;
this.webExceptionLogger = webExceptionLogger;
} }
@Override @Override
public void run() { public void run() {
try { try {
WebExceptionLogger.logIfOccurs(this.getClass(), () -> webExceptionLogger.logIfOccurs(this.getClass(), () ->
infoSystem.sendRequest(infoRequestFactory.generateAnalysisPageRequest(serverInfo.getServerUUID())) infoSystem.sendRequest(infoRequestFactory.generateAnalysisPageRequest(serverInfo.getServerUUID()))
); );
} catch (IllegalStateException ignore) { } catch (IllegalStateException ignore) {

View File

@ -12,7 +12,6 @@ import com.djrapitops.plugin.api.Check;
import com.djrapitops.plugin.logging.L; import com.djrapitops.plugin.logging.L;
import com.djrapitops.plugin.logging.console.PluginLogger; import com.djrapitops.plugin.logging.console.PluginLogger;
import com.djrapitops.plugin.logging.error.ErrorHandler; import com.djrapitops.plugin.logging.error.ErrorHandler;
import com.djrapitops.plugin.utilities.Verify;
import com.sun.net.httpserver.HttpServer; import com.sun.net.httpserver.HttpServer;
import com.sun.net.httpserver.HttpsConfigurator; import com.sun.net.httpserver.HttpsConfigurator;
import com.sun.net.httpserver.HttpsParameters; import com.sun.net.httpserver.HttpsParameters;
@ -75,13 +74,6 @@ public class WebServer implements SubSystem {
this.errorHandler = errorHandler; this.errorHandler = errorHandler;
} }
@Deprecated
public static WebServer getInstance() {
WebServer webServer = WebServerSystem.getInstance().getWebServer();
Verify.nullCheck(webServer, () -> new IllegalStateException("WebServer was not initialized."));
return webServer;
}
@Override @Override
public void enable() throws EnableException { public void enable() throws EnableException {
this.port = config.getNumber(Settings.WEBSERVER_PORT); this.port = config.getNumber(Settings.WEBSERVER_PORT);

View File

@ -5,18 +5,19 @@
package com.djrapitops.plan.system.webserver; package com.djrapitops.plan.system.webserver;
import com.djrapitops.plan.api.exceptions.EnableException; import com.djrapitops.plan.api.exceptions.EnableException;
import com.djrapitops.plan.system.PlanSystem;
import com.djrapitops.plan.system.SubSystem; import com.djrapitops.plan.system.SubSystem;
import com.djrapitops.plan.system.webserver.cache.ResponseCache; import com.djrapitops.plan.system.webserver.cache.ResponseCache;
import com.djrapitops.plugin.benchmarking.Timings; import com.djrapitops.plugin.benchmarking.Timings;
import javax.inject.Inject; import javax.inject.Inject;
import javax.inject.Singleton;
/** /**
* WebServer subsystem for managing WebServer initialization. * WebServer subsystem for managing WebServer initialization.
* *
* @author Rsl1122 * @author Rsl1122
*/ */
@Singleton
public class WebServerSystem implements SubSystem { public class WebServerSystem implements SubSystem {
private final WebServer webServer; private final WebServer webServer;
@ -28,17 +29,6 @@ public class WebServerSystem implements SubSystem {
this.timings = timings; this.timings = timings;
} }
@Deprecated
public static WebServerSystem getInstance() {
return PlanSystem.getInstance().getWebServerSystem();
}
@Deprecated
public static boolean isWebServerEnabled() {
WebServer webServer = getInstance().webServer;
return webServer != null && webServer.isEnabled();
}
@Override @Override
public void enable() throws EnableException { public void enable() throws EnableException {
timings.start("WebServer Initialization"); timings.start("WebServer Initialization");

View File

@ -72,7 +72,7 @@ public class ServerPageHandler implements PageHandler {
} }
return ResponseCache.loadResponse(PageId.SERVER.of(serverUUID)); return ResponseCache.loadResponse(PageId.SERVER.of(serverUUID));
} }
return AnalysisPageResponse.refreshNow(serverUUID); return AnalysisPageResponse.refreshNow(serverUUID, infoSystem);
} }
} }

View File

@ -21,10 +21,10 @@ import java.util.UUID;
public class AnalysisPageResponse extends Response { public class AnalysisPageResponse extends Response {
@Deprecated @Deprecated
public static AnalysisPageResponse refreshNow(UUID serverUUID) { public static AnalysisPageResponse refreshNow(UUID serverUUID, InfoSystem infoSystem) {
Processing.submitNonCritical(() -> { Processing.submitNonCritical(() -> {
try { try {
InfoSystem.getInstance().generateAnalysisPage(serverUUID); infoSystem.generateAnalysisPage(serverUUID);
} catch (NoServersException | ConnectionFailException e) { } catch (NoServersException | ConnectionFailException e) {
ResponseCache.cacheResponse(PageId.SERVER.of(serverUUID), () -> new NotFoundResponse(e.getMessage())); ResponseCache.cacheResponse(PageId.SERVER.of(serverUUID), () -> new NotFoundResponse(e.getMessage()));
} catch (WebException e) { } catch (WebException e) {

View File

@ -3,7 +3,6 @@ package com.djrapitops.plan.utilities.metrics;
import com.djrapitops.plan.PlanBungee; import com.djrapitops.plan.PlanBungee;
import com.djrapitops.plan.system.database.databases.Database; import com.djrapitops.plan.system.database.databases.Database;
import com.djrapitops.plan.system.info.connection.ConnectionSystem; import com.djrapitops.plan.system.info.connection.ConnectionSystem;
import com.djrapitops.plugin.api.utility.log.Log;
import org.bstats.bungeecord.Metrics; import org.bstats.bungeecord.Metrics;
import java.io.Serializable; import java.io.Serializable;
@ -11,14 +10,18 @@ import java.io.Serializable;
public class BStatsBungee { public class BStatsBungee {
private final PlanBungee plugin; private final PlanBungee plugin;
private final Database database;
private final ConnectionSystem connectionSystem;
private Metrics metrics; private Metrics metrics;
public BStatsBungee(PlanBungee plugin) { public BStatsBungee(PlanBungee plugin, Database database, ConnectionSystem connectionSystem) {
this.plugin = plugin; this.plugin = plugin;
this.database = database;
this.connectionSystem = connectionSystem;
} }
public void registerMetrics() { public void registerMetrics() {
Log.logDebug("Enable", "Enabling bStats Metrics.");
if (metrics == null) { if (metrics == null) {
metrics = new Metrics(plugin); metrics = new Metrics(plugin);
} }
@ -27,11 +30,11 @@ public class BStatsBungee {
private void registerConfigSettingGraphs() { private void registerConfigSettingGraphs() {
String serverType = plugin.getProxy().getName(); String serverType = plugin.getProxy().getName();
String databaseType = Database.getActive().getName(); String databaseType = database.getName();
addStringSettingPie("server_type", serverType); addStringSettingPie("server_type", serverType);
addStringSettingPie("database_type", databaseType); addStringSettingPie("database_type", databaseType);
addStringSettingPie("network_servers", ConnectionSystem.getInstance().getBukkitServers().size()); addStringSettingPie("network_servers", connectionSystem.getBukkitServers().size());
} }
protected void addStringSettingPie(String id, Serializable setting) { protected void addStringSettingPie(String id, Serializable setting) {

View File

@ -1,8 +1,6 @@
package com.djrapitops.plan.utilities.metrics; package com.djrapitops.plan.utilities.metrics;
import com.djrapitops.plan.system.database.databases.Database; import com.djrapitops.plan.system.database.databases.Database;
import com.djrapitops.plan.system.info.connection.ConnectionSystem;
import com.djrapitops.plugin.api.utility.log.Log;
import org.bstats.sponge.Metrics; import org.bstats.sponge.Metrics;
import java.io.Serializable; import java.io.Serializable;
@ -10,27 +8,25 @@ import java.io.Serializable;
public class BStatsSponge { public class BStatsSponge {
private final Metrics metrics; private final Metrics metrics;
private final Database database;
public BStatsSponge(Metrics metrics) { public BStatsSponge(Metrics metrics, Database database) {
this.metrics = metrics; this.metrics = metrics;
this.database = database;
} }
public void registerMetrics() { public void registerMetrics() {
Log.logDebug("Enable", "Enabling bStats Metrics.");
if (metrics != null) { if (metrics != null) {
registerConfigSettingGraphs(); registerConfigSettingGraphs();
} else {
Log.debug("Metrics not injected properly.");
} }
} }
private void registerConfigSettingGraphs() { private void registerConfigSettingGraphs() {
String serverType = "Sponge"; String serverType = "Sponge";
String databaseType = Database.getActive().getName(); String databaseType = database.getName();
addStringSettingPie("server_type", serverType); addStringSettingPie("server_type", serverType);
addStringSettingPie("database_type", databaseType); addStringSettingPie("database_type", databaseType);
addStringSettingPie("network_servers", ConnectionSystem.getInstance().getBukkitServers().size());
} }
protected void addStringSettingPie(String id, Serializable setting) { protected void addStringSettingPie(String id, Serializable setting) {