From dfc713fde61e6c89fd8081988f2e12ea1a7d7fe3 Mon Sep 17 00:00:00 2001 From: ljacqu Date: Wed, 9 Mar 2016 18:39:04 +0100 Subject: [PATCH] Reload only specific entities (work in progress) - Remove attempt of reinitializing all components -> will lead to inconsistent states. Call reload on reloadable components instead --- src/main/java/fr/xephi/authme/AuthMe.java | 93 ++----------------- .../executable/authme/ReloadCommand.java | 2 +- .../authme/datasource/CacheDataSource.java | 5 + .../xephi/authme/datasource/DataSource.java | 5 + .../fr/xephi/authme/datasource/FlatFile.java | 5 + .../fr/xephi/authme/datasource/MySQL.java | 3 +- .../fr/xephi/authme/datasource/SQLite.java | 5 + 7 files changed, 33 insertions(+), 85 deletions(-) diff --git a/src/main/java/fr/xephi/authme/AuthMe.java b/src/main/java/fr/xephi/authme/AuthMe.java index cfd2b506b..005297426 100644 --- a/src/main/java/fr/xephi/authme/AuthMe.java +++ b/src/main/java/fr/xephi/authme/AuthMe.java @@ -331,90 +331,17 @@ public class AuthMe extends JavaPlugin { ConsoleLogger.info("AuthMe " + this.getDescription().getVersion() + " correctly enabled!"); } - /** Temporary method for reloading all stateful entities. */ - // TODO #432: Merge this with onEnable, not running things like Metrics multiple times where it would be bad - // Until then this method is a shameful copy of major parts of onEnable()... - public void reloadEntities() { - // Set various instances - server = getServer(); - plugin = this; - ConsoleLogger.setLogger(getLogger()); - - setPluginInfos(); - - // Load settings and custom configurations, if it fails, stop the server due to security reasons. - newSettings = createNewSetting(); - if (newSettings == null) { - ConsoleLogger.showError("Could not load configuration. Aborting."); - server.shutdown(); - return; - } - ConsoleLogger.setLoggingOptions(newSettings.getProperty(SecuritySettings.USE_LOGGING), - new File(getDataFolder(), "authme.log")); - - // Old settings manager - if (!loadSettings()) { - server.shutdown(); - setEnabled(false); - return; - } - - messages = new Messages(newSettings.getMessagesFile(), newSettings.getDefaultMessagesFile()); - - // Connect to the database and setup tables - try { - setupDatabase(newSettings); - } catch (Exception e) { - ConsoleLogger.logException("Fatal error occurred during database connection! " - + "Authme initialization aborted!", e); - stopOrUnload(); - return; - } - - passwordSecurity = new PasswordSecurity(getDataSource(), newSettings.getProperty(SecuritySettings.PASSWORD_HASH), - Bukkit.getPluginManager(), newSettings.getProperty(SecuritySettings.SUPPORT_OLD_PASSWORD_HASH)); - - // Set up the permissions manager and command handler - permsMan = initializePermissionsManager(); - commandHandler = initializeCommandHandler(permsMan, messages, passwordSecurity, newSettings, ipAddressManager); - - // Download and load GeoIp.dat file if absent - GeoLiteAPI.isDataAvailable(); - - // Set up the mail API - setupMailApi(); - - // Hooks - // Check Combat Tag Plus Version - checkCombatTagPlus(); - - // Check Multiverse - checkMultiverse(); - - // Check Essentials - checkEssentials(); - - // Check if the ProtocolLib is available. If so we could listen for - // inventory protection - checkProtocolLib(); - // End of Hooks - - dataManager = new DataManager(this); - - ProcessService processService = new ProcessService(newSettings, messages, this, - ipAddressManager, passwordSecurity); - management = new Management(this, processService, database, PlayerCache.getInstance()); - - // Set up the BungeeCord hook - setupBungeeCordHook(newSettings, ipAddressManager); - - // Reload support hook - reloadSupportHook(); - + /** + * Reload certain components. + * + * @throws Exception if an error occurs + */ + public void reload() throws Exception { + newSettings.reload(); + messages.reload(newSettings.getMessagesFile()); + // TODO ljacqu 20160309: change static interface of Spawn Spawn.reload(); - - // Show settings warnings - showSettingsWarnings(); + // setupDatabase(newSettings); } /** diff --git a/src/main/java/fr/xephi/authme/command/executable/authme/ReloadCommand.java b/src/main/java/fr/xephi/authme/command/executable/authme/ReloadCommand.java index 7353abc73..91df58322 100644 --- a/src/main/java/fr/xephi/authme/command/executable/authme/ReloadCommand.java +++ b/src/main/java/fr/xephi/authme/command/executable/authme/ReloadCommand.java @@ -18,7 +18,7 @@ public class ReloadCommand implements ExecutableCommand { public void executeCommand(CommandSender sender, List arguments, CommandService commandService) { AuthMe plugin = commandService.getAuthMe(); try { - plugin.reloadEntities(); + plugin.reload(); commandService.send(sender, MessageKey.CONFIG_RELOAD_SUCCESS); } catch (Exception e) { sender.sendMessage("Error occurred during reload of AuthMe: aborting"); diff --git a/src/main/java/fr/xephi/authme/datasource/CacheDataSource.java b/src/main/java/fr/xephi/authme/datasource/CacheDataSource.java index bb6049fa3..6617f7b53 100644 --- a/src/main/java/fr/xephi/authme/datasource/CacheDataSource.java +++ b/src/main/java/fr/xephi/authme/datasource/CacheDataSource.java @@ -64,6 +64,11 @@ public class CacheDataSource implements DataSource { return cachedAuths; } + @Override + public void reload() { + source.reload(); + } + @Override public synchronized boolean isAuthAvailable(String user) { return getAuth(user) != null; diff --git a/src/main/java/fr/xephi/authme/datasource/DataSource.java b/src/main/java/fr/xephi/authme/datasource/DataSource.java index 29157480b..5e2cc0c73 100644 --- a/src/main/java/fr/xephi/authme/datasource/DataSource.java +++ b/src/main/java/fr/xephi/authme/datasource/DataSource.java @@ -187,4 +187,9 @@ public interface DataSource { boolean isEmailStored(String email); + /** + * Reload the data source. + */ + void reload(); + } diff --git a/src/main/java/fr/xephi/authme/datasource/FlatFile.java b/src/main/java/fr/xephi/authme/datasource/FlatFile.java index 10f8a9a09..0765c7874 100644 --- a/src/main/java/fr/xephi/authme/datasource/FlatFile.java +++ b/src/main/java/fr/xephi/authme/datasource/FlatFile.java @@ -59,6 +59,11 @@ public class FlatFile implements DataSource { this.source = source; } + @Override + public void reload() { + throw new UnsupportedOperationException("Flatfile no longer supported"); + } + @Override public synchronized boolean isAuthAvailable(String user) { BufferedReader br = null; diff --git a/src/main/java/fr/xephi/authme/datasource/MySQL.java b/src/main/java/fr/xephi/authme/datasource/MySQL.java index 7d21fa856..db4ed5384 100644 --- a/src/main/java/fr/xephi/authme/datasource/MySQL.java +++ b/src/main/java/fr/xephi/authme/datasource/MySQL.java @@ -131,7 +131,8 @@ public class MySQL implements DataSource { ConsoleLogger.info("Connection arguments loaded, Hikari ConnectionPool ready!"); } - private synchronized void reloadArguments() throws RuntimeException { + @Override + public synchronized void reload() throws RuntimeException { if (ds != null) { ds.close(); } diff --git a/src/main/java/fr/xephi/authme/datasource/SQLite.java b/src/main/java/fr/xephi/authme/datasource/SQLite.java index d526bc858..f98edc0dd 100644 --- a/src/main/java/fr/xephi/authme/datasource/SQLite.java +++ b/src/main/java/fr/xephi/authme/datasource/SQLite.java @@ -124,6 +124,11 @@ public class SQLite implements DataSource { ConsoleLogger.info("SQLite Setup finished"); } + @Override + public void reload() { + // TODO 20160309: Implement reloading + } + @Override public synchronized boolean isAuthAvailable(String user) { PreparedStatement pst = null;