Giter VIP home page Giter VIP logo

simplereloadlib's Introduction

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
ReloadManager reloadManager = new ReloadManager();
  1. 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
    }
}
  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

simplereloadlib's People

Contributors

abhisahn avatar carmjos avatar dependabot[bot] avatar ghost-chu avatar mend-bolt-for-github[bot] avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

abhisahn

simplereloadlib's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.