mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2024-09-06 03:38:06 +02:00
Removed all getInstance method calls related to InfoSystem.
This commit is contained in:
parent
ff02eefb20
commit
c0f1dfc8c5
@ -97,7 +97,11 @@ public class PlanBungee extends BungeePlugin implements PlanPlugin {
|
||||
locale = system.getLocaleSystem().getLocale();
|
||||
system.enable();
|
||||
|
||||
new BStatsBungee(this).registerMetrics();
|
||||
new BStatsBungee(
|
||||
this,
|
||||
system.getDatabaseSystem().getActiveDatabase(),
|
||||
system.getInfoSystem().getConnectionSystem()
|
||||
).registerMetrics();
|
||||
|
||||
logger.info(locale.getString(PluginLang.ENABLED));
|
||||
} catch (AbstractMethodError e) {
|
||||
|
@ -120,7 +120,10 @@ public class PlanSponge extends SpongePlugin implements PlanPlugin {
|
||||
locale = system.getLocaleSystem().getLocale();
|
||||
system.enable();
|
||||
|
||||
new BStatsSponge(metrics).registerMetrics();
|
||||
new BStatsSponge(
|
||||
metrics,
|
||||
system.getDatabaseSystem().getActiveDatabase()
|
||||
).registerMetrics();
|
||||
|
||||
logger.info(locale.getString(PluginLang.ENABLED));
|
||||
} catch (AbstractMethodError e) {
|
||||
|
@ -2,6 +2,7 @@ package com.djrapitops.plan.command.commands;
|
||||
|
||||
import com.djrapitops.plan.api.exceptions.database.DBOpException;
|
||||
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.lang.CmdHelpLang;
|
||||
import com.djrapitops.plan.system.locale.lang.CommandLang;
|
||||
@ -33,7 +34,8 @@ public class InspectCommand extends CommandNode {
|
||||
private final Locale locale;
|
||||
private final Database database;
|
||||
private final WebServer webServer;
|
||||
private UUIDUtility uuidUtility;
|
||||
private final ConnectionSystem connectionSystem;
|
||||
private final UUIDUtility uuidUtility;
|
||||
private final ErrorHandler errorHandler;
|
||||
|
||||
@Inject
|
||||
@ -41,10 +43,12 @@ public class InspectCommand extends CommandNode {
|
||||
Locale locale,
|
||||
Database database,
|
||||
WebServer webServer,
|
||||
ConnectionSystem connectionSystem,
|
||||
UUIDUtility uuidUtility,
|
||||
ErrorHandler errorHandler
|
||||
) {
|
||||
super("inspect", Permissions.INSPECT.getPermission(), CommandType.PLAYER_OR_ARGS);
|
||||
this.connectionSystem = connectionSystem;
|
||||
setArguments("<player>");
|
||||
|
||||
this.locale = locale;
|
||||
@ -83,7 +87,7 @@ public class InspectCommand extends CommandNode {
|
||||
}
|
||||
|
||||
checkWebUserAndNotify(sender);
|
||||
Processing.submit(new InspectCacheRequestProcessor(uuid, sender, playerName, locale));
|
||||
Processing.submit(new InspectCacheRequestProcessor(uuid, sender, playerName, this::sendInspectMsg));
|
||||
} catch (DBOpException e) {
|
||||
sender.sendMessage("§eDatabase exception occurred: " + e.getMessage());
|
||||
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(">");
|
||||
}
|
||||
}
|
@ -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";
|
||||
}
|
@ -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.InfoRequestFactory;
|
||||
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.ResponseCache;
|
||||
import com.djrapitops.plan.system.webserver.response.errors.InternalErrorResponse;
|
||||
import com.djrapitops.plan.system.webserver.response.pages.NetworkPageResponse;
|
||||
import com.djrapitops.plugin.logging.console.PluginLogger;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
@ -32,16 +34,22 @@ public class BungeeInfoSystem extends InfoSystem {
|
||||
private final ServerInfo serverInfo;
|
||||
|
||||
@Inject
|
||||
public BungeeInfoSystem(InfoRequestFactory infoRequestFactory, ConnectionSystem connectionSystem, ServerInfo serverInfo) {
|
||||
super(infoRequestFactory, connectionSystem);
|
||||
public BungeeInfoSystem(
|
||||
InfoRequestFactory infoRequestFactory,
|
||||
ConnectionSystem connectionSystem,
|
||||
ServerInfo serverInfo,
|
||||
WebServer webServer,
|
||||
PluginLogger logger
|
||||
) {
|
||||
super(infoRequestFactory, connectionSystem, serverInfo, webServer, logger);
|
||||
|
||||
this.serverInfo = serverInfo;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void runLocally(InfoRequest infoRequest) throws WebException {
|
||||
if (infoRequest instanceof CacheRequest ||
|
||||
infoRequest instanceof GenerateInspectPageRequest) {
|
||||
if (infoRequest instanceof CacheRequest
|
||||
|| infoRequest instanceof GenerateInspectPageRequest) {
|
||||
infoRequest.runLocally();
|
||||
} else {
|
||||
// runLocally is called when ConnectionSystem has no servers.
|
||||
|
@ -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.NoServersException;
|
||||
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.info.connection.ConnectionSystem;
|
||||
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.server.Server;
|
||||
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.utility.log.Log;
|
||||
import com.djrapitops.plugin.utilities.Verify;
|
||||
import com.djrapitops.plugin.logging.console.PluginLogger;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
@ -37,17 +36,22 @@ public abstract class InfoSystem implements SubSystem {
|
||||
|
||||
protected final InfoRequestFactory infoRequestFactory;
|
||||
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.connectionSystem = connectionSystem;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public static InfoSystem getInstance() {
|
||||
InfoSystem infoSystem = PlanSystem.getInstance().getInfoSystem();
|
||||
Verify.nullCheck(infoSystem, () -> new IllegalStateException("Info System was not initialized."));
|
||||
return infoSystem;
|
||||
this.serverInfo = serverInfo;
|
||||
this.webServer = webServer;
|
||||
this.logger = logger;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -77,7 +81,7 @@ public abstract class InfoSystem implements SubSystem {
|
||||
*/
|
||||
public void generateAnalysisPage(UUID serverUUID) throws WebException {
|
||||
GenerateRequest request = infoRequestFactory.generateAnalysisPageRequest(serverUUID);
|
||||
if (ServerInfo.getServerUUID_Old().equals(serverUUID)) {
|
||||
if (serverInfo.getServerUUID().equals(serverUUID)) {
|
||||
runLocally(request);
|
||||
} else {
|
||||
sendRequest(request);
|
||||
@ -95,14 +99,14 @@ public abstract class InfoSystem implements SubSystem {
|
||||
public void sendRequest(InfoRequest infoRequest) throws WebException {
|
||||
try {
|
||||
if (!connectionSystem.isServerAvailable()) {
|
||||
Log.debug("Main server unavailable, running locally.");
|
||||
logger.debug(DebugChannels.INFO_REQUESTS, "Main server unavailable, running locally.");
|
||||
runLocally(infoRequest);
|
||||
return;
|
||||
}
|
||||
connectionSystem.sendInfoRequest(infoRequest);
|
||||
} catch (WebException original) {
|
||||
try {
|
||||
Log.debug("Exception during request: " + original.toString() + ", running locally.");
|
||||
logger.debug(DebugChannels.INFO_REQUESTS, "Exception during request: " + original.toString() + ", running locally.");
|
||||
runLocally(infoRequest);
|
||||
} catch (NoServersException e2) {
|
||||
throw original;
|
||||
@ -156,7 +160,7 @@ public abstract class InfoSystem implements SubSystem {
|
||||
throw new BadRequestException("Method not available on Bungee.");
|
||||
}
|
||||
Server bungee = new Server(-1, null, "Bungee", addressToRequestServer, -1);
|
||||
String addressOfThisServer = WebServerSystem.getInstance().getWebServer().getAccessAddress();
|
||||
String addressOfThisServer = webServer.getAccessAddress();
|
||||
|
||||
connectionSystem.setSetupAllowed(true);
|
||||
connectionSystem.sendInfoRequest(infoRequestFactory.sendDBSettingsRequest(addressOfThisServer), bungee);
|
||||
|
@ -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.SetupRequest;
|
||||
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.plugin.logging.console.PluginLogger;
|
||||
|
||||
@ -33,9 +34,10 @@ public class ServerInfoSystem extends InfoSystem {
|
||||
ConnectionSystem connectionSystem,
|
||||
ServerInfo serverInfo,
|
||||
InfoRequestFactory infoRequestFactory,
|
||||
WebServer webServer,
|
||||
PluginLogger logger
|
||||
) {
|
||||
super(infoRequestFactory, connectionSystem);
|
||||
super(infoRequestFactory, connectionSystem, serverInfo, webServer, logger);
|
||||
this.serverInfo = serverInfo;
|
||||
this.logger = logger;
|
||||
}
|
||||
|
@ -31,7 +31,8 @@ public class BungeeConnectionSystem extends ConnectionSystem {
|
||||
|
||||
private final Database database;
|
||||
private final WebServer webServer;
|
||||
private ErrorHandler errorHandler;
|
||||
private final ErrorHandler errorHandler;
|
||||
private final WebExceptionLogger webExceptionLogger;
|
||||
|
||||
private long latestServerMapRefresh;
|
||||
|
||||
@ -43,12 +44,14 @@ public class BungeeConnectionSystem extends ConnectionSystem {
|
||||
InfoRequests infoRequests,
|
||||
Lazy<InfoSystem> infoSystem,
|
||||
ServerInfo serverInfo,
|
||||
ErrorHandler errorHandler
|
||||
ErrorHandler errorHandler,
|
||||
WebExceptionLogger webExceptionLogger
|
||||
) {
|
||||
super(connectionLog, infoRequests, infoSystem, serverInfo);
|
||||
this.database = database;
|
||||
this.webServer = webServer;
|
||||
this.errorHandler = errorHandler;
|
||||
this.webExceptionLogger = webExceptionLogger;
|
||||
|
||||
latestServerMapRefresh = 0;
|
||||
}
|
||||
@ -88,7 +91,7 @@ public class BungeeConnectionSystem extends ConnectionSystem {
|
||||
throw new NoServersException("No Servers available to make wide-request: " + infoRequest.getClass().getSimpleName());
|
||||
}
|
||||
for (Server server : bukkitServers.values()) {
|
||||
WebExceptionLogger.logIfOccurs(this.getClass(), () -> sendInfoRequest(infoRequest, server));
|
||||
webExceptionLogger.logIfOccurs(this.getClass(), () -> sendInfoRequest(infoRequest, server));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -5,11 +5,13 @@
|
||||
package com.djrapitops.plan.system.info.connection;
|
||||
|
||||
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.server.Server;
|
||||
import com.djrapitops.plugin.logging.debug.DebugLogger;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
@ -19,6 +21,7 @@ import java.util.Objects;
|
||||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
@Singleton
|
||||
public class ConnectionLog {
|
||||
|
||||
private final DebugLogger debugLogger;
|
||||
@ -31,41 +34,16 @@ public class ConnectionLog {
|
||||
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) {
|
||||
String requestName = request.getClass().getSimpleName();
|
||||
String address = server.getWebAddress();
|
||||
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) {
|
||||
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) {
|
||||
|
@ -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.server.Server;
|
||||
import com.djrapitops.plan.system.info.server.ServerInfo;
|
||||
import com.djrapitops.plugin.utilities.Verify;
|
||||
import dagger.Lazy;
|
||||
|
||||
import java.util.*;
|
||||
@ -48,13 +47,6 @@ public abstract class ConnectionSystem implements SubSystem {
|
||||
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) {
|
||||
return dataRequests.get(name.toLowerCase());
|
||||
}
|
||||
|
@ -72,7 +72,7 @@ public class InfoRequestPageHandler implements PageHandler {
|
||||
responseCode = getResponseCodeFor(e);
|
||||
throw e;
|
||||
} finally {
|
||||
ConnectionLog.logConnectionFrom_Old(request.getRemoteAddress(), request.getTarget(), responseCode);
|
||||
connectionSystem.getConnectionLog().logConnectionFrom(request.getRemoteAddress(), request.getTarget(), responseCode);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -40,6 +40,7 @@ public class ServerConnectionSystem extends ConnectionSystem {
|
||||
private final Database database;
|
||||
private final WebServer webServer;
|
||||
private final PluginLogger pluginLogger;
|
||||
private final WebExceptionLogger webExceptionLogger;
|
||||
|
||||
private long latestServerMapRefresh;
|
||||
|
||||
@ -55,7 +56,8 @@ public class ServerConnectionSystem extends ConnectionSystem {
|
||||
InfoRequests infoRequests,
|
||||
Lazy<InfoSystem> infoSystem,
|
||||
ServerInfo serverInfo,
|
||||
PluginLogger pluginLogger
|
||||
PluginLogger pluginLogger,
|
||||
WebExceptionLogger webExceptionLogger
|
||||
) {
|
||||
super(connectionLog, infoRequests, infoSystem, serverInfo);
|
||||
this.locale = locale;
|
||||
@ -63,6 +65,7 @@ public class ServerConnectionSystem extends ConnectionSystem {
|
||||
this.database = database;
|
||||
this.webServer = webServer;
|
||||
this.pluginLogger = pluginLogger;
|
||||
this.webExceptionLogger = webExceptionLogger;
|
||||
latestServerMapRefresh = 0;
|
||||
}
|
||||
|
||||
@ -105,7 +108,7 @@ public class ServerConnectionSystem extends ConnectionSystem {
|
||||
throw new NoServersException("No Servers available to make wide-request: " + infoRequest.getClass().getSimpleName());
|
||||
}
|
||||
for (Server server : bukkitServers.values()) {
|
||||
WebExceptionLogger.logIfOccurs(this.getClass(), () -> {
|
||||
webExceptionLogger.logIfOccurs(this.getClass(), () -> {
|
||||
try {
|
||||
sendInfoRequest(infoRequest, server);
|
||||
} catch (ConnectionFailException ignored) {
|
||||
|
@ -6,8 +6,12 @@ package com.djrapitops.plan.system.info.connection;
|
||||
|
||||
import com.djrapitops.plan.api.exceptions.connection.*;
|
||||
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.Collections;
|
||||
import java.util.List;
|
||||
@ -18,31 +22,45 @@ import java.util.Map;
|
||||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
@Singleton
|
||||
public class WebExceptionLogger {
|
||||
|
||||
@Deprecated
|
||||
public static void logIfOccurs(Class c, ThrowingVoidFunction<WebException> function) {
|
||||
private final ConnectionLog connectionLog;
|
||||
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 {
|
||||
function.apply();
|
||||
} catch (ConnectionFailException e) {
|
||||
if (shouldLog(e)) {
|
||||
Log.debug(e.getMessage());
|
||||
logger.debug(e.getMessage());
|
||||
}
|
||||
} catch (UnsupportedTransferDatabaseException | UnauthorizedServerException
|
||||
| NotFoundException | NoServersException e) {
|
||||
Log.debug(e.getMessage());
|
||||
logger.debug(e.getMessage());
|
||||
} catch (WebException e) {
|
||||
Log.toLog(c, e);
|
||||
errorHandler.log(L.WARN, definingClass, e);
|
||||
}
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
private static boolean shouldLog(ConnectionFailException e) {
|
||||
private boolean shouldLog(ConnectionFailException e) {
|
||||
String address = getAddress(e);
|
||||
if (address == null) {
|
||||
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);
|
||||
if (entries != null) {
|
||||
List<ConnectionLog.Entry> connections = new ArrayList<>(entries.values());
|
||||
@ -64,8 +82,4 @@ public class WebExceptionLogger {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private WebExceptionLogger() {
|
||||
// Static method class.
|
||||
}
|
||||
}
|
||||
|
@ -7,14 +7,11 @@ package com.djrapitops.plan.system.processing.processors.info;
|
||||
import com.djrapitops.plan.api.exceptions.connection.*;
|
||||
import com.djrapitops.plan.system.cache.SessionCache;
|
||||
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.command.CommandUtils;
|
||||
import com.djrapitops.plugin.command.ISender;
|
||||
|
||||
import java.util.UUID;
|
||||
import java.util.function.BiConsumer;
|
||||
|
||||
/**
|
||||
* 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 ISender sender;
|
||||
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.sender = sender;
|
||||
this.playerName = playerName;
|
||||
this.locale = locale;
|
||||
this.msgSender = msgSender;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
SessionCache.refreshActiveSessionsState();
|
||||
try {
|
||||
InfoSystem.getInstance().generateAndCachePlayerPage(uuid);
|
||||
sendInspectMsg(sender, playerName);
|
||||
infoSystem.generateAndCachePlayerPage(uuid);
|
||||
msgSender.accept(sender, playerName);
|
||||
} catch (ConnectionFailException | UnsupportedTransferDatabaseException | UnauthorizedServerException
|
||||
| NotFoundException | NoServersException e) {
|
||||
sender.sendMessage("§c" + e.getMessage());
|
||||
@ -48,21 +52,4 @@ public class InspectCacheRequestProcessor implements Runnable {
|
||||
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(">");
|
||||
}
|
||||
}
|
||||
|
@ -15,10 +15,12 @@ import com.djrapitops.plugin.api.utility.log.Log;
|
||||
*/
|
||||
public class NetworkPageUpdateProcessor implements Runnable {
|
||||
|
||||
private InfoSystem infoSystem;
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
InfoSystem.getInstance().updateNetworkPage();
|
||||
infoSystem.updateNetworkPage();
|
||||
} catch (WebException e) {
|
||||
Log.toLog(this.getClass(), e);
|
||||
}
|
||||
|
@ -13,20 +13,23 @@ public class PlayerPageUpdateProcessor implements Runnable {
|
||||
|
||||
private final UUID uuid;
|
||||
|
||||
private InfoSystem infoSystem;
|
||||
private WebExceptionLogger webExceptionLogger;
|
||||
|
||||
public PlayerPageUpdateProcessor(UUID uuid) {
|
||||
this.uuid = uuid;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
if (!InfoSystem.getInstance().getConnectionSystem().isServerAvailable() || Check.isBungeeAvailable()) {
|
||||
if (!infoSystem.getConnectionSystem().isServerAvailable() || Check.isBungeeAvailable()) {
|
||||
RunnableFactory.createNew("Generate Inspect page: " + uuid, new AbsRunnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
|
||||
WebExceptionLogger.logIfOccurs(PlayerPageUpdateProcessor.class,
|
||||
() -> InfoSystem.getInstance().generateAndCachePlayerPage(uuid)
|
||||
webExceptionLogger.logIfOccurs(PlayerPageUpdateProcessor.class,
|
||||
() -> infoSystem.generateAndCachePlayerPage(uuid)
|
||||
);
|
||||
} finally {
|
||||
cancel();
|
||||
|
@ -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 */
|
||||
}
|
||||
}
|
||||
}
|
@ -6,24 +6,29 @@ import com.djrapitops.plan.system.info.request.InfoRequestFactory;
|
||||
import com.djrapitops.plugin.task.AbsRunnable;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
@Singleton
|
||||
public class EnableConnectionTask extends AbsRunnable {
|
||||
|
||||
private ConnectionSystem connectionSystem;
|
||||
private final InfoRequestFactory infoRequestFactory;
|
||||
private final WebExceptionLogger webExceptionLogger;
|
||||
|
||||
@Inject
|
||||
public EnableConnectionTask(
|
||||
ConnectionSystem connectionSystem,
|
||||
InfoRequestFactory infoRequestFactory
|
||||
InfoRequestFactory infoRequestFactory,
|
||||
WebExceptionLogger webExceptionLogger
|
||||
) {
|
||||
this.connectionSystem = connectionSystem;
|
||||
this.infoRequestFactory = infoRequestFactory;
|
||||
this.webExceptionLogger = webExceptionLogger;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
WebExceptionLogger.logIfOccurs(this.getClass(),
|
||||
webExceptionLogger.logIfOccurs(this.getClass(),
|
||||
() -> connectionSystem.sendWideInfoRequest(infoRequestFactory.generateNetworkPageContentRequest())
|
||||
);
|
||||
cancel();
|
||||
|
@ -7,28 +7,33 @@ import com.djrapitops.plan.system.info.server.ServerInfo;
|
||||
import com.djrapitops.plugin.task.AbsRunnable;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
@Singleton
|
||||
public class BootAnalysisTask extends AbsRunnable {
|
||||
|
||||
private final InfoSystem infoSystem;
|
||||
private final InfoRequestFactory infoRequestFactory;
|
||||
private final ServerInfo serverInfo;
|
||||
private final WebExceptionLogger webExceptionLogger;
|
||||
|
||||
@Inject
|
||||
public BootAnalysisTask(
|
||||
InfoSystem infoSystem,
|
||||
InfoRequestFactory infoRequestFactory,
|
||||
ServerInfo serverInfo
|
||||
ServerInfo serverInfo,
|
||||
WebExceptionLogger webExceptionLogger
|
||||
) {
|
||||
this.infoSystem = infoSystem;
|
||||
this.infoRequestFactory = infoRequestFactory;
|
||||
this.serverInfo = serverInfo;
|
||||
this.webExceptionLogger = webExceptionLogger;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
WebExceptionLogger.logIfOccurs(this.getClass(), () ->
|
||||
webExceptionLogger.logIfOccurs(this.getClass(), () ->
|
||||
infoSystem.sendRequest(infoRequestFactory.generateAnalysisPageRequest(serverInfo.getServerUUID()))
|
||||
);
|
||||
} catch (IllegalStateException ignore) {
|
||||
|
@ -5,18 +5,25 @@ import com.djrapitops.plan.system.info.connection.WebExceptionLogger;
|
||||
import com.djrapitops.plugin.task.AbsRunnable;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
@Singleton
|
||||
public class NetworkPageRefreshTask extends AbsRunnable {
|
||||
|
||||
private InfoSystem infoSystem;
|
||||
private final WebExceptionLogger webExceptionLogger;
|
||||
|
||||
@Inject
|
||||
public NetworkPageRefreshTask(InfoSystem infoSystem) {
|
||||
public NetworkPageRefreshTask(
|
||||
InfoSystem infoSystem,
|
||||
WebExceptionLogger webExceptionLogger
|
||||
) {
|
||||
this.infoSystem = infoSystem;
|
||||
this.webExceptionLogger = webExceptionLogger;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
WebExceptionLogger.logIfOccurs(this.getClass(), () -> infoSystem.updateNetworkPage());
|
||||
webExceptionLogger.logIfOccurs(this.getClass(), () -> infoSystem.updateNetworkPage());
|
||||
}
|
||||
}
|
||||
|
@ -10,7 +10,9 @@ import com.djrapitops.plugin.logging.error.ErrorHandler;
|
||||
import com.djrapitops.plugin.task.AbsRunnable;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
@Singleton
|
||||
public class PeriodicAnalysisTask extends AbsRunnable {
|
||||
|
||||
private final InfoSystem infoSystem;
|
||||
@ -18,25 +20,28 @@ public class PeriodicAnalysisTask extends AbsRunnable {
|
||||
private final ServerInfo serverInfo;
|
||||
private final PluginLogger logger;
|
||||
private final ErrorHandler errorHandler;
|
||||
private final WebExceptionLogger webExceptionLogger;
|
||||
|
||||
@Inject
|
||||
public PeriodicAnalysisTask(
|
||||
InfoSystem infoSystem,
|
||||
InfoRequestFactory infoRequestFactory, ServerInfo serverInfo,
|
||||
PluginLogger logger,
|
||||
ErrorHandler errorHandler
|
||||
ErrorHandler errorHandler,
|
||||
WebExceptionLogger webExceptionLogger
|
||||
) {
|
||||
this.infoSystem = infoSystem;
|
||||
this.infoRequestFactory = infoRequestFactory;
|
||||
this.serverInfo = serverInfo;
|
||||
this.logger = logger;
|
||||
this.errorHandler = errorHandler;
|
||||
this.webExceptionLogger = webExceptionLogger;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
WebExceptionLogger.logIfOccurs(this.getClass(), () ->
|
||||
webExceptionLogger.logIfOccurs(this.getClass(), () ->
|
||||
infoSystem.sendRequest(infoRequestFactory.generateAnalysisPageRequest(serverInfo.getServerUUID()))
|
||||
);
|
||||
} catch (IllegalStateException ignore) {
|
||||
|
@ -12,7 +12,6 @@ import com.djrapitops.plugin.api.Check;
|
||||
import com.djrapitops.plugin.logging.L;
|
||||
import com.djrapitops.plugin.logging.console.PluginLogger;
|
||||
import com.djrapitops.plugin.logging.error.ErrorHandler;
|
||||
import com.djrapitops.plugin.utilities.Verify;
|
||||
import com.sun.net.httpserver.HttpServer;
|
||||
import com.sun.net.httpserver.HttpsConfigurator;
|
||||
import com.sun.net.httpserver.HttpsParameters;
|
||||
@ -75,13 +74,6 @@ public class WebServer implements SubSystem {
|
||||
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
|
||||
public void enable() throws EnableException {
|
||||
this.port = config.getNumber(Settings.WEBSERVER_PORT);
|
||||
|
@ -5,18 +5,19 @@
|
||||
package com.djrapitops.plan.system.webserver;
|
||||
|
||||
import com.djrapitops.plan.api.exceptions.EnableException;
|
||||
import com.djrapitops.plan.system.PlanSystem;
|
||||
import com.djrapitops.plan.system.SubSystem;
|
||||
import com.djrapitops.plan.system.webserver.cache.ResponseCache;
|
||||
import com.djrapitops.plugin.benchmarking.Timings;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
/**
|
||||
* WebServer subsystem for managing WebServer initialization.
|
||||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
@Singleton
|
||||
public class WebServerSystem implements SubSystem {
|
||||
|
||||
private final WebServer webServer;
|
||||
@ -28,17 +29,6 @@ public class WebServerSystem implements SubSystem {
|
||||
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
|
||||
public void enable() throws EnableException {
|
||||
timings.start("WebServer Initialization");
|
||||
|
@ -72,7 +72,7 @@ public class ServerPageHandler implements PageHandler {
|
||||
}
|
||||
return ResponseCache.loadResponse(PageId.SERVER.of(serverUUID));
|
||||
}
|
||||
return AnalysisPageResponse.refreshNow(serverUUID);
|
||||
return AnalysisPageResponse.refreshNow(serverUUID, infoSystem);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -21,10 +21,10 @@ import java.util.UUID;
|
||||
public class AnalysisPageResponse extends Response {
|
||||
|
||||
@Deprecated
|
||||
public static AnalysisPageResponse refreshNow(UUID serverUUID) {
|
||||
public static AnalysisPageResponse refreshNow(UUID serverUUID, InfoSystem infoSystem) {
|
||||
Processing.submitNonCritical(() -> {
|
||||
try {
|
||||
InfoSystem.getInstance().generateAnalysisPage(serverUUID);
|
||||
infoSystem.generateAnalysisPage(serverUUID);
|
||||
} catch (NoServersException | ConnectionFailException e) {
|
||||
ResponseCache.cacheResponse(PageId.SERVER.of(serverUUID), () -> new NotFoundResponse(e.getMessage()));
|
||||
} catch (WebException e) {
|
||||
|
@ -3,7 +3,6 @@ package com.djrapitops.plan.utilities.metrics;
|
||||
import com.djrapitops.plan.PlanBungee;
|
||||
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.bungeecord.Metrics;
|
||||
|
||||
import java.io.Serializable;
|
||||
@ -11,14 +10,18 @@ import java.io.Serializable;
|
||||
public class BStatsBungee {
|
||||
|
||||
private final PlanBungee plugin;
|
||||
private final Database database;
|
||||
private final ConnectionSystem connectionSystem;
|
||||
|
||||
private Metrics metrics;
|
||||
|
||||
public BStatsBungee(PlanBungee plugin) {
|
||||
public BStatsBungee(PlanBungee plugin, Database database, ConnectionSystem connectionSystem) {
|
||||
this.plugin = plugin;
|
||||
this.database = database;
|
||||
this.connectionSystem = connectionSystem;
|
||||
}
|
||||
|
||||
public void registerMetrics() {
|
||||
Log.logDebug("Enable", "Enabling bStats Metrics.");
|
||||
if (metrics == null) {
|
||||
metrics = new Metrics(plugin);
|
||||
}
|
||||
@ -27,11 +30,11 @@ public class BStatsBungee {
|
||||
|
||||
private void registerConfigSettingGraphs() {
|
||||
String serverType = plugin.getProxy().getName();
|
||||
String databaseType = Database.getActive().getName();
|
||||
String databaseType = database.getName();
|
||||
|
||||
addStringSettingPie("server_type", serverType);
|
||||
addStringSettingPie("database_type", databaseType);
|
||||
addStringSettingPie("network_servers", ConnectionSystem.getInstance().getBukkitServers().size());
|
||||
addStringSettingPie("network_servers", connectionSystem.getBukkitServers().size());
|
||||
}
|
||||
|
||||
protected void addStringSettingPie(String id, Serializable setting) {
|
||||
|
@ -1,8 +1,6 @@
|
||||
package com.djrapitops.plan.utilities.metrics;
|
||||
|
||||
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 java.io.Serializable;
|
||||
@ -10,27 +8,25 @@ import java.io.Serializable;
|
||||
public class BStatsSponge {
|
||||
|
||||
private final Metrics metrics;
|
||||
private final Database database;
|
||||
|
||||
public BStatsSponge(Metrics metrics) {
|
||||
public BStatsSponge(Metrics metrics, Database database) {
|
||||
this.metrics = metrics;
|
||||
this.database = database;
|
||||
}
|
||||
|
||||
public void registerMetrics() {
|
||||
Log.logDebug("Enable", "Enabling bStats Metrics.");
|
||||
if (metrics != null) {
|
||||
registerConfigSettingGraphs();
|
||||
} else {
|
||||
Log.debug("Metrics not injected properly.");
|
||||
}
|
||||
}
|
||||
|
||||
private void registerConfigSettingGraphs() {
|
||||
String serverType = "Sponge";
|
||||
String databaseType = Database.getActive().getName();
|
||||
String databaseType = database.getName();
|
||||
|
||||
addStringSettingPie("server_type", serverType);
|
||||
addStringSettingPie("database_type", databaseType);
|
||||
addStringSettingPie("network_servers", ConnectionSystem.getInstance().getBukkitServers().size());
|
||||
}
|
||||
|
||||
protected void addStringSettingPie(String id, Serializable setting) {
|
||||
|
Loading…
Reference in New Issue
Block a user