Improvements & Fix #147

- RslPlugin v1.4.0
- RunnableFactory
- Prevented a collision if multiple RslPlugin implementations are
installed.
- Queues now wait for each other.
This commit is contained in:
Rsl1122 2017-07-04 11:24:50 +03:00
parent b0045077f6
commit 8cf22de4b6
26 changed files with 122 additions and 94 deletions

View File

@ -16,7 +16,7 @@ public class Log {
* @param message "Message" will show up as [INFO][Plan]: Message
*/
public static void info(String message) {
Plan.getPluginInstance().getPluginLogger().info(message);
Plan.getInstance().getPluginLogger().info(message);
}
/**

View File

@ -22,6 +22,7 @@ package main.java.com.djrapitops.plan;
import com.djrapitops.javaplugin.api.ColorScheme;
import com.djrapitops.javaplugin.RslPlugin;
import com.djrapitops.javaplugin.task.RslBukkitRunnable;
import com.djrapitops.javaplugin.task.RslRunnable;
import com.djrapitops.javaplugin.task.RslTask;
import java.io.File;
import java.io.FileNotFoundException;
@ -114,7 +115,7 @@ public class Plan extends RslPlugin<Plan> {
this.inspectCache = new InspectCacheHandler(this);
this.analysisCache = new AnalysisCacheHandler(this);
registerListeners();
new TPSCountTimer(this).runTaskTimer(1000, 20);
getRunnableFactory().createNew(new TPSCountTimer(this)).runTaskTimer(1000, 20);
registerCommand(new PlanCommand(this));
@ -231,7 +232,7 @@ public class Plan extends RslPlugin<Plan> {
}
private void startAnalysisRefreshTask(int analysisRefreshMinutes) throws IllegalStateException, IllegalArgumentException {
RslTask task = new RslBukkitRunnable<Plan>("PeriodicalAnalysisTask") {
RslTask task = getRunnableFactory().createNew("PeriodicalAnalysisTask", new RslRunnable() {
@Override
public void run() {
if (!analysisCache.isCached()) {
@ -240,19 +241,19 @@ public class Plan extends RslPlugin<Plan> {
analysisCache.updateCache();
}
}
}.runTaskTimerAsynchronously(analysisRefreshMinutes * 60 * 20, analysisRefreshMinutes * 60 * 20);
}).runTaskTimerAsynchronously(analysisRefreshMinutes * 60 * 20, analysisRefreshMinutes * 60 * 20);
}
private void startBootAnalysisTask() throws IllegalStateException, IllegalArgumentException {
Log.info(Phrase.ANALYSIS_BOOT_NOTIFY + "");
RslTask bootAnalysisTask = new RslBukkitRunnable<Plan>("BootAnalysisTask") {
RslTask bootAnalysisTask = getRunnableFactory().createNew("BootAnalysisTask", new RslRunnable() {
@Override
public void run() {
Log.info(Phrase.ANALYSIS_BOOT + "");
analysisCache.updateCache();
this.cancel();
}
}.runTaskLaterAsynchronously(30 * 20);
}).runTaskLaterAsynchronously(30 * 20);
bootAnalysisTaskID = bootAnalysisTask.getTaskId();
}
@ -429,6 +430,6 @@ public class Plan extends RslPlugin<Plan> {
* @return this object.
*/
public static Plan getInstance() {
return (Plan) getPluginInstance();
return (Plan) getPluginInstance(Plan.class);
}
}

View File

@ -3,7 +3,7 @@ package main.java.com.djrapitops.plan.command.commands;
import com.djrapitops.javaplugin.command.CommandType;
import com.djrapitops.javaplugin.command.SubCommand;
import com.djrapitops.javaplugin.command.sender.ISender;
import com.djrapitops.javaplugin.task.RslBukkitRunnable;
import com.djrapitops.javaplugin.task.RslRunnable;
import com.djrapitops.javaplugin.task.RslTask;
import main.java.com.djrapitops.plan.Log;
import main.java.com.djrapitops.plan.Permissions;
@ -61,7 +61,7 @@ public class AnalyzeCommand extends SubCommand {
}
analysisCache.updateCache();
}
final RslTask task = new RslBukkitRunnable<Plan>("AnalysisMessageSenderTask") {
final RslTask task = plugin.getRunnableFactory().createNew("AnalysisMessageSenderTask", new RslRunnable() {
private int timesrun = 0;
@Override
@ -78,7 +78,7 @@ public class AnalyzeCommand extends SubCommand {
this.cancel();
}
}
}.runTaskTimer(1 * 20, 5 * 20);
}).runTaskTimer(1 * 20, 5 * 20);
return true;
}

