Simple Java generic reload library.
SimpleReloadLib isvused to be a part of QuickShop-Reremake. But it is really easy to use and powerful, so I made it to a standalone lib.
You can insert this to any Java project including Bukkit, Paper, BungeeCord, Forge, Fabric etc.
This lib is already used in QuickShop-Reremake over 1 year and no errors were found.
- Reloading mechanism based on registration order, no need to worry about reload order。
- Simple and easy to use, just need to register with eyes closed.
- Lightweight, powered by 5 java classes. You can package it into any project.
- WeakReference to save your memory and prevent memory leaking.
- Support both object and static method.
- Create a Reload Manager
ReloadManager reloadManager = new ReloadManager();
- Implement Reloadable and register it into ReloadManager (or static method if register for static util)
public class Example implements Reloadable {
public Example(){
Instance.getReloadManager().register(this);
}
@Override
public ReloadResult reloadModule() throws Exception {
try{
// Reload code here
return ReloadResult.builder().status(ReloadStatus.SUCCESS).build();
} catch (IllegalStateException scheduleException) {
return ReloadResult.builder().status(ReloadStatus.SCHEDULED).reason("Resource in use").build();
} catch (RuntimeException requireRestartException) {
return ReloadResult.builder().status(ReloadStatus.REQUIRE_RESTART).reason("Restart required").build();
} catch (Exception otherException){
return ReloadResult.builder().status(ReloadStatus.EXCEPTION).exception(otherException).reason("Unkown error raised").build();
}
// If there have any Exception not be catched, Manager will catch it and report with ReloadStatus.EXCEPTION
}
}
- Reload it!
Map<ReloadableContainer, ReloadResult> results = reloadManager.reload();
Map<ReloadableContainer, ReloadResult> results = reloadManager.reload(Example.class);
- Any classes that implement Reloadable
- Any no args and returns ReloadResult static Method
SimpleReloadLib offers a Map contains ReloadContainer and ReloadResults:
- SUCCESS - Successfully to reloading.
- OUTDATED - WeakReferenced object already invalid and will be removed in next reload.
- REQUIRE_RESTART - Reload is impossible, restart required.
- SCHEDULED - Cannot reload in this time but already scheduled reloading if possible.
- EXCEPTION - Something just exploded
We're in central.
<dependencies>
<dependency>
<groupId>com.ghostchu</groupId>
<artifactId>simplereloadlib</artifactId>
<version>1.1.2</version>
</dependency>
</dependencies>
MIT