Package org.confng.reload
Class ConfigReloadManager
- java.lang.Object
-
- org.confng.reload.ConfigReloadManager
-
- All Implemented Interfaces:
AutoCloseable
public class ConfigReloadManager extends Object implements AutoCloseable
Manages configuration reloading and change notifications.This class coordinates file watching, configuration reloading, and notifying listeners when configuration values change.
- Since:
- 1.1.0
- Author:
- Bharat Kumar Malviya, GitHub: github.com/imBharatMalviya
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddChangeListener(ConfigChangeListener listener)Adds a configuration change listener.voidclose()voiddisableAutoReload()Disables automatic reloading.voidenableAutoReload()Enables automatic reloading when configuration files change.voidenableAutoReload(long debounceMs)Enables automatic reloading with custom debounce time.static ConfigReloadManagergetInstance()Gets the singleton instance of the reload manager.booleanisAutoReloadEnabled()Checks if auto-reload is enabled.voidregisterLoadedFile(String filePath)Registers a file that was loaded for potential watching.voidremoveChangeListener(ConfigChangeListener listener)Removes a configuration change listener.static voidreset()Resets the singleton instance.voidtriggerReload(String source)Manually triggers a reload and notifies listeners.
-
-
-
Method Detail
-
getInstance
public static ConfigReloadManager getInstance()
Gets the singleton instance of the reload manager.
-
registerLoadedFile
public void registerLoadedFile(String filePath)
Registers a file that was loaded for potential watching.
-
addChangeListener
public void addChangeListener(ConfigChangeListener listener)
Adds a configuration change listener.
-
removeChangeListener
public void removeChangeListener(ConfigChangeListener listener)
Removes a configuration change listener.
-
enableAutoReload
public void enableAutoReload() throws IOExceptionEnables automatic reloading when configuration files change.- Throws:
IOException
-
enableAutoReload
public void enableAutoReload(long debounceMs) throws IOExceptionEnables automatic reloading with custom debounce time.- Parameters:
debounceMs- minimum time between reloads for the same file- Throws:
IOException
-
disableAutoReload
public void disableAutoReload()
Disables automatic reloading.
-
isAutoReloadEnabled
public boolean isAutoReloadEnabled()
Checks if auto-reload is enabled.
-
triggerReload
public void triggerReload(String source)
Manually triggers a reload and notifies listeners.
-
close
public void close()
- Specified by:
closein interfaceAutoCloseable
-
reset
public static void reset()
Resets the singleton instance. Useful for testing.
-
-