[Debt] AnalysisPluginsTabContentCreator non-static

This commit is contained in:
Rsl1122 2018-09-19 20:04:58 +03:00
parent 7a817d3463
commit e7cbf10ee3
3 changed files with 41 additions and 23 deletions

View File

@ -52,6 +52,7 @@ public class AnalysisContainer extends DataContainer {
private Graphs graphs; private Graphs graphs;
private HtmlTables tables; private HtmlTables tables;
private Accordions accordions; private Accordions accordions;
private AnalysisPluginsTabContentCreator pluginsTabContentCreator;
private Formatter<DateHolder> yearFormatter; private Formatter<DateHolder> yearFormatter;
private Formatter<Long> secondLongFormatter; private Formatter<Long> secondLongFormatter;
@ -430,12 +431,7 @@ public class AnalysisContainer extends DataContainer {
private void addPluginSuppliers() { private void addPluginSuppliers() {
// TODO Refactor into a system that supports running the analysis on Bungee // TODO Refactor into a system that supports running the analysis on Bungee
Key<String[]> navAndTabs = new Key<>(new Type<String[]>() {}, "NAV_AND_TABS"); Key<String[]> navAndTabs = new Key<>(new Type<String[]>() {}, "NAV_AND_TABS");
putSupplier(navAndTabs, () -> putSupplier(navAndTabs, () -> pluginsTabContentCreator.createContent(this));
AnalysisPluginsTabContentCreator.createContent(
getUnsafe(AnalysisKeys.PLAYERS_MUTATOR),
this
)
);
putSupplier(AnalysisKeys.PLUGINS_TAB_NAV, () -> getUnsafe(navAndTabs)[0]); putSupplier(AnalysisKeys.PLUGINS_TAB_NAV, () -> getUnsafe(navAndTabs)[0]);
putSupplier(AnalysisKeys.PLUGINS_TAB, () -> getUnsafe(navAndTabs)[1]); putSupplier(AnalysisKeys.PLUGINS_TAB, () -> getUnsafe(navAndTabs)[1]);
} }

View File

@ -7,6 +7,7 @@ package com.djrapitops.plan.system;
*/ */
public class DebugChannels { public class DebugChannels {
public static final String ANALYSIS = "Analysis";
public static final String INFO_REQUESTS = "InfoRequests"; public static final String INFO_REQUESTS = "InfoRequests";
public static final String CONNECTIONS = "Connections"; public static final String CONNECTIONS = "Connections";
public static final String WEB_REQUESTS = "Web Requests"; public static final String WEB_REQUESTS = "Web Requests";

View File

@ -4,18 +4,22 @@
*/ */
package com.djrapitops.plan.utilities.html.structure; package com.djrapitops.plan.utilities.html.structure;
import com.djrapitops.plan.PlanPlugin;
import com.djrapitops.plan.data.element.AnalysisContainer; import com.djrapitops.plan.data.element.AnalysisContainer;
import com.djrapitops.plan.data.element.InspectContainer; import com.djrapitops.plan.data.element.InspectContainer;
import com.djrapitops.plan.data.plugin.HookHandler; import com.djrapitops.plan.data.plugin.HookHandler;
import com.djrapitops.plan.data.plugin.PluginData; import com.djrapitops.plan.data.plugin.PluginData;
import com.djrapitops.plan.data.store.keys.AnalysisKeys;
import com.djrapitops.plan.data.store.mutators.PlayersMutator; import com.djrapitops.plan.data.store.mutators.PlayersMutator;
import com.djrapitops.plan.system.DebugChannels;
import com.djrapitops.plan.utilities.comparators.PluginDataNameComparator; import com.djrapitops.plan.utilities.comparators.PluginDataNameComparator;
import com.djrapitops.plan.utilities.html.tables.HtmlTables; import com.djrapitops.plan.utilities.html.tables.HtmlTables;
import com.djrapitops.plugin.StaticHolder; import com.djrapitops.plugin.benchmarking.Timings;
import com.djrapitops.plugin.api.Benchmark; import com.djrapitops.plugin.logging.L;
import com.djrapitops.plugin.api.utility.log.Log; 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.*; import java.util.*;
/** /**
@ -23,13 +27,35 @@ import java.util.*;
* *
* @author Rsl1122 * @author Rsl1122
*/ */
// TODO Turn non static @Singleton
public class AnalysisPluginsTabContentCreator { public class AnalysisPluginsTabContentCreator {
public static String[] createContent( private final HookHandler hookHandler;
PlayersMutator mutator, private final HtmlTables tables;
private final Timings timings;
private final PluginLogger logger;
private final ErrorHandler errorHandler;
@Inject
public AnalysisPluginsTabContentCreator(
HookHandler hookHandler,
HtmlTables tables,
Timings timings,
PluginLogger logger,
ErrorHandler errorHandler
) {
this.hookHandler = hookHandler;
this.tables = tables;
this.timings = timings;
this.logger = logger;
this.errorHandler = errorHandler;
}
public String[] createContent(
com.djrapitops.plan.data.store.containers.AnalysisContainer analysisContainer com.djrapitops.plan.data.store.containers.AnalysisContainer analysisContainer
) { ) {
PlayersMutator mutator = analysisContainer.getValue(AnalysisKeys.PLAYERS_MUTATOR).orElse(new PlayersMutator(new ArrayList<>()));
if (mutator.all().isEmpty()) { if (mutator.all().isEmpty()) {
return new String[]{"<li><a>No Data</a></li>", ""}; return new String[]{"<li><a>No Data</a></li>", ""};
} }
@ -77,8 +103,6 @@ public class AnalysisPluginsTabContentCreator {
generalTab.append("</div></div>"); generalTab.append("</div></div>");
HtmlTables tables = null; // TODO Use HtmlTables
String playerListTab = "<div class=\"tab\">" + String playerListTab = "<div class=\"tab\">" +
"<div class=\"row clearfix\">" + "<div class=\"row clearfix\">" +
"<div class=\"col-lg-12 col-md-12 col-sm-12 col-xs-12\">" + "<div class=\"col-lg-12 col-md-12 col-sm-12 col-xs-12\">" +
@ -96,20 +120,17 @@ public class AnalysisPluginsTabContentCreator {
}; };
} }
private static Map<PluginData, AnalysisContainer> analyzeAdditionalPluginData( private Map<PluginData, AnalysisContainer> analyzeAdditionalPluginData(
Collection<UUID> uuids, Collection<UUID> uuids,
com.djrapitops.plan.data.store.containers.AnalysisContainer analysisContainer com.djrapitops.plan.data.store.containers.AnalysisContainer analysisContainer
) { ) {
Map<PluginData, AnalysisContainer> containers = new HashMap<>(); Map<PluginData, AnalysisContainer> containers = new HashMap<>();
HookHandler hookHandler = null; // TODO
List<PluginData> sources = hookHandler.getAdditionalDataSources(); List<PluginData> sources = hookHandler.getAdditionalDataSources();
sources.parallelStream().forEach(source -> { sources.parallelStream().forEach(source -> {
PlanPlugin plugin = PlanPlugin.getInstance();
StaticHolder.saveInstance(AnalysisPluginsTabContentCreator.class, plugin.getClass());
try { try {
Benchmark.start("Analysis: Source " + source.getSourcePlugin()); timings.start("Source " + source.getSourcePlugin());
source.setAnalysisData(analysisContainer); source.setAnalysisData(analysisContainer);
AnalysisContainer container = source.getServerData(uuids, new AnalysisContainer()); AnalysisContainer container = source.getServerData(uuids, new AnalysisContainer());
@ -118,10 +139,10 @@ public class AnalysisPluginsTabContentCreator {
} }
} catch (Exception | NoClassDefFoundError | NoSuchFieldError | NoSuchMethodError e) { } catch (Exception | NoClassDefFoundError | NoSuchFieldError | NoSuchMethodError e) {
Log.error("A PluginData-source caused an exception: " + source.getSourcePlugin()); logger.error("A PluginData-source caused an exception: " + source.getSourcePlugin());
Log.toLog(AnalysisPluginsTabContentCreator.class, e); errorHandler.log(L.WARN, this.getClass(), e);
} finally { } finally {
Benchmark.stop("Analysis", "Analysis: Source " + source.getSourcePlugin()); timings.end(DebugChannels.ANALYSIS, "Source " + source.getSourcePlugin());
} }
}); });
return containers; return containers;