mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2025-01-24 16:14:26 +08:00
Deleted DBCallableProcessor & AnalysisCacheHandler
This commit is contained in:
parent
69ea446eb9
commit
1baa4d14c0
@ -1,132 +0,0 @@
|
||||
package main.java.com.djrapitops.plan.data.cache;
|
||||
|
||||
import com.djrapitops.plugin.command.CommandUtils;
|
||||
import com.djrapitops.plugin.command.ISender;
|
||||
import com.djrapitops.plugin.utilities.player.IPlayer;
|
||||
import main.java.com.djrapitops.plan.Plan;
|
||||
import main.java.com.djrapitops.plan.data.AnalysisData;
|
||||
import main.java.com.djrapitops.plan.locale.Locale;
|
||||
import main.java.com.djrapitops.plan.locale.Msg;
|
||||
import main.java.com.djrapitops.plan.utilities.analysis.Analysis;
|
||||
import main.java.com.djrapitops.plan.utilities.html.HtmlUtils;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* This class is used to store the most recent AnalysisData object and to run
|
||||
* Analysis.
|
||||
*
|
||||
* @author Rsl1122
|
||||
* @since 2.0.0
|
||||
*/
|
||||
@Deprecated
|
||||
public class AnalysisCacheHandler {
|
||||
|
||||
private final Plan plugin;
|
||||
private final Analysis analysis;
|
||||
private AnalysisData cache;
|
||||
private boolean analysisEnabled;
|
||||
|
||||
private final Set<UUID> notifyWhenCached;
|
||||
|
||||
/**
|
||||
* Class Constructor.
|
||||
* <p>
|
||||
* Initializes Analysis
|
||||
*
|
||||
* @param plugin Current instance of Plan
|
||||
*/
|
||||
public AnalysisCacheHandler(Plan plugin) {
|
||||
this.plugin = plugin;
|
||||
analysis = new Analysis(plugin);
|
||||
analysisEnabled = true;
|
||||
notifyWhenCached = new HashSet<>();
|
||||
}
|
||||
|
||||
/**
|
||||
* Runs analysis, cache method is called after analysis is complete.
|
||||
*/
|
||||
public void updateCache() {
|
||||
analysis.runAnalysis(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves the new analysis data to cache.
|
||||
*
|
||||
* @param data AnalysisData generated by Analysis.analyze
|
||||
*/
|
||||
public void cache(AnalysisData data) {
|
||||
cache = data;
|
||||
for (UUID uuid : notifyWhenCached) {
|
||||
Optional<IPlayer> player = plugin.fetch().getPlayer(uuid);
|
||||
player.ifPresent(this::sendAnalysisMessage);
|
||||
}
|
||||
notifyWhenCached.clear();
|
||||
}
|
||||
|
||||
public void sendAnalysisMessage(ISender sender) {
|
||||
sender.sendMessage(Locale.get(Msg.CMD_HEADER_ANALYZE).toString());
|
||||
|
||||
// Link
|
||||
String url = HtmlUtils.getServerAnalysisUrlWithProtocol();
|
||||
String message = Locale.get(Msg.CMD_INFO_LINK).toString();
|
||||
boolean console = !CommandUtils.isPlayer(sender);
|
||||
if (console) {
|
||||
sender.sendMessage(message + url);
|
||||
} else {
|
||||
sender.sendMessage(message);
|
||||
sender.sendLink(" ", Locale.get(Msg.CMD_INFO_CLICK_ME).toString(), url);
|
||||
}
|
||||
|
||||
sender.sendMessage(Locale.get(Msg.CMD_CONSTANT_FOOTER).toString());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the cached AnalysisData.
|
||||
*
|
||||
* @return null if not cached
|
||||
*/
|
||||
public AnalysisData getData() {
|
||||
return cache;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the AnalysisData has been cached.
|
||||
*
|
||||
* @return true if there is data in the cache.
|
||||
*/
|
||||
public boolean isCached() {
|
||||
return cache != null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return if currently an analysis is being run
|
||||
*/
|
||||
public boolean isAnalysisBeingRun() {
|
||||
return analysis.isAnalysisBeingRun();
|
||||
}
|
||||
|
||||
public boolean isAnalysisEnabled() {
|
||||
return analysisEnabled;
|
||||
}
|
||||
|
||||
public void disableAnalysisTemporarily() {
|
||||
analysisEnabled = false;
|
||||
analysis.setTaskId(-2);
|
||||
}
|
||||
|
||||
public void enableAnalysis() {
|
||||
analysis.setTaskId(-1);
|
||||
analysisEnabled = true;
|
||||
}
|
||||
|
||||
public void addNotification(ISender sender) {
|
||||
if (CommandUtils.isPlayer(sender)) {
|
||||
notifyWhenCached.add(((Player) sender.getSender()).getUniqueId());
|
||||
}
|
||||
}
|
||||
}
|
@ -1,26 +0,0 @@
|
||||
package main.java.com.djrapitops.plan.data.cache;
|
||||
|
||||
import main.java.com.djrapitops.plan.data.UserInfo;
|
||||
|
||||
/**
|
||||
* This interface can be extended with anything as the process method and
|
||||
* given to the Database.
|
||||
* <p>
|
||||
* The process method will be called with the UserInfo object fetched from the
|
||||
* database.
|
||||
*
|
||||
* @author Rsl1122
|
||||
* @since 2.6.0
|
||||
*/
|
||||
@Deprecated
|
||||
public interface DBCallableProcessor {
|
||||
|
||||
/**
|
||||
* Method used to do multiple things to UserInfo objects such as Caching,
|
||||
* changing properties etc.
|
||||
*
|
||||
* @param data UserInfo object given to the DBCallableProcessor by the
|
||||
* method it was given as parameter to.
|
||||
*/
|
||||
void process(UserInfo data);
|
||||
}
|
@ -10,12 +10,12 @@ import main.java.com.djrapitops.plan.data.additional.AnalysisType;
|
||||
import main.java.com.djrapitops.plan.data.additional.HookHandler;
|
||||
import main.java.com.djrapitops.plan.data.additional.PluginData;
|
||||
import main.java.com.djrapitops.plan.data.analysis.*;
|
||||
import main.java.com.djrapitops.plan.data.cache.AnalysisCacheHandler;
|
||||
import main.java.com.djrapitops.plan.database.Database;
|
||||
import main.java.com.djrapitops.plan.locale.Locale;
|
||||
import main.java.com.djrapitops.plan.locale.Msg;
|
||||
import main.java.com.djrapitops.plan.systems.cache.DataCache;
|
||||
import main.java.com.djrapitops.plan.systems.cache.PageCache;
|
||||
import main.java.com.djrapitops.plan.systems.info.InformationManager;
|
||||
import main.java.com.djrapitops.plan.systems.webserver.response.AnalysisPageResponse;
|
||||
import main.java.com.djrapitops.plan.systems.webserver.response.PlayersPageResponse;
|
||||
import main.java.com.djrapitops.plan.systems.webserver.response.api.JsonResponse;
|
||||
@ -46,14 +46,10 @@ public class Analysis {
|
||||
|
||||
/**
|
||||
* Analyzes the data of all offline players on the server.
|
||||
* <p>
|
||||
* First retrieves all offline players and checks those that are in the
|
||||
* database. Then runs a new Analysis Task asynchronously. Saves AnalysisData
|
||||
* to the provided Cache. Saves all UserInfo to InspectCache for 15 minutes.
|
||||
*
|
||||
* @param analysisCache Cache that the data is saved to.
|
||||
* @param infoManager InformationManager of the plugin.
|
||||
*/
|
||||
public void runAnalysis(AnalysisCacheHandler analysisCache) {
|
||||
public void runAnalysis(InformationManager infoManager) {
|
||||
if (isAnalysisBeingRun()) {
|
||||
return;
|
||||
}
|
||||
@ -65,7 +61,7 @@ public class Analysis {
|
||||
@Override
|
||||
public void run() {
|
||||
taskId = this.getTaskId();
|
||||
analyze(analysisCache, plugin.getDB());
|
||||
analyze(infoManager, plugin.getDB());
|
||||
taskId = -1;
|
||||
this.cancel();
|
||||
}
|
||||
@ -75,12 +71,12 @@ public class Analysis {
|
||||
/**
|
||||
* Caches analyzed data of db to the provided cache analysisCache.
|
||||
*
|
||||
* @param analysisCache Cache that will contain AnalysisData result of this
|
||||
* @param infoManager InformationManager of the plugin.
|
||||
* method.
|
||||
* @param db Database which data will be analyzed.
|
||||
* @return Whether or not analysis was successful.
|
||||
*/
|
||||
public boolean analyze(AnalysisCacheHandler analysisCache, Database db) {
|
||||
public boolean analyze(InformationManager infoManager, Database db) {
|
||||
log(Locale.get(Msg.ANALYSIS_FETCH).toString());
|
||||
Benchmark.start("Fetch Phase");
|
||||
Log.debug("Database", "Analysis Fetch");
|
||||
@ -95,15 +91,15 @@ public class Analysis {
|
||||
Log.toLog(this.getClass().getName(), ex);
|
||||
}
|
||||
|
||||
return analyzeData(tpsData, analysisCache);
|
||||
return analyzeData(tpsData, infoManager);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param tpsData
|
||||
* @param analysisCache
|
||||
* @param infoManager InformationManager of the plugin.
|
||||
* @return
|
||||
*/
|
||||
public boolean analyzeData(List<TPS> tpsData, AnalysisCacheHandler analysisCache) {
|
||||
public boolean analyzeData(List<TPS> tpsData, InformationManager infoManager) {
|
||||
try {
|
||||
// rawData.sort(new UserDataLastPlayedComparator());
|
||||
// List<UUID> uuids = rawData.stream().map(UserInfo::getUuid).collect(Collectors.toList());
|
||||
@ -143,7 +139,7 @@ public class Analysis {
|
||||
Log.debug("Analysis", "Analyzing additional data sources (3rd party)");
|
||||
// TODO analysisData.setAdditionalDataReplaceMap(analyzeAdditionalPluginData(uuids));
|
||||
|
||||
analysisCache.cache(analysisData);
|
||||
infoManager.cacheAnalysisdata(analysisData);
|
||||
long time = Benchmark.stop("Analysis", "Analysis");
|
||||
|
||||
Log.logDebug("Analysis", time);
|
||||
|
Loading…
Reference in New Issue
Block a user