Skip to content

Repository files navigation

SimpleReloadLib

Simple Java generic reload library.

Introduce

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.

Features

  • 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.

How to use

  1. Create a Reload Manager
ReloadManagerreloadManager = newReloadManager();
  1. Implement Reloadable and register it into ReloadManager (or static method if register for static util)
publicclassExampleimplementsReloadable {
publicExample(){
Instance.getReloadManager().register(this);
}
@OverridepublicReloadResultreloadModule() throwsException {
try{
// Reload code herereturnReloadResult.builder().status(ReloadStatus.SUCCESS).build();
} catch (IllegalStateExceptionscheduleException) {
returnReloadResult.builder().status(ReloadStatus.SCHEDULED).reason("Resource in use").build();
} catch (RuntimeExceptionrequireRestartException) {
returnReloadResult.builder().status(ReloadStatus.REQUIRE_RESTART).reason("Restart required").build();
} catch (ExceptionotherException){
returnReloadResult.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
}
}
  1. Reload it!
Map<ReloadableContainer, ReloadResult> results = reloadManager.reload();
Map<ReloadableContainer, ReloadResult> results = reloadManager.reload(Example.class);

Registerable reloadables

  • Any classes that implement Reloadable
  • Any no args and returns ReloadResult static Method

Get summary

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

Maven

We're in central.

 <dependencies>
<dependency>
<groupId>com.ghostchu</groupId>
<artifactId>simplereloadlib</artifactId>
<version>1.1.2</version>
</dependency>
</dependencies>

License

MIT

About

Simple but useful generic reload library for Java projects.

Topics

Resources

Stars

13 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages