Reload only specific entities (work in progress)

- Remove attempt of reinitializing all components -> will lead to inconsistent states. Call reload on reloadable components instead
This commit is contained in:
ljacqu 2016-03-09 18:39:04 +01:00
parent 4d55bedcaa
commit dfc713fde6
7 changed files with 33 additions and 85 deletions

View File

@ -331,90 +331,17 @@ public class AuthMe extends JavaPlugin {
ConsoleLogger.info("AuthMe " + this.getDescription().getVersion() + " correctly enabled!"); 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 * Reload certain components.
// Until then this method is a shameful copy of major parts of onEnable()... *
public void reloadEntities() { * @throws Exception if an error occurs
// Set various instances */
server = getServer(); public void reload() throws Exception {
plugin = this; newSettings.reload();
ConsoleLogger.setLogger(getLogger()); messages.reload(newSettings.getMessagesFile());
// TODO ljacqu 20160309: change static interface of Spawn
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();
Spawn.reload(); Spawn.reload();
// setupDatabase(newSettings);
// Show settings warnings
showSettingsWarnings();
} }
/** /**

View File

@ -18,7 +18,7 @@ public class ReloadCommand implements ExecutableCommand {
public void executeCommand(CommandSender sender, List<String> arguments, CommandService commandService) { public void executeCommand(CommandSender sender, List<String> arguments, CommandService commandService) {
AuthMe plugin = commandService.getAuthMe(); AuthMe plugin = commandService.getAuthMe();
try { try {
plugin.reloadEntities(); plugin.reload();
commandService.send(sender, MessageKey.CONFIG_RELOAD_SUCCESS); commandService.send(sender, MessageKey.CONFIG_RELOAD_SUCCESS);
} catch (Exception e) { } catch (Exception e) {
sender.sendMessage("Error occurred during reload of AuthMe: aborting"); sender.sendMessage("Error occurred during reload of AuthMe: aborting");

View File

@ -64,6 +64,11 @@ public class CacheDataSource implements DataSource {
return cachedAuths; return cachedAuths;
} }
@Override
public void reload() {
source.reload();
}
@Override @Override
public synchronized boolean isAuthAvailable(String user) { public synchronized boolean isAuthAvailable(String user) {
return getAuth(user) != null; return getAuth(user) != null;

View File

@ -187,4 +187,9 @@ public interface DataSource {
boolean isEmailStored(String email); boolean isEmailStored(String email);
/**
* Reload the data source.
*/
void reload();
} }

View File

@ -59,6 +59,11 @@ public class FlatFile implements DataSource {
this.source = source; this.source = source;
} }
@Override
public void reload() {
throw new UnsupportedOperationException("Flatfile no longer supported");
}
@Override @Override
public synchronized boolean isAuthAvailable(String user) { public synchronized boolean isAuthAvailable(String user) {
BufferedReader br = null; BufferedReader br = null;

View File

@ -131,7 +131,8 @@ public class MySQL implements DataSource {
ConsoleLogger.info("Connection arguments loaded, Hikari ConnectionPool ready!"); ConsoleLogger.info("Connection arguments loaded, Hikari ConnectionPool ready!");
} }
private synchronized void reloadArguments() throws RuntimeException { @Override
public synchronized void reload() throws RuntimeException {
if (ds != null) { if (ds != null) {
ds.close(); ds.close();
} }

View File

@ -124,6 +124,11 @@ public class SQLite implements DataSource {
ConsoleLogger.info("SQLite Setup finished"); ConsoleLogger.info("SQLite Setup finished");
} }
@Override
public void reload() {
// TODO 20160309: Implement reloading
}
@Override @Override
public synchronized boolean isAuthAvailable(String user) { public synchronized boolean isAuthAvailable(String user) {
PreparedStatement pst = null; PreparedStatement pst = null;