#704 Implement reloading via injector
- Create interfaces Reloadable and SettingsDependent to recognize reloadable classes - Iterate through instances in injector to reload
This commit is contained in:
@@ -2,6 +2,7 @@ package fr.xephi.authme.initialization;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import fr.xephi.authme.settings.NewSetting;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import javax.inject.Provider;
|
||||
@@ -122,6 +123,26 @@ public class AuthMeServiceInitializer {
|
||||
return object;
|
||||
}
|
||||
|
||||
/**
|
||||
* Performs a reload on all applicable instances which are registered.
|
||||
* Requires that the {@link NewSetting settings} instance be registered.
|
||||
* <p>
|
||||
* Note that the order in which these classes are reloaded is not guaranteed.
|
||||
*/
|
||||
public void performReloadOnServices() {
|
||||
NewSetting settings = (NewSetting) objects.get(NewSetting.class);
|
||||
if (settings == null) {
|
||||
throw new IllegalStateException("Settings instance is null");
|
||||
}
|
||||
for (Object object : objects.values()) {
|
||||
if (object instanceof Reloadable) {
|
||||
((Reloadable) object).reload();
|
||||
} else if (object instanceof SettingsDependent) {
|
||||
((SettingsDependent) object).loadSettings(settings);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Instantiates the given class by locating an @Inject constructor and retrieving
|
||||
* or instantiating its parameters.
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
package fr.xephi.authme.initialization;
|
||||
|
||||
/**
|
||||
* Interface for reloadable entities.
|
||||
*/
|
||||
public interface Reloadable {
|
||||
|
||||
/**
|
||||
* Performs the reload action.
|
||||
*/
|
||||
void reload();
|
||||
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package fr.xephi.authme.initialization;
|
||||
|
||||
import fr.xephi.authme.settings.NewSetting;
|
||||
|
||||
/**
|
||||
* Interface for classes that keep a local copy of certain settings.
|
||||
*/
|
||||
public interface SettingsDependent {
|
||||
|
||||
/**
|
||||
* Loads the needed settings.
|
||||
*
|
||||
* @param settings the settings instance
|
||||
*/
|
||||
void loadSettings(NewSetting settings);
|
||||
}
|
||||
Reference in New Issue
Block a user