A reactive non blocking api for scheduling runnable tasks (called services) using Reactor
Go to file
Paldiu 25ea207677
Update README.md
2023-04-14 00:26:53 -05:00
.github/workflows Create codeql.yml 2022-12-14 23:41:50 -06:00
build Update Docs 2022-12-14 23:08:12 -06:00
docs Update Docs 2022-12-14 23:08:12 -06:00
gradle/wrapper Minor fix 2022-12-14 19:00:41 -06:00
src/main Update ServiceManager.java 2022-12-21 15:31:42 -06:00
.gitattributes SimplexSS (Scheduling Service) 2022-07-07 23:09:25 -05:00
.gitignore Minor fix 2022-12-14 19:00:41 -06:00
LICENSE Update LICENSE 2022-12-14 21:22:18 -06:00
README.md Update README.md 2023-04-14 00:26:53 -05:00
build.gradle Update Docs 2022-12-14 23:08:12 -06:00
gradle.properties SimplexSS (Scheduling Service) 2022-07-07 23:09:25 -05:00
gradlew SimplexSS (Scheduling Service) 2022-07-07 23:09:25 -05:00
gradlew.bat SimplexSS (Scheduling Service) 2022-07-07 23:09:25 -05:00
settings.gradle SimplexSS (Scheduling Service) 2022-07-07 23:09:25 -05:00

README.md

SimplexSS


A reactive non blocking api for scheduling runnable tasks (called services)

JavaDocs can be found here.

Adding SimplexSS to your project

In order to use SimplexSS in your project, you need to add the jitpack repository to your build.gradle or pom.xml file.

Here's an example, in Gradle:

repositories {
    maven {
        id 'jitpack'
        url 'https://jitpack.io'
    }
}

Then, you can add the dependency.

The groupId is com.github.SimplexDevelopment

The artifactId is SimplexSS

The version is 1.0.1-SNAPSHOT

It is recommended you use either the Maven Shade Plugin,

<build>
   <plugins>
     <plugin>
       <groupId>org.apache.maven.plugins</groupId>
       <artifactId>maven-jar-plugin</artifactId>
       ...
       <configuration>
         <archive>
           <manifest>
             <addClasspath>true</addClasspath>
             <mainClass>path.to.MainClass</mainClass>
           </manifest>
         </archive>
       </configuration>
       ...
     </plugin>
   </plugins>
 </build>

or the Gradle Shadow Plugin (com.github.johnrengelman.shadow).

plugins {
    id 'com.github.johnrengelman.shadow' version '7.1.2'
}

Here is an example of the dependency, in Gradle:

dependencies {
   shadow 'com.github.SimplexDevelopment:SimplexSS:1.0.1-SNAPSHOT'
}

Using SimplexSS

To use Simplex Scheduling System, the first thing you need to do is initialize a new instance of the Scheduling System.

private SchedulingSystem<YourPlugin> scheduler;

@Override
public void onEnable() {
    this.scheduler = new SchedulingSystem<>(this);
}

Then, you should use the Service Manager to create some new service pools. You can use ServicePool#emptyBukkitServicePool(String, JavaPlugin) for a service pool which will operate on the main server thread, or you can use ServicePool#emptyServicePool(String, boolean) for a completely separate, non-blocking scheduler which can be either singular or multithreaded. You should also use the service manager stream to register your services, and assign a Flux object so we can cancel the services later on in JavaPlugin#onDisable().

private SchedulingSystem<YourPlugin> scheduler;
private Flux<Disposable> disposables;

@Override
public void onEnable() {
    this.scheduler = new SchedulingSystem<>(this);
    
    YourFirstService firstService;
    YourSecondService secondService;
    YourThirdService thirdService;
    
    scheduler.getServiceManager().subscribe(manager -> {
        manager.emptyBukkitServicePool("pool_name", this).subscribe(pool -> {
            Set<Disposable> dispos = new HashSet<>();

            firstService = new YourFirstService(pool, "first_service_name");
            secondService = new YourSecondService(pool, "second_service_name", 20 * 60L);
            thirdService = new YourThirdService(pool, "third_service_name", 20 * 60L, 20 * 60 * 10L, true, false);

            scheduler.queue(firstService).subscribe(dispos::add);
            scheduler.queue(secondService).subscribe(dispos::add);
            scheduler.queue(thirdService).subscribe(dispos::add);

            disposables = Flux.fromIterable(dispos);
        });
    });
}

You can then stop, cancel, and/or dispose of the tasks in your JavaPlugin#onDisable() method by calling:

@Override
public void onDisable() {
    scheduler.getServiceManager().subscribe(manager -> {
        manager.getServicePools().doOnEach(signal -> Objects.requireNonNull(signal.get())
                   .stopServices(disposables)
                   .subscribe());
    });
}