From ba51f803ba5c6af761d8a672be6ff32421bb518a Mon Sep 17 00:00:00 2001 From: Luck Date: Wed, 25 Apr 2018 17:15:30 +0100 Subject: [PATCH] add more logging to the importer --- .../me/lucko/luckperms/common/backup/Importer.java | 14 +++++++++++--- .../luckperms/common/locale/message/Message.java | 1 + 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/common/src/main/java/me/lucko/luckperms/common/backup/Importer.java b/common/src/main/java/me/lucko/luckperms/common/backup/Importer.java index 17f9cd3e1..4b1817195 100644 --- a/common/src/main/java/me/lucko/luckperms/common/backup/Importer.java +++ b/common/src/main/java/me/lucko/luckperms/common/backup/Importer.java @@ -30,6 +30,7 @@ import com.google.common.base.Strings; import com.google.common.collect.ImmutableSet; import com.google.common.collect.ListMultimap; import com.google.common.collect.MultimapBuilder; +import com.google.common.util.concurrent.ThreadFactoryBuilder; import me.lucko.luckperms.common.command.CommandManager; import me.lucko.luckperms.common.command.CommandResult; @@ -89,6 +90,8 @@ public class Importer implements Runnable { // start an update task in the background - we'll #join this later CompletableFuture updateTask = CompletableFuture.runAsync(() -> this.commandManager.getPlugin().getUpdateTaskBuffer().requestDirectly()); + this.notify.forEach(s -> Message.IMPORT_INFO.send(s, "Processing commands...")); + // form instances for all commands, and register them int index = 1; for (String command : this.commandList) { @@ -106,15 +109,18 @@ public class Importer implements Runnable { // holder id --> commands ListMultimap sections = MultimapBuilder.linkedHashKeys().arrayListValues().build(); for (ImportCommand cmd : this.commands) { - String target = Strings.nullToEmpty(cmd.getTarget()); - sections.put(target, cmd); + sections.put(Strings.nullToEmpty(cmd.getTarget()), cmd); } + this.notify.forEach(s -> Message.IMPORT_INFO.send(s, "Waiting for initial update task to complete...")); + // join the update task future before scheduling command executions updateTask.join(); + this.notify.forEach(s -> Message.IMPORT_INFO.send(s, "Setting up command executor...")); + // create a threadpool for the processing - ExecutorService executor = Executors.newFixedThreadPool(128); + ExecutorService executor = Executors.newFixedThreadPool(128, new ThreadFactoryBuilder().setNameFormat("luckperms-importer-%d").build()); // A set of futures, which are really just the processes we need to wait for. Set> futures = new HashSet<>(); @@ -138,6 +144,8 @@ public class Importer implements Runnable { // all of the threads have been scheduled now and are running. we just need to wait for them all to complete CompletableFuture overallFuture = CompletableFuture.allOf(futures.toArray(new CompletableFuture[futures.size()])); + this.notify.forEach(s -> Message.IMPORT_INFO.send(s, "All commands have been processed and scheduled - now waiting for the execution to complete.")); + while (true) { try { overallFuture.get(2, TimeUnit.SECONDS); diff --git a/common/src/main/java/me/lucko/luckperms/common/locale/message/Message.java b/common/src/main/java/me/lucko/luckperms/common/locale/message/Message.java index cbee35478..b3cfb1df0 100644 --- a/common/src/main/java/me/lucko/luckperms/common/locale/message/Message.java +++ b/common/src/main/java/me/lucko/luckperms/common/locale/message/Message.java @@ -419,6 +419,7 @@ public enum Message { IMPORT_PROGRESS("&b(Import) &b-> &f{}&f% complete &7- &b{}&f/&b{} &foperations complete with &c{} &ferrors.", true), IMPORT_PROGRESS_SIN("&b(Import) &b-> &f{}&f% complete &7- &b{}&f/&b{} &foperations complete with &c{} &ferror.", true), IMPORT_START("&b(Import) &b-> &fStarting import process.", true), + IMPORT_INFO("&b(Import) &b-> &f{}.", true), IMPORT_END_COMPLETE("&b(Import) &a&lCOMPLETED &7- took &b{} &7seconds - &7No errors.", true), IMPORT_END_COMPLETE_ERR("&b(Import) &a&lCOMPLETED &7- took &b{} &7seconds - &c{} errors.", true),