Use Processor (still needs something todo)

This commit is contained in:
Fuzzlemann 2017-08-20 14:47:36 +02:00
parent 1ed32a8f12
commit 9db4a74154
6 changed files with 63 additions and 84 deletions

View File

@ -11,7 +11,6 @@ import org.bukkit.configuration.file.FileConfiguration;
* @author Rsl1122
* @since 3.5.0
*/
// TODO Move the auto generation to the correct location (Customization.Plugins -> Plugins)
public class PluginConfigSectionHandler {
private final Plan plan;

View File

@ -50,55 +50,50 @@ public class DataCacheGetQueue extends Queue<Map<UUID, List<DBCallableProcessor>
}
}
boolean containsUUIDtoBeCached(UUID uuid) {
return uuid != null && queue.stream()
.map(map -> map.get(uuid))
.filter(Objects::nonNull)
.anyMatch(list -> list.size() >= 2);
}
}
@Deprecated
class GetConsumer extends Consumer<Map<UUID, List<DBCallableProcessor>>> {
@Deprecated
class GetConsumer extends Consumer<Map<UUID, List<DBCallableProcessor>>> {
private Database db;
private Database db;
GetConsumer(BlockingQueue<Map<UUID, List<DBCallableProcessor>>> q, Database db) {
super(q, "GetQueueConsumer");
this.db = db;
}
@Override
protected void consume(Map<UUID, List<DBCallableProcessor>> processors) {
if (!Verify.notNull(processors, db)) {
return;
GetConsumer(BlockingQueue<Map<UUID, List<DBCallableProcessor>>> q, Database db) {
super(q, "GetQueueConsumer");
this.db = db;
}
try {
for (Map.Entry<UUID, List<DBCallableProcessor>> entrySet : processors.entrySet()) {
UUID uuid = entrySet.getKey();
List<DBCallableProcessor> processorsList = entrySet.getValue();
if (uuid == null || Verify.isEmpty(processorsList)) {
continue;
}
Log.debug("Database", uuid + ": Get, For:" + processorsList.size());
db.giveUserDataToProcessors(uuid, processorsList);
@Override
protected void consume(Map<UUID, List<DBCallableProcessor>> processors) {
if (!Verify.notNull(processors, db)) {
return;
}
try {
for (Map.Entry<UUID, List<DBCallableProcessor>> entrySet : processors.entrySet()) {
UUID uuid = entrySet.getKey();
List<DBCallableProcessor> processorsList = entrySet.getValue();
if (uuid == null || Verify.isEmpty(processorsList)) {
continue;
}
Log.debug("Database", uuid + ": Get, For:" + processorsList.size());
db.giveUserDataToProcessors(uuid, processorsList);
}
} catch (Exception ex) {
Log.toLog(this.getClass().getName(), ex);
}
}
@Override
protected void clearVariables() {
if (db != null) {
db = null;
}
} catch (Exception ex) {
Log.toLog(this.getClass().getName(), ex);
}
}
@Override
protected void clearVariables() {
if (db != null) {
db = null;
@Deprecated
class GetSetup extends Setup<Map<UUID, List<DBCallableProcessor>>> {
GetSetup(BlockingQueue<Map<UUID, List<DBCallableProcessor>>> q, Database db) {
super(new GetConsumer(q, db), new GetConsumer(q, db));
}
}
}
@Deprecated
class GetSetup extends Setup<Map<UUID, List<DBCallableProcessor>>> {
GetSetup(BlockingQueue<Map<UUID, List<DBCallableProcessor>>> q, Database db) {
super(new GetConsumer(q, db), new GetConsumer(q, db));
}
}

View File

@ -4,9 +4,8 @@ import com.djrapitops.plugin.utilities.Verify;
import main.java.com.djrapitops.plan.Log;
import main.java.com.djrapitops.plan.data.cache.DBCallableProcessor;
import main.java.com.djrapitops.plan.data.cache.DataCacheHandler;
import main.java.com.djrapitops.plan.data.handling.info.HandlingInfo;
import main.java.com.djrapitops.plan.queue.processing.Processor;
import java.util.UUID;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingQueue;
@ -20,7 +19,7 @@ import java.util.concurrent.BlockingQueue;
// TODO Change Processing Queue to use more generic object as processing.
// GOAL: Processing queue can be used to process query results from the database
// & for processing events into statements.
public class DataCacheProcessQueue extends Queue<HandlingInfo> {
public class DataCacheProcessQueue extends Queue<Processor> {
/**
* Class constructor, starts the new Thread for processing.
@ -38,53 +37,33 @@ public class DataCacheProcessQueue extends Queue<HandlingInfo> {
*
* @param info object that extends HandlingInfo.
*/
public void addToPool(HandlingInfo info) {
public void addToPool(Processor info) {
try {
queue.add(info);
} catch (IllegalStateException e) {
Log.toLog(this.getClass().getName(), e);
}
}
/**
* Check whether or not the queue contains a HandlingInfo object with the
* uuid.
*
* @param uuid UUID of the player.
* @return true/false
*/
public boolean containsUUID(UUID uuid) {
return uuid != null && queue.stream().anyMatch(info -> info.getUuid().equals(uuid));
}
}
class ProcessConsumer extends Consumer<HandlingInfo> {
class ProcessConsumer extends Consumer<Processor> {
private DataCacheHandler handler;
ProcessConsumer(BlockingQueue<HandlingInfo> q, DataCacheHandler h) {
ProcessConsumer(BlockingQueue<Processor> q, DataCacheHandler h) {
super(q, "ProcessQueueConsumer");
handler = h;
}
@Override
protected void consume(HandlingInfo info) {
protected void consume(Processor info) {
if (!Verify.notNull(handler, info)) {
return;
}
if (handler.getGetTask().containsUUIDtoBeCached(info.getUuid())) { // Wait for get queue.
queue.add(info);
return;
}
DBCallableProcessor p = data -> info.process();
DBCallableProcessor p = data -> {
if (!info.process(data)) {
Log.error("Attempted to process data for wrong uuid: W:" + data.getUuid() + " | R:" + info.getUuid() + " Type:" + info.getType().name());
}
};
handler.getUserDataForProcessing(p, info.getUuid());
//TODO handler.getUserDataForProcessing(p, info.getUuid());
}
@Override
@ -95,9 +74,9 @@ class ProcessConsumer extends Consumer<HandlingInfo> {
}
}
class ProcessSetup extends Setup<HandlingInfo> {
class ProcessSetup extends Setup<Processor> {
ProcessSetup(BlockingQueue<HandlingInfo> q, DataCacheHandler h) {
ProcessSetup(BlockingQueue<Processor> q, DataCacheHandler h) {
super(new ProcessConsumer(q, h), new ProcessConsumer(q, h));
}
}

View File

@ -89,10 +89,10 @@ class SaveConsumer extends Consumer<UserData> {
}
UUID uuid = data.getUuid();
if (handler.getProcessTask().containsUUID(uuid)) { // Wait for process queue.
/*TODO if (handler.getProcessTask().containsUUID(uuid)) { // Wait for process queue.
queue.add(data);
return;
}
}*/
try {
db.saveUserData(data);

View File

@ -9,6 +9,12 @@ package main.java.com.djrapitops.plan.queue.processing;
*
* @author Rsl1122
*/
public interface Processor<T> {
public void process(T object);
public abstract class Processor<T> {
private T processed;
public Processor(T processed) {
this.processed = processed;
}
public abstract void process();
}

View File

@ -30,7 +30,7 @@ public enum Html {
COLOR_F("<span class=\"white\">"),
//
FONT_AWESOME_ICON("<i class=\"fa fa-${0}\" aria-hidden=\"true\"></i>"),
MINOTAR_SMALL_IMG("<img style=\"float: left; padding: 2px 2px 0px 2px\" alt=\"${0}\" src=\"https://minotar.net/avatar/${0}/19\">"),
@Deprecated MINOTAR_SMALL_IMG("<img style=\"float: left; padding: 2px 2px 0px 2px\" alt=\"${0}\" src=\"https://minotar.net/avatar/${0}/19\">"),
SPAN("${0}</span>"),
BUTTON("<a class=\"button\" href=\"${0}\">${1}</a>"),
BUTTON_CLASS("class=\"button\""),
@ -38,11 +38,11 @@ public enum Html {
LINK_EXTERNAL("<a class=\"link\" target=\"_blank\" href=\"${0}\">${1}</a>"),
LINK_CLASS("class=\"link\""),
IMG("<img src=\"${0}\">"),
COLUMNS_DIV_WRAPPER("<div class=\"columns\">${0}</div>"),
COLUMN_DIV_WRAPPER("<div class=\"about box column\">${0}</div>"),
HEADER("<div class=\"headerbox\" style=\"width: 95%;\"><div class=\"header-icon\"><div class=\"header-label\"><i class=\"fa fa-cube\" aria-hidden=\"true\"></i><span class=\"header-text\"> ${0}</span></div></div></div>"),
PLUGIN_DATA_WRAPPER("<div class=\"plugin-data\">${0}</div>"),
PLUGIN_CONTAINER_START("<div class=\"plugin-container\">"),
@Deprecated COLUMNS_DIV_WRAPPER("<div class=\"columns\">${0}</div>"),
@Deprecated COLUMN_DIV_WRAPPER("<div class=\"about box column\">${0}</div>"),
@Deprecated HEADER("<div class=\"headerbox\" style=\"width: 95%;\"><div class=\"header-icon\"><div class=\"header-label\"><i class=\"fa fa-cube\" aria-hidden=\"true\"></i><span class=\"header-text\"> ${0}</span></div></div></div>"),
@Deprecated PLUGIN_DATA_WRAPPER("<div class=\"plugin-data\">${0}</div>"),
@Deprecated PLUGIN_CONTAINER_START("<div class=\"plugin-container\">"),
//
TABLE_START_2("<table class=\"sortable table\"><thead><tr><th>${0}</th><th>${1}</th></tr></thead><tbody>"),
TABLE_START_3("<table class=\"sortable table\"><thead><tr><th>${0}</th><th>${1}</th><th>${2}</th></tr></thead><tbody>"),
@ -57,7 +57,7 @@ public enum Html {
TABLELINE_PLAYERS("<tr><td>${0}</td><td>${1}</td><td sorttable_customkey=\"${2}\">${3}</td><td>${4}</td><td sorttable_customkey=\"${5}\">${6}</td>" + "<td sorttable_customkey=\"${7}\">${8}</td><td>${9}</td></tr>"),
TABLELINE_3_CUSTOMKEY("<tr><td sorttable_customkey=\"${0}\">${1}</td><td sorttable_customkey=\"${2}\">${3}</td><td sorttable_customkey=\"${4}\">${5}</td></tr>"),
TABLELINE_3_CUSTOMKEY_1("<tr><td sorttable_customkey=\"${0}\">${1}</td><td>${2}</td><td>${3}</td></tr>"),
ERROR_TABLE_2(TABLELINE_2.parse("No data", "No data")),
@Deprecated ERROR_TABLE_2(TABLELINE_2.parse("No data", "No data")),
TABLE_END("</tbody></table>"); // KILLDATA_NONE("No Kills"),
private String html;