refactor: rename static executors to uppercase snake case
This commit is contained in:
@@ -66,8 +66,8 @@ public class Bot extends SessionAdapter {
|
||||
public boolean loggedIn = false;
|
||||
public long loginTime;
|
||||
|
||||
public final ExecutorService executorService = Main.executorService;
|
||||
public final ScheduledExecutorService executor = Main.executor;
|
||||
public final ExecutorService executorService = Main.EXECUTOR_SERVICE;
|
||||
public final ScheduledExecutorService executor = Main.EXECUTOR;
|
||||
|
||||
public LoggerPlugin logger;
|
||||
public TickPlugin tick;
|
||||
|
||||
@@ -26,11 +26,11 @@ public class Main {
|
||||
|
||||
public static final List<Bot> bots = new ArrayList<>();
|
||||
|
||||
public static final ExecutorService executorService = Executors.newFixedThreadPool(
|
||||
public static final ExecutorService EXECUTOR_SERVICE = Executors.newFixedThreadPool(
|
||||
Math.max(1, Runtime.getRuntime().availableProcessors() / 2),
|
||||
new ThreadFactoryBuilder().setNameFormat("ExecutorService #%d").build()
|
||||
);
|
||||
public static final ScheduledExecutorService executor = Executors.newScheduledThreadPool(
|
||||
public static final ScheduledExecutorService EXECUTOR = Executors.newScheduledThreadPool(
|
||||
Math.max(1, Runtime.getRuntime().availableProcessors() / 2),
|
||||
new ThreadFactoryBuilder().setNameFormat("ScheduledExecutorService #%d").build()
|
||||
);
|
||||
@@ -89,7 +89,7 @@ public class Main {
|
||||
if (!config.backup.enabled) {
|
||||
initializeBots();
|
||||
} else {
|
||||
executor.scheduleAtFixedRate(() -> {
|
||||
EXECUTOR.scheduleAtFixedRate(() -> {
|
||||
boolean reachable;
|
||||
|
||||
try {
|
||||
@@ -181,9 +181,9 @@ public class Main {
|
||||
|
||||
LoggerUtilities.log(stoppingMessage);
|
||||
|
||||
executor.shutdown();
|
||||
EXECUTOR.shutdown();
|
||||
|
||||
executorService.shutdown();
|
||||
EXECUTOR_SERVICE.shutdown();
|
||||
|
||||
if (database != null) database.stop();
|
||||
|
||||
|
||||
@@ -78,7 +78,7 @@ public class FilterCommand extends Command {
|
||||
final boolean finalRegex = regex;
|
||||
final boolean finalIgnoreCase = ignoreCase;
|
||||
|
||||
DatabasePlugin.executorService.submit(() -> bot.playerFilter.add(player, reason, finalRegex, finalIgnoreCase));
|
||||
DatabasePlugin.EXECUTOR_SERVICE.submit(() -> bot.playerFilter.add(player, reason, finalRegex, finalIgnoreCase));
|
||||
|
||||
if (reason.isEmpty()) {
|
||||
return Component.translatable(
|
||||
@@ -102,7 +102,7 @@ public class FilterCommand extends Command {
|
||||
|
||||
if (player == null) throw new CommandException(Component.text("Invalid index"));
|
||||
|
||||
DatabasePlugin.executorService.submit(() -> bot.playerFilter.remove(player.playerName));
|
||||
DatabasePlugin.EXECUTOR_SERVICE.submit(() -> bot.playerFilter.remove(player.playerName));
|
||||
|
||||
return Component.translatable(
|
||||
"Removed %s from the filters",
|
||||
@@ -112,7 +112,7 @@ public class FilterCommand extends Command {
|
||||
case "clear" -> {
|
||||
context.checkOverloadArgs(1);
|
||||
|
||||
DatabasePlugin.executorService.submit(() -> bot.playerFilter.clear());
|
||||
DatabasePlugin.EXECUTOR_SERVICE.submit(() -> bot.playerFilter.clear());
|
||||
return Component.text("Cleared the filter").color(ColorUtilities.getColorByString(bot.config.colorPalette.defaultColor));
|
||||
}
|
||||
case "list" -> {
|
||||
|
||||
@@ -54,7 +54,7 @@ public class IPFilterCommand extends Command {
|
||||
);
|
||||
}
|
||||
|
||||
DatabasePlugin.executorService.submit(() -> bot.ipFilter.add(ip, reason));
|
||||
DatabasePlugin.EXECUTOR_SERVICE.submit(() -> bot.ipFilter.add(ip, reason));
|
||||
|
||||
if (reason.isEmpty()) {
|
||||
return Component.translatable(
|
||||
@@ -78,7 +78,7 @@ public class IPFilterCommand extends Command {
|
||||
|
||||
if (targetIP == null) throw new CommandException(Component.text("Invalid index"));
|
||||
|
||||
DatabasePlugin.executorService.submit(() -> bot.ipFilter.remove(targetIP));
|
||||
DatabasePlugin.EXECUTOR_SERVICE.submit(() -> bot.ipFilter.remove(targetIP));
|
||||
|
||||
return Component.translatable(
|
||||
"Removed %s from the filters",
|
||||
@@ -88,7 +88,7 @@ public class IPFilterCommand extends Command {
|
||||
case "clear" -> {
|
||||
context.checkOverloadArgs(1);
|
||||
|
||||
DatabasePlugin.executorService.submit(() -> bot.ipFilter.clear());
|
||||
DatabasePlugin.EXECUTOR_SERVICE.submit(() -> bot.ipFilter.clear());
|
||||
return Component.text("Cleared the filter").color(ColorUtilities.getColorByString(bot.config.colorPalette.defaultColor));
|
||||
}
|
||||
case "list" -> {
|
||||
|
||||
@@ -51,7 +51,7 @@ public class MailCommand extends Command {
|
||||
final String action = context.getAction();
|
||||
|
||||
switch (action) {
|
||||
case "send" -> DatabasePlugin.executorService.submit(() -> {
|
||||
case "send" -> DatabasePlugin.EXECUTOR_SERVICE.submit(() -> {
|
||||
try {
|
||||
bot.mail.send(
|
||||
new Mail(
|
||||
@@ -82,7 +82,7 @@ public class MailCommand extends Command {
|
||||
throw new CommandException(Component.text("Player has no `message` NBT tag in their selected item's minecraft:custom_data"));
|
||||
}
|
||||
|
||||
DatabasePlugin.executorService.submit(() -> {
|
||||
DatabasePlugin.EXECUTOR_SERVICE.submit(() -> {
|
||||
try {
|
||||
bot.mail.send(
|
||||
new Mail(
|
||||
@@ -112,7 +112,7 @@ public class MailCommand extends Command {
|
||||
case "read" -> {
|
||||
context.checkOverloadArgs(1);
|
||||
|
||||
DatabasePlugin.executorService.submit(() -> {
|
||||
DatabasePlugin.EXECUTOR_SERVICE.submit(() -> {
|
||||
final List<Mail> mails = bot.mail.list();
|
||||
|
||||
int senderMailSize = 0;
|
||||
|
||||
@@ -64,7 +64,7 @@ public class SeenCommand extends Command {
|
||||
|
||||
if (online) return Component.join(JoinConfiguration.newlines(), onlineComponents);
|
||||
|
||||
DatabasePlugin.executorService.submit(() -> {
|
||||
DatabasePlugin.EXECUTOR_SERVICE.submit(() -> {
|
||||
try {
|
||||
final JsonNode playerElement = bot.playersDatabase.getPlayerData(player);
|
||||
if (playerElement == null) throw new CommandException(Component.translatable(
|
||||
|
||||
@@ -40,7 +40,7 @@ public class UrbanCommand extends Command {
|
||||
false
|
||||
);
|
||||
|
||||
Main.executor.scheduleAtFixedRate(() -> requestsPerSecond = 0, 0, 1, TimeUnit.SECONDS);
|
||||
Main.EXECUTOR.scheduleAtFixedRate(() -> requestsPerSecond = 0, 0, 1, TimeUnit.SECONDS);
|
||||
}
|
||||
|
||||
public Component execute (CommandContext context) throws CommandException {
|
||||
|
||||
@@ -12,7 +12,7 @@ import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.ThreadPoolExecutor;
|
||||
|
||||
public class DatabasePlugin {
|
||||
public static final ExecutorService executorService = Executors.newSingleThreadExecutor(
|
||||
public static final ExecutorService EXECUTOR_SERVICE = Executors.newSingleThreadExecutor(
|
||||
new ThreadFactoryBuilder()
|
||||
.setNameFormat("ExecutorService (database)")
|
||||
.build()
|
||||
@@ -33,7 +33,7 @@ public class DatabasePlugin {
|
||||
}
|
||||
|
||||
public void checkOverloaded () throws CommandException {
|
||||
final ThreadPoolExecutor threadPoolExecutor = (ThreadPoolExecutor) executorService;
|
||||
final ThreadPoolExecutor threadPoolExecutor = (ThreadPoolExecutor) EXECUTOR_SERVICE;
|
||||
|
||||
if (threadPoolExecutor.getQueue().size() > 20) throw new CommandException(
|
||||
Component.text("The executor service is filled with requests!")
|
||||
@@ -59,7 +59,7 @@ public class DatabasePlugin {
|
||||
}
|
||||
|
||||
public void stop () {
|
||||
executorService.shutdown();
|
||||
EXECUTOR_SERVICE.shutdown();
|
||||
|
||||
try {
|
||||
connection.close();
|
||||
|
||||
@@ -23,7 +23,7 @@ public class IPFilterPlugin implements PlayersPlugin.Listener, CorePlugin.Listen
|
||||
|
||||
static {
|
||||
if (Main.database != null) {
|
||||
DatabasePlugin.executorService.submit(() -> {
|
||||
DatabasePlugin.EXECUTOR_SERVICE.submit(() -> {
|
||||
try {
|
||||
Main.database.execute(CREATE_TABLE);
|
||||
} catch (SQLException e) {
|
||||
@@ -31,7 +31,7 @@ public class IPFilterPlugin implements PlayersPlugin.Listener, CorePlugin.Listen
|
||||
}
|
||||
});
|
||||
|
||||
Main.executor.scheduleAtFixedRate(IPFilterPlugin::list, 5, 30, TimeUnit.SECONDS);
|
||||
Main.EXECUTOR.scheduleAtFixedRate(IPFilterPlugin::list, 5, 30, TimeUnit.SECONDS);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -85,7 +85,7 @@ public class IRCPlugin extends ListenerAdapter {
|
||||
});
|
||||
}
|
||||
|
||||
Main.executor.scheduleAtFixedRate(this::queueTick, 0, 100, TimeUnit.MILLISECONDS);
|
||||
Main.EXECUTOR.scheduleAtFixedRate(this::queueTick, 0, 100, TimeUnit.MILLISECONDS);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -23,7 +23,7 @@ public class MailPlugin implements PlayersPlugin.Listener {
|
||||
|
||||
static {
|
||||
if (Main.database != null) {
|
||||
DatabasePlugin.executorService.submit(() -> {
|
||||
DatabasePlugin.EXECUTOR_SERVICE.submit(() -> {
|
||||
try {
|
||||
Main.database.execute(CREATE_TABLE);
|
||||
} catch (SQLException e) {
|
||||
@@ -45,7 +45,7 @@ public class MailPlugin implements PlayersPlugin.Listener {
|
||||
|
||||
@Override
|
||||
public void playerJoined (PlayerEntry target) {
|
||||
DatabasePlugin.executorService.submit(() -> {
|
||||
DatabasePlugin.EXECUTOR_SERVICE.submit(() -> {
|
||||
final String name = target.profile.getName();
|
||||
|
||||
int sendToTargetSize = 0;
|
||||
|
||||
@@ -27,7 +27,7 @@ public class PlayerFilterPlugin implements PlayersPlugin.Listener {
|
||||
|
||||
static {
|
||||
if (Main.database != null) {
|
||||
DatabasePlugin.executorService.submit(() -> {
|
||||
DatabasePlugin.EXECUTOR_SERVICE.submit(() -> {
|
||||
try {
|
||||
Main.database.execute(CREATE_TABLE);
|
||||
} catch (SQLException e) {
|
||||
@@ -35,7 +35,7 @@ public class PlayerFilterPlugin implements PlayersPlugin.Listener {
|
||||
}
|
||||
});
|
||||
|
||||
Main.executor.scheduleAtFixedRate(PlayerFilterPlugin::list, 5, 30, TimeUnit.SECONDS);
|
||||
Main.EXECUTOR.scheduleAtFixedRate(PlayerFilterPlugin::list, 5, 30, TimeUnit.SECONDS);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -33,7 +33,7 @@ public class PlayersDatabasePlugin implements PlayersPlugin.Listener {
|
||||
|
||||
static {
|
||||
if (Main.database != null) {
|
||||
DatabasePlugin.executorService.submit(() -> {
|
||||
DatabasePlugin.EXECUTOR_SERVICE.submit(() -> {
|
||||
try {
|
||||
Main.database.execute(CREATE_TABLE);
|
||||
} catch (SQLException e) {
|
||||
@@ -135,7 +135,7 @@ public class PlayersDatabasePlugin implements PlayersPlugin.Listener {
|
||||
|
||||
@Override
|
||||
public void playerJoined (PlayerEntry target) {
|
||||
DatabasePlugin.executorService.submit(() -> {
|
||||
DatabasePlugin.EXECUTOR_SERVICE.submit(() -> {
|
||||
try {
|
||||
final PreparedStatement insertPlayerStatement = Main.database.connection.prepareStatement(INSERT_PLAYER);
|
||||
|
||||
@@ -188,7 +188,7 @@ public class PlayersDatabasePlugin implements PlayersPlugin.Listener {
|
||||
|
||||
@Override
|
||||
public void playerLeft (PlayerEntry target) {
|
||||
DatabasePlugin.executorService.submit(() -> {
|
||||
DatabasePlugin.EXECUTOR_SERVICE.submit(() -> {
|
||||
try {
|
||||
final PreparedStatement updatePlayerStatement = Main.database.connection.prepareStatement(UPDATE_PLAYER);
|
||||
|
||||
|
||||
@@ -84,7 +84,7 @@ public class PlayersPlugin extends Bot.Listener implements TickPlugin.Listener {
|
||||
public CompletableFuture<String> getPlayerIP (PlayerEntry target, boolean forceSeen) {
|
||||
final CompletableFuture<String> outputFuture = new CompletableFuture<>();
|
||||
|
||||
DatabasePlugin.executorService.submit(() -> {
|
||||
DatabasePlugin.EXECUTOR_SERVICE.submit(() -> {
|
||||
if (!forceSeen) {
|
||||
final String databaseIP = bot.playersDatabase.getPlayerIP(target.profile.getName());
|
||||
|
||||
|
||||
@@ -34,7 +34,7 @@ public class DownloadUtilities {
|
||||
private static int limit = 0;
|
||||
|
||||
static {
|
||||
Main.executor.scheduleAtFixedRate(() -> limit = 0, 0, 1, TimeUnit.SECONDS);
|
||||
Main.EXECUTOR.scheduleAtFixedRate(() -> limit = 0, 0, 1, TimeUnit.SECONDS);
|
||||
}
|
||||
|
||||
public static byte[] DownloadToByteArray (URL url, int maxSize) throws IOException, KeyManagementException, NoSuchAlgorithmException {
|
||||
|
||||
Reference in New Issue
Block a user