0.1.1 | Scheduler shenanigans
This commit is contained in:
@@ -67,4 +67,73 @@ public class main {
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### Usage Scheduler (without retries)
|
||||
|
||||
```java
|
||||
|
||||
import java.time.Duration;
|
||||
|
||||
public class main {
|
||||
public static void main(String[] args) {
|
||||
LicenseScheduler scheduler = LicenseScheduler.startScheduler(
|
||||
Duration.ofMinutes(5),
|
||||
apiUrl,
|
||||
plugin,
|
||||
licenseKey,
|
||||
serverId,
|
||||
result -> {
|
||||
if (result instanceof LicenseSuccess success) {
|
||||
if (!success.valid()) {
|
||||
// Handle invalid license
|
||||
}
|
||||
} else if (result instanceof LicenseError error) {
|
||||
// Log errors if you want
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
// Later: Stop the scheduler
|
||||
scheduler.stop();
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
### Usage Scheduler (with retries)
|
||||
|
||||
```java
|
||||
import java.time.Duration;
|
||||
|
||||
public class main {
|
||||
public static void main(String[] args) {
|
||||
LicenseScheduler scheduler = LicenseScheduler.startSchedulerWithRetries(
|
||||
Duration.ofMinutes(5),
|
||||
apiUrl,
|
||||
plugin,
|
||||
licenseKey,
|
||||
serverId,
|
||||
3, //max retries,
|
||||
Duration.ofSeconds(10), //delay between retries
|
||||
result -> {
|
||||
if(result instanceof LicenseSuccess success) {
|
||||
if (!success.valid()) {
|
||||
// Handle invalid license
|
||||
}
|
||||
} else if (result instanceof LicenseError error) {
|
||||
// Log errors if you want
|
||||
}
|
||||
},
|
||||
result -> {
|
||||
// Called only after all retries failed
|
||||
// Put your "offline" handling here
|
||||
// Disable plugin or something like that
|
||||
}
|
||||
);
|
||||
|
||||
// Later: Stop the scheduler
|
||||
scheduler.stop();
|
||||
}
|
||||
}
|
||||
```
|
||||
Reference in New Issue
Block a user