View File

@ -4,6 +4,7 @@ import com.djrapitops.javaplugin.command.CommandType;
import com.djrapitops.javaplugin.command.SubCommand;
import com.djrapitops.javaplugin.command.sender.ISender;
import com.djrapitops.javaplugin.task.RslBukkitRunnable;
import com.djrapitops.javaplugin.task.RslRunnable;
import com.djrapitops.javaplugin.task.RslTask;
import main.java.com.djrapitops.plan.command.ConditionUtils;
import java.util.UUID;
@ -50,7 +51,7 @@ public class InspectCommand extends SubCommand {
return true;
}
String playerName = MiscUtils.getPlayerName(args, sender);
final RslTask inspectTask = new RslBukkitRunnable<Plan>("InspectTask") {
final RslTask inspectTask = plugin.getRunnableFactory().createNew(new RslRunnable("InspectTask") {
@Override
public void run() {
UUID uuid = ConditionUtils.getUUID(playerName);
@ -69,7 +70,7 @@ public class InspectCommand extends SubCommand {
}
sender.sendMessage(Phrase.GRABBING_DATA_MESSAGE + "");
inspectCache.cache(uuid);
final RslTask inspectMessageSenderTask = new RslBukkitRunnable<Plan>("InspectMessageSenderTask") {
final RslTask inspectMessageSenderTask = plugin.getRunnableFactory().createNew(new RslRunnable("InspectMessageSenderTask") {
private int timesrun = 0;
@Override
@ -87,10 +88,10 @@ public class InspectCommand extends SubCommand {
}
}
}.runTaskTimer(1 * 20, 5 * 20);
}).runTaskTimer(1 * 20, 5 * 20);
this.cancel();
}
}.runTaskAsynchronously();
}).runTaskAsynchronously();
return true;
}

View File

@ -4,6 +4,7 @@ import com.djrapitops.javaplugin.command.CommandType;
import com.djrapitops.javaplugin.command.SubCommand;
import com.djrapitops.javaplugin.command.sender.ISender;
import com.djrapitops.javaplugin.task.RslBukkitRunnable;
import com.djrapitops.javaplugin.task.RslRunnable;
import com.djrapitops.javaplugin.task.RslTask;
import main.java.com.djrapitops.plan.Log;
import main.java.com.djrapitops.plan.Permissions;
@ -56,7 +57,7 @@ public class QuickAnalyzeCommand extends SubCommand {
analysisCache.updateCache();
}
RslTask analysisMessageSenderTask = new RslBukkitRunnable<Plan>("QanalysisMessageSenderTask") {
RslTask analysisMessageSenderTask = plugin.getRunnableFactory().createNew(new RslRunnable("QanalysisMessageSenderTask") {
private int timesrun = 0;
@Override
@ -74,7 +75,7 @@ public class QuickAnalyzeCommand extends SubCommand {
this.cancel();
}
}
}.runTaskTimer(1 * 20, 5 * 20);
}).runTaskTimer(1 * 20, 5 * 20);
return true;
}
}

View File

@ -4,6 +4,7 @@ import com.djrapitops.javaplugin.command.CommandType;
import com.djrapitops.javaplugin.command.SubCommand;
import com.djrapitops.javaplugin.command.sender.ISender;
import com.djrapitops.javaplugin.task.RslBukkitRunnable;
import com.djrapitops.javaplugin.task.RslRunnable;
import com.djrapitops.javaplugin.task.RslTask;
import java.util.UUID;
import main.java.com.djrapitops.plan.Log;
@ -45,7 +46,7 @@ public class QuickInspectCommand extends SubCommand {
@Override
public boolean onCommand(ISender sender, String commandLabel, String[] args) {
String playerName = MiscUtils.getPlayerName(args, sender, Permissions.QUICK_INSPECT_OTHER);
final RslTask inspectTask = new RslBukkitRunnable<Plan>("QinspectTask") {
final RslTask inspectTask = plugin.getRunnableFactory().createNew(new RslRunnable("QinspectTask") {
@Override
public void run() {
UUID uuid = ConditionUtils.getUUID(playerName);
@ -64,7 +65,7 @@ public class QuickInspectCommand extends SubCommand {
}
sender.sendMessage(Phrase.GRABBING_DATA_MESSAGE + "");
inspectCache.cache(uuid);
final RslTask inspectMessageSenderTask = new RslBukkitRunnable<Plan>("QinspectMessageSenderTask") {
final RslTask inspectMessageSenderTask = plugin.getRunnableFactory().createNew(new RslRunnable("QinspectMessageSenderTask") {
private int timesrun = 0;
@Override
@ -82,10 +83,10 @@ public class QuickInspectCommand extends SubCommand {
this.cancel();
}
}
}.runTaskTimer(1 * 20, 5 * 20);
}).runTaskTimer(1 * 20, 5 * 20);
this.cancel();
}
}.runTaskAsynchronously();
}).runTaskAsynchronously();
return true;
}
}

View File

@ -4,6 +4,7 @@ import com.djrapitops.javaplugin.command.CommandType;
import com.djrapitops.javaplugin.command.SubCommand;
import com.djrapitops.javaplugin.command.sender.ISender;
import com.djrapitops.javaplugin.task.RslBukkitRunnable;
import com.djrapitops.javaplugin.task.RslRunnable;
import com.djrapitops.javaplugin.task.RslTask;
import com.djrapitops.javaplugin.utilities.FormattingUtils;
import java.util.Arrays;
@ -18,8 +19,6 @@ import main.java.com.djrapitops.plan.command.Condition;
import main.java.com.djrapitops.plan.data.cache.InspectCacheHandler;
import main.java.com.djrapitops.plan.utilities.MiscUtils;
import org.bukkit.OfflinePlayer;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
/**
* This subcommand is used to search for a user, and to view all matches' data.
@ -51,7 +50,7 @@ public class SearchCommand extends SubCommand {
return true;
}
sender.sendMessage(Phrase.CMD_SEARCH_SEARCHING + "");
final RslTask searchTask = new RslBukkitRunnable<Plan>("SearchTask: " + Arrays.toString(args)) {
final RslTask searchTask =plugin.getRunnableFactory().createNew(new RslRunnable("SearchTask: " + Arrays.toString(args)) {
@Override
public void run() {
try {
@ -70,7 +69,7 @@ public class SearchCommand extends SubCommand {
this.cancel();
}
}
}.runTaskAsynchronously();
}).runTaskAsynchronously();
return true;
}
}

View File

@ -4,14 +4,13 @@ import com.djrapitops.javaplugin.command.CommandType;
import com.djrapitops.javaplugin.command.SubCommand;
import com.djrapitops.javaplugin.command.sender.ISender;
import com.djrapitops.javaplugin.task.RslBukkitRunnable;
import com.djrapitops.javaplugin.task.RslRunnable;
import main.java.com.djrapitops.plan.Log;
import main.java.com.djrapitops.plan.Permissions;
import main.java.com.djrapitops.plan.Phrase;
import main.java.com.djrapitops.plan.Plan;
import main.java.com.djrapitops.plan.database.Database;
import main.java.com.djrapitops.plan.utilities.ManageUtils;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
/**
* This manage subcommand is used to backup a database to a .db file.
@ -62,7 +61,7 @@ public class ManageBackupCommand extends SubCommand {
return true;
}
final Database copyFromDB = database;
(new RslBukkitRunnable<Plan>("BackupTask") {
plugin.getRunnableFactory().createNew(new RslRunnable("BackupTask") {
@Override
public void run() {
sender.sendMessage(Phrase.MANAGE_PROCESS_START.parse());

View File

@ -4,6 +4,7 @@ import com.djrapitops.javaplugin.command.CommandType;
import com.djrapitops.javaplugin.command.SubCommand;
import com.djrapitops.javaplugin.command.sender.ISender;
import com.djrapitops.javaplugin.task.RslBukkitRunnable;
import com.djrapitops.javaplugin.task.RslRunnable;
import main.java.com.djrapitops.plan.Log;
import main.java.com.djrapitops.plan.Permissions;
import main.java.com.djrapitops.plan.Phrase;
@ -59,7 +60,7 @@ public class ManageCleanCommand extends SubCommand {
}
final Database clearThisDB = clearDB;
(new RslBukkitRunnable<Plan>("DBCleanTask") {
plugin.getRunnableFactory().createNew(new RslRunnable("DBCleanTask") {
@Override
public void run() {
sender.sendMessage(Phrase.MANAGE_PROCESS_START.parse());

View File

@ -4,6 +4,7 @@ import com.djrapitops.javaplugin.command.CommandType;
import com.djrapitops.javaplugin.command.SubCommand;
import com.djrapitops.javaplugin.command.sender.ISender;
import com.djrapitops.javaplugin.task.RslBukkitRunnable;
import com.djrapitops.javaplugin.task.RslRunnable;
import java.sql.SQLException;
import java.util.Arrays;
import main.java.com.djrapitops.plan.Log;
@ -11,8 +12,6 @@ import main.java.com.djrapitops.plan.Permissions;
import main.java.com.djrapitops.plan.Phrase;
import main.java.com.djrapitops.plan.Plan;
import main.java.com.djrapitops.plan.database.Database;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
/**
* This manage subcommand is used to clear a database of all data.
@ -65,7 +64,7 @@ public class ManageClearCommand extends SubCommand {
}
final Database clearThisDB = clearDB;
(new RslBukkitRunnable<Plan>("DBClearTask") {
plugin.getRunnableFactory().createNew(new RslRunnable("DBClearTask") {
@Override
public void run() {
sender.sendMessage(Phrase.MANAGE_PROCESS_START.parse());

View File

@ -3,7 +3,7 @@ package main.java.com.djrapitops.plan.command.commands.manage;
import com.djrapitops.javaplugin.command.CommandType;
import com.djrapitops.javaplugin.command.SubCommand;
import com.djrapitops.javaplugin.command.sender.ISender;
import com.djrapitops.javaplugin.task.RslBukkitRunnable;
import com.djrapitops.javaplugin.task.RslRunnable;
import com.djrapitops.javaplugin.task.RslTask;
import java.util.Arrays;
import java.util.List;
@ -63,12 +63,12 @@ public class ManageImportCommand extends SubCommand {
return true;
}
String[] arguments = new String[args.length-1];
String[] arguments = new String[args.length - 1];
for (int i = 1; i < args.length; i++) {
arguments[i-1] = args[i];
arguments[i - 1] = args[i];
}
final Importer importer = importPlugins.get(importFromPlugin);
RslTask asyncImportTask = new RslBukkitRunnable<Plan>("ImportTask") {
RslTask asyncImportTask = plugin.getRunnableFactory().createNew(new RslRunnable("ImportTask") {
@Override
public void run() {
sender.sendMessage(Phrase.MANAGE_IMPORTING + "");
@ -80,7 +80,7 @@ public class ManageImportCommand extends SubCommand {
}
this.cancel();
}
}.runTaskAsynchronously();
}).runTaskAsynchronously();
return true;
}
@ -88,7 +88,7 @@ public class ManageImportCommand extends SubCommand {
sender.sendMessage(Phrase.CMD_FOOTER.parse());
Map<String, Importer> importers = ImportUtils.getImporters();
for (String key : importers.keySet()) {
sender.sendMessage(Phrase.CMD_BALL+" "+key+": "+importers.get(key).getInfo());
sender.sendMessage(Phrase.CMD_BALL + " " + key + ": " + importers.get(key).getInfo());
}
sender.sendMessage(Phrase.CMD_FOOTER.parse());
}

View File

@ -4,6 +4,7 @@ import com.djrapitops.javaplugin.command.CommandType;
import com.djrapitops.javaplugin.command.SubCommand;
import com.djrapitops.javaplugin.command.sender.ISender;
import com.djrapitops.javaplugin.task.RslBukkitRunnable;
import com.djrapitops.javaplugin.task.RslRunnable;
import java.util.Arrays;
import java.util.Collection;
import java.util.UUID;
@ -13,8 +14,6 @@ import main.java.com.djrapitops.plan.Phrase;
import main.java.com.djrapitops.plan.Plan;
import main.java.com.djrapitops.plan.database.Database;
import main.java.com.djrapitops.plan.utilities.ManageUtils;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
/**
* This manage subcommand is used to move all data from one database to another.
@ -89,7 +88,7 @@ public class ManageMoveCommand extends SubCommand {
final Database moveFromDB = fromDatabase;
final Database moveToDB = toDatabase;
(new RslBukkitRunnable<Plan>("DBMoveTask") {
plugin.getRunnableFactory().createNew(new RslRunnable("DBMoveTask") {
@Override
public void run() {
final Collection<UUID> uuids = ManageUtils.getUUIDS(moveFromDB);

View File

@ -3,7 +3,7 @@ package main.java.com.djrapitops.plan.command.commands.manage;
import com.djrapitops.javaplugin.command.CommandType;
import com.djrapitops.javaplugin.command.SubCommand;
import com.djrapitops.javaplugin.command.sender.ISender;
import com.djrapitops.javaplugin.task.RslBukkitRunnable;
import com.djrapitops.javaplugin.task.RslRunnable;
import java.sql.SQLException;
import java.util.Arrays;
import java.util.UUID;
@ -13,8 +13,6 @@ import main.java.com.djrapitops.plan.Phrase;
import main.java.com.djrapitops.plan.Plan;
import main.java.com.djrapitops.plan.utilities.MiscUtils;
import main.java.com.djrapitops.plan.utilities.uuid.UUIDUtility;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
/**
* This manage subcommand is used to remove a single player's data from the
@ -46,7 +44,7 @@ public class ManageRemoveCommand extends SubCommand {
String playerName = MiscUtils.getPlayerName(args, sender, Permissions.MANAGE);
(new RslBukkitRunnable<Plan>("DBRemoveTask " + playerName) {
plugin.getRunnableFactory().createNew(new RslRunnable("DBRemoveTask " + playerName) {
@Override
public void run() {
UUID uuid;
@ -85,7 +83,7 @@ public class ManageRemoveCommand extends SubCommand {
}
this.cancel();
}
}).runTaskAsynchronously(plugin);
}).runTaskAsynchronously();
return true;
}
}

View File

@ -4,6 +4,7 @@ import com.djrapitops.javaplugin.command.CommandType;
import com.djrapitops.javaplugin.command.SubCommand;
import com.djrapitops.javaplugin.command.sender.ISender;
import com.djrapitops.javaplugin.task.RslBukkitRunnable;
import com.djrapitops.javaplugin.task.RslRunnable;
import com.djrapitops.javaplugin.task.RslTask;
import java.io.File;
import java.util.Arrays;
@ -16,8 +17,6 @@ import main.java.com.djrapitops.plan.Plan;
import main.java.com.djrapitops.plan.database.Database;
import main.java.com.djrapitops.plan.database.databases.SQLiteDB;
import main.java.com.djrapitops.plan.utilities.ManageUtils;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
/**
* This manage subcommand is used to restore a backup.db file in the
@ -72,7 +71,7 @@ public class ManageRestoreCommand extends SubCommand {
return true;
}
final Database copyToDB = database;
RslTask asyncRestoreTask = new RslBukkitRunnable<Plan>("RestoreTask") {
RslTask asyncRestoreTask = plugin.getRunnableFactory().createNew(new RslRunnable("RestoreTask") {
@Override
public void run() {
String backupDBName = args[0];
@ -109,7 +108,7 @@ public class ManageRestoreCommand extends SubCommand {
}
this.cancel();
}
}.runTaskAsynchronously();
}).runTaskAsynchronously();
} catch (NullPointerException e) {
sender.sendMessage(Phrase.MANAGE_DATABASE_FAILURE + "");
}

View File

@ -1,6 +1,7 @@
package main.java.com.djrapitops.plan.data.cache;
import com.djrapitops.javaplugin.task.RslBukkitRunnable;
import com.djrapitops.javaplugin.task.RslRunnable;
import com.djrapitops.javaplugin.task.RslTask;
import java.sql.SQLException;
import java.util.ArrayList;
@ -34,6 +35,13 @@ import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.entity.Player;
import static org.bukkit.Bukkit.getOfflinePlayer;
import static org.bukkit.Bukkit.getOfflinePlayer;
import static org.bukkit.Bukkit.getOfflinePlayer;
import static org.bukkit.Bukkit.getOfflinePlayer;
import static org.bukkit.Bukkit.getOfflinePlayer;
import static org.bukkit.Bukkit.getOfflinePlayer;
import static org.bukkit.Bukkit.getOfflinePlayer;
import static org.bukkit.Bukkit.getOfflinePlayer;
/**
* This Class contains the Cache.
@ -115,7 +123,7 @@ public class DataCacheHandler extends LocationCache {
*/
public void startQueues() {
clearTask = new DataCacheClearQueue(this);
saveTask = new DataCacheSaveQueue(plugin, clearTask);
saveTask = new DataCacheSaveQueue(plugin, this);
getTask = new DataCacheGetQueue(plugin);
processTask = new DataCacheProcessQueue(this);
}
@ -139,7 +147,7 @@ public class DataCacheHandler extends LocationCache {
} else {
clearAfterXsaves = configValue;
}
RslTask asyncPeriodicCacheSaveTask = new RslBukkitRunnable<Plan>("PeriodicCacheSaveTask") {
RslTask asyncPeriodicCacheSaveTask = plugin.getRunnableFactory().createNew(new RslRunnable("PeriodicCacheSaveTask") {
private int timesSaved = 0;
@Override
@ -159,12 +167,12 @@ public class DataCacheHandler extends LocationCache {
saveUnsavedTPSHistory();
timesSaved++;
} catch (Exception e) {
Log.toLog(this.getClass().getName() + "(" + this.getTaskName() + ")", e);
Log.toLog(this.getClass().getName() + "(" + this.getName() + ")", e);
} finally {
periodicTaskIsSaving = false;
}
}
}.runTaskTimerAsynchronously(60 * 20 * minutes, 60 * 20 * minutes);
}).runTaskTimerAsynchronously(60 * 20 * minutes, 60 * 20 * minutes);
}
/**
@ -518,7 +526,7 @@ public class DataCacheHandler extends LocationCache {
* Calls all the methods that are ran when PlayerJoinEvent is fired
*/
public void handleReload() {
RslTask asyncReloadCacheUpdateTask = (new RslBukkitRunnable<Plan>("ReloadCacheUpdateTask") {
RslTask asyncReloadCacheUpdateTask = plugin.getRunnableFactory().createNew(new RslRunnable("ReloadCacheUpdateTask") {
@Override
public void run() {
for (Player player : Bukkit.getOnlinePlayers()) {

View File

@ -1,8 +1,7 @@
package main.java.com.djrapitops.plan.data.cache.queue;
import com.djrapitops.javaplugin.task.RslBukkitRunnable;
import com.djrapitops.javaplugin.task.RslRunnable;
import java.util.concurrent.BlockingQueue;
import main.java.com.djrapitops.plan.Plan;
/**
* Abstract class representing a queue consumer.
@ -10,7 +9,7 @@ import main.java.com.djrapitops.plan.Plan;
* @author Rsl1122
* @param <T>
*/
public abstract class Consumer<T> extends RslBukkitRunnable<Plan> {
public abstract class Consumer<T> extends RslRunnable {
boolean run;
final BlockingQueue<T> queue;

View File

@ -46,15 +46,19 @@ public class DataCacheGetQueue extends Queue<Map<UUID, List<DBCallableProcessor>
Log.debug(uuid + ": Scheduling for get");
try {
Map<UUID, List<DBCallableProcessor>> map = new HashMap<>();
if (map.get(uuid) == null) {
map.put(uuid, new ArrayList<>());
}
map.get(uuid).addAll(Arrays.asList(processors));
map.put(uuid, Arrays.asList(processors));
queue.add(map);
} catch (IllegalStateException e) {
Log.error(Phrase.ERROR_TOO_SMALL_QUEUE.parse("Get Queue", Settings.PROCESS_GET_LIMIT.getNumber() + ""));
}
}
public boolean containsUUIDtoBeCached(UUID uuid) {
if (uuid == null) {
return false;
}
return new ArrayList<>(queue).stream().anyMatch((map) -> (map.get(uuid) != null && map.get(uuid).size() >= 2)); // Map has 2 processors if being cached
}
}
class GetConsumer extends Consumer<Map<UUID, List<DBCallableProcessor>>> {

View File

@ -66,7 +66,10 @@ public class DataCacheProcessQueue extends Queue<HandlingInfo> {
* @return true/false
*/
public boolean containsUUID(UUID uuid) {
return new ArrayList<>(queue).stream().map(d -> d.getUuid()).collect(Collectors.toList()).contains(uuid);
if (uuid == null) {
return false;
}
return new ArrayList<>(queue).stream().anyMatch(info -> info.getUuid().equals(uuid));
}
}
@ -84,6 +87,10 @@ class ProcessConsumer extends Consumer<HandlingInfo> {
if (handler == null) {
return;
}
if (handler.getGetTask().containsUUIDtoBeCached(info.getUuid())) { // Wait for get queue.
queue.add(info);
return;
}
Log.debug(info.getUuid() + ": Processing type: " + info.getType().name());
DBCallableProcessor p = new DBCallableProcessor() {
@Override
@ -105,6 +112,7 @@ class ProcessConsumer extends Consumer<HandlingInfo> {
}
class ProcessSetup extends Setup<HandlingInfo> {
ProcessSetup(BlockingQueue<HandlingInfo> q, DataCacheHandler h) {
super(new ProcessConsumer(q, h), new ProcessConsumer(q, h));
}

View File

@ -12,6 +12,7 @@ import main.java.com.djrapitops.plan.Phrase;
import main.java.com.djrapitops.plan.Plan;
import main.java.com.djrapitops.plan.Settings;
import main.java.com.djrapitops.plan.data.UserData;
import main.java.com.djrapitops.plan.data.cache.DataCacheHandler;
import main.java.com.djrapitops.plan.database.Database;
/**
@ -20,18 +21,17 @@ import main.java.com.djrapitops.plan.database.Database;
* @author Rsl1122
* @since 3.0.0
*/
public class DataCacheSaveQueue extends Queue<UserData>{
public class DataCacheSaveQueue extends Queue<UserData> {
/**
* Class constructor, starts the new Thread for saving.
*
* @param plugin current instance of Plan
* @param clear current instance of the Clear task to schedule clear if
* UserData.clearAfterSave() is true
* @param handler DataCacheHandler
*/
public DataCacheSaveQueue(Plan plugin, DataCacheClearQueue clear) {
public DataCacheSaveQueue(Plan plugin, DataCacheHandler handler) {
super(new ArrayBlockingQueue(Settings.PROCESS_SAVE_LIMIT.getNumber()));
setup = new SaveSetup(queue, clear, plugin.getDB());
setup = new SaveSetup(queue, handler, plugin.getDB());
setup.go();
}
@ -84,19 +84,22 @@ public class DataCacheSaveQueue extends Queue<UserData>{
* @return true/false
*/
public boolean containsUUID(UUID uuid) {
return new ArrayList<>(queue).stream().map(d -> d.getUuid()).collect(Collectors.toList()).contains(uuid);
if (uuid == null) {
return false;
}
return new ArrayList<>(queue).stream().anyMatch(d -> d.getUuid().equals(uuid));
}
}
class SaveConsumer extends Consumer<UserData> {
private Database db;
private DataCacheClearQueue clear;
private DataCacheHandler handler;
SaveConsumer(BlockingQueue q, DataCacheClearQueue clear, Database db) {
SaveConsumer(BlockingQueue q, DataCacheHandler handler, Database db) {
super(q, "SaveQueueConsumer");
this.db = db;
this.clear = clear;
this.handler = handler;
run = true;
}
@ -106,14 +109,18 @@ class SaveConsumer extends Consumer<UserData> {
return;
}
UUID uuid = data.getUuid();
if (handler.getProcessTask().containsUUID(uuid)) { // Wait for process queue.
queue.add(data);
return;
}
Log.debug(uuid + ": Saving: " + uuid);
try {
db.saveUserData(data);
data.stopAccessing();
Log.debug(uuid + ": Saved!");
if (data.shouldClearAfterSave()) {
if (clear != null) {
clear.scheduleForClear(uuid);
if (handler != null) {
handler.getClearTask().scheduleForClear(uuid);
}
}
} catch (SQLException ex) {
@ -127,14 +134,15 @@ class SaveConsumer extends Consumer<UserData> {
if (db != null) {
db = null;
}
if (clear != null) {
clear = null;
if (handler != null) {
handler = null;
}
}
}
class SaveSetup extends Setup<UserData>{
SaveSetup(BlockingQueue<UserData> q, DataCacheClearQueue clear, Database db) {
super(new SaveConsumer(q, clear, db), new SaveConsumer(q, clear, db));
class SaveSetup extends Setup<UserData> {
SaveSetup(BlockingQueue<UserData> q, DataCacheHandler handler, Database db) {
super(new SaveConsumer(q, handler, db), new SaveConsumer(q, handler, db));
}
}

View File

@ -1,6 +1,5 @@
package main.java.com.djrapitops.plan.data.cache.queue;
import com.djrapitops.javaplugin.task.RslBukkitRunnable;
import main.java.com.djrapitops.plan.Plan;
/**
@ -10,7 +9,7 @@ import main.java.com.djrapitops.plan.Plan;
* @param <T> Object this queue consumes.
*/
public abstract class Setup<T> {
private final Consumer<T>[] consumers;
/**
@ -21,13 +20,13 @@ public abstract class Setup<T> {
public Setup(Consumer<T>... consumers) {
this.consumers = consumers;
}
void go() {
for (Consumer<T> consumer : consumers) {
consumer.runTaskAsynchronously();
Plan.getInstance().getRunnableFactory().createNew(consumer).runTaskAsynchronously();
}
}
void stop() {
for (Consumer<T> consumer : consumers) {
consumer.stop();

View File

@ -1,6 +1,7 @@
package main.java.com.djrapitops.plan.data.listeners;
import com.djrapitops.javaplugin.task.RslBukkitRunnable;
import com.djrapitops.javaplugin.task.RslRunnable;
import com.djrapitops.javaplugin.task.RslTask;
import java.util.UUID;
import main.java.com.djrapitops.plan.Log;
@ -57,7 +58,7 @@ public class PlanPlayerListener implements Listener {
UUID uuid = player.getUniqueId();
handler.startSession(uuid);
Log.debug(uuid + ": PlayerJoinEvent");
RslTask asyncNewPlayerCheckTask = new RslBukkitRunnable<Plan>("NewPlayerCheckTask") {
RslTask asyncNewPlayerCheckTask = plugin.getRunnableFactory().createNew(new RslRunnable("NewPlayerCheckTask") {
@Override
public void run() {
LoginInfo loginInfo = new LoginInfo(uuid, MiscUtils.getTime(), player.getAddress().getAddress(), player.isBanned(), player.getDisplayName(), player.getGameMode(), 1);
@ -72,7 +73,7 @@ public class PlanPlayerListener implements Listener {
Log.debug(uuid + ": PlayerJoinEvent_AsyncTask_END, New:" + isNewPlayer);
this.cancel();
}
}.runTaskAsynchronously();
}).runTaskAsynchronously();
Log.debug(uuid + ": PlayerJoinEvent_END");
}

View File

@ -1,7 +1,7 @@
package main.java.com.djrapitops.plan.data.listeners;
import com.djrapitops.javaplugin.api.TimeAmount;
import com.djrapitops.javaplugin.task.RslBukkitRunnable;
import com.djrapitops.javaplugin.task.RslRunnable;
import java.util.ArrayList;
import java.util.List;
import main.java.com.djrapitops.plan.Plan;
@ -14,7 +14,7 @@ import main.java.com.djrapitops.plan.utilities.MiscUtils;
*
* @author Rsl1122
*/
public class TPSCountTimer extends RslBukkitRunnable<Plan> {
public class TPSCountTimer extends RslRunnable {
private long lastCheckNano;
private final Plan plugin;

View File

@ -1,6 +1,7 @@
package main.java.com.djrapitops.plan.database.databases;
import com.djrapitops.javaplugin.task.RslBukkitRunnable;
import com.djrapitops.javaplugin.task.RslRunnable;
import java.net.InetAddress;
import java.sql.Connection;
import java.sql.SQLException;
@ -67,7 +68,7 @@ public abstract class SQLDB extends Database {
*/
public void startConnectionPingTask(Plan plugin) throws IllegalArgumentException, IllegalStateException {
// Maintains Connection.
new RslBukkitRunnable<Plan>("DBConnectionPingTask " + getName()) {
plugin.getRunnableFactory().createNew(new RslRunnable("DBConnectionPingTask " + getName()) {
@Override
public void run() {
try {
@ -78,7 +79,7 @@ public abstract class SQLDB extends Database {
connection = getNewConnection();
}
}
}.runTaskTimerAsynchronously(60 * 20, 60 * 20);
}).runTaskTimerAsynchronously(60 * 20, 60 * 20);
}
/**
@ -150,7 +151,7 @@ public abstract class SQLDB extends Database {
*
*/
public void convertBukkitDataToDB() {
new RslBukkitRunnable<Plan>("BukkitDataConversionTask") {
plugin.getRunnableFactory().createNew(new RslRunnable("BukkitDataConversionTask") {
@Override
public void run() {
try {
@ -177,7 +178,7 @@ public abstract class SQLDB extends Database {
this.cancel();
}
}
}.runTaskAsynchronously();
}).runTaskAsynchronously();
}
/**

View File

@ -1,6 +1,7 @@
package main.java.com.djrapitops.plan.ui.webserver;
import com.djrapitops.javaplugin.task.RslBukkitRunnable;
import com.djrapitops.javaplugin.task.RslRunnable;
import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
@ -60,7 +61,7 @@ public class WebSocketServer {
System.exit(1);
}
//Run server in seperate thread
(new RslBukkitRunnable<Plan>("WebServerTask") {
plugin.getRunnableFactory().createNew(new RslRunnable("WebServerTask") {
@Override
public void run() {
while (!shutdown) {

View File

@ -2,6 +2,7 @@ package main.java.com.djrapitops.plan.utilities.analysis;
import com.djrapitops.javaplugin.api.TimeAmount;
import com.djrapitops.javaplugin.task.RslBukkitRunnable;
import com.djrapitops.javaplugin.task.RslRunnable;
import com.djrapitops.javaplugin.task.RslTask;
import java.util.ArrayList;
import main.java.com.djrapitops.plan.data.additional.HookHandler;
@ -77,7 +78,7 @@ public class Analysis {
plugin.processStatus().startExecution("Analysis");
log(Phrase.ANALYSIS_START + "");
// Async task for Analysis
RslTask asyncAnalysisTask = (new RslBukkitRunnable<Plan>("AnalysisTask") {
RslTask asyncAnalysisTask = plugin.getRunnableFactory().createNew(new RslRunnable("AnalysisTask") {
@Override
public void run() {
taskId = this.getTaskId();

View File

@ -75,7 +75,7 @@ public class TestInit {
when(planMock.processStatus()).thenReturn(process);
BenchmarkUtil bench = new BenchmarkUtil();
when(planMock.benchmark()).thenReturn(bench);
Plan.setInstance(planMock);
Plan.setInstance(Plan.class, planMock);
// Mockito.doReturn("0.0.0.0").when(planMock).getServer().getIp();
Settings.DEBUG.setValue(true);
return true;