T - Configuration object typepublic abstract class ConfigurationAbstractImpl<T> extends Object implements Configuration<T>
Configuration which defines the logic by which event subscription works.
Extending classes must call init(File) in the last call of the constructor. For example:
class ConfigurationCustomImpl implements Configuration<User> {
private final UserDao userDao;
public ConfigurationCustomImpl(String sourceId, File configFile, EventBus eventBus, UserDao userDao) {
super(sourceId, eventBus);
this.userDao = userDao;
init(configFile);
}
@Override
public User load(File configFile) {
String username = readAdminUsernameFromFile(configFile);
return new UserDao().getUser(username);
}
}
| Constructor and Description |
|---|
ConfigurationAbstractImpl(String sourceId,
EventBus eventBus) |
| Modifier and Type | Method and Description |
|---|---|
protected EventBus |
getEventBus() |
String |
getSourceId() |
T |
getValue()
Returns the configuration object.
|
protected void |
init(File configFile)
Initializes the configuration
value and subscribes this object to file changes. |
void |
onFileEvent(FileEvent fileEvent)
Called when a file event published from the
eventBus is heard. |
protected void |
onFileEventMatch(File configFile,
FileEventType fileEventType)
Defines the reloading logic to be performed when the file event matches this configuration object.
|
protected void |
reload(File configFile) |
protected void |
whenConfigFileCreated(File configFile)
Called when the file associated with this object is
FileEventType.CREATED. |
protected void |
whenConfigFileDeleted(File configFile)
Called when the file associated with this object is
FileEventType.DELETED. |
protected void |
whenConfigFileUpdated(File configFile)
Called when the file associated with this object is
FileEventType.UPDATED. |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitloadprotected void init(File configFile) throws IOException
value and subscribes this object to file changes.configFile - Non-null configuration fileIOException - On I/O error parsing the config filepublic String getSourceId()
protected EventBus getEventBus()
public T getValue()
public void onFileEvent(FileEvent fileEvent) throws IOException
eventBus is heard.fileEvent - Non-null file event which may or may not correspond to this configuration objectIOExceptionprotected void onFileEventMatch(File configFile, FileEventType fileEventType) throws IOException
configFile - Non-null configuration file which was changedfileEventType - Non-null file event typeIOExceptionprotected void whenConfigFileCreated(File configFile) throws IOException
FileEventType.CREATED. By default, this method
reloads the #config object.IOExceptionprotected void whenConfigFileUpdated(File configFile) throws IOException
FileEventType.UPDATED. By default, this method
reloads the #config object.IOExceptionprotected void whenConfigFileDeleted(File configFile) throws IOException
FileEventType.DELETED. By default, this method does
nothing.IOExceptionprotected void reload(File configFile) throws IOException
IOExceptionCopyright © 2016–2017. All rights reserved.