mirror of
https://github.com/tommyskeff/futur4j.git
synced 2026-01-18 07:16:45 +00:00
Initial commit
This commit is contained in:
42
futur-standalone/.gitignore
vendored
Normal file
42
futur-standalone/.gitignore
vendored
Normal file
@@ -0,0 +1,42 @@
|
||||
.gradle
|
||||
build/
|
||||
!gradle/wrapper/gradle-wrapper.jar
|
||||
!**/src/main/**/build/
|
||||
!**/src/test/**/build/
|
||||
|
||||
### IntelliJ IDEA ###
|
||||
.idea/modules.xml
|
||||
.idea/jarRepositories.xml
|
||||
.idea/compiler.xml
|
||||
.idea/libraries/
|
||||
*.iws
|
||||
*.iml
|
||||
*.ipr
|
||||
out/
|
||||
!**/src/main/**/out/
|
||||
!**/src/test/**/out/
|
||||
|
||||
### Eclipse ###
|
||||
.apt_generated
|
||||
.classpath
|
||||
.factorypath
|
||||
.project
|
||||
.settings
|
||||
.springBeans
|
||||
.sts4-cache
|
||||
bin/
|
||||
!**/src/main/**/bin/
|
||||
!**/src/test/**/bin/
|
||||
|
||||
### NetBeans ###
|
||||
/nbproject/private/
|
||||
/nbbuild/
|
||||
/dist/
|
||||
/nbdist/
|
||||
/.nb-gradle/
|
||||
|
||||
### VS Code ###
|
||||
.vscode/
|
||||
|
||||
### Mac OS ###
|
||||
.DS_Store
|
||||
34
futur-standalone/build.gradle.kts
Normal file
34
futur-standalone/build.gradle.kts
Normal file
@@ -0,0 +1,34 @@
|
||||
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
|
||||
|
||||
plugins {
|
||||
id("java")
|
||||
id("com.github.johnrengelman.shadow") version "7.1.2"
|
||||
}
|
||||
|
||||
group = "dev.tommyjs"
|
||||
version = "1.0.0"
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation("org.jetbrains:annotations:24.1.0")
|
||||
implementation(project(mapOf("path" to ":futur-api")))
|
||||
testImplementation(platform("org.junit:junit-bom:5.9.1"))
|
||||
testImplementation("org.junit.jupiter:junit-jupiter")
|
||||
}
|
||||
|
||||
tasks {
|
||||
build {
|
||||
dependsOn(shadowJar)
|
||||
}
|
||||
|
||||
withType<ShadowJar> {
|
||||
exclude("META-INF/**")
|
||||
}
|
||||
}
|
||||
|
||||
tasks.test {
|
||||
useJUnitPlatform()
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
package dev.tommyjs.futur.standalone;
|
||||
|
||||
import dev.tommyjs.futur.scheduler.Scheduler;
|
||||
import dev.tommyjs.futur.trace.ExecutorTrace;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public class ExclusiveThreadPoolScheduler implements Scheduler {
|
||||
|
||||
private final ScheduledExecutorService executor;
|
||||
|
||||
protected ExclusiveThreadPoolScheduler(ScheduledExecutorService executor) {
|
||||
this.executor = executor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void runSync(@NotNull Runnable task, @NotNull ExecutorTrace trace) {
|
||||
throw new UnsupportedOperationException("Sync task invoked on asynchronous environment");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void runDelayedSync(@NotNull Runnable task, long delay, @NotNull TimeUnit unit, @NotNull ExecutorTrace trace) {
|
||||
throw new UnsupportedOperationException("Sync task invoked on asynchronous environment");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void runRepeatingSync(@NotNull Runnable task, long interval, @NotNull TimeUnit unit, @NotNull ExecutorTrace trace) {
|
||||
throw new UnsupportedOperationException("Sync task invoked on asynchronous environment");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void runAsync(@NotNull Runnable task, @NotNull ExecutorTrace trace) {
|
||||
executor.submit(wrapExceptions(task, trace));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void runDelayedAsync(@NotNull Runnable task, long delay, @NotNull TimeUnit unit, @NotNull ExecutorTrace trace) {
|
||||
executor.schedule(wrapExceptions(task, trace), delay, unit);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void runRepeatingAsync(@NotNull Runnable task, long interval, @NotNull TimeUnit unit, @NotNull ExecutorTrace trace) {
|
||||
executor.scheduleAtFixedRate(wrapExceptions(task, trace), 0L, interval, unit);
|
||||
}
|
||||
|
||||
public @NotNull ScheduledExecutorService getExecutor() {
|
||||
return executor;
|
||||
}
|
||||
|
||||
public static ExclusiveThreadPoolScheduler create(ScheduledExecutorService executor) {
|
||||
return new ExclusiveThreadPoolScheduler(executor);
|
||||
}
|
||||
|
||||
public static ExclusiveThreadPoolScheduler create(int nThreads) {
|
||||
return create(Executors.newScheduledThreadPool(nThreads));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
package dev.tommyjs.futur.standalone;
|
||||
|
||||
import dev.tommyjs.futur.scheduler.Scheduler;
|
||||
import dev.tommyjs.futur.trace.ExecutorTrace;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public class ThreadPoolScheduler implements Scheduler {
|
||||
|
||||
private final ScheduledExecutorService syncExecutor;
|
||||
private final ScheduledExecutorService asyncExecutor;
|
||||
|
||||
protected ThreadPoolScheduler(ScheduledExecutorService syncExecutor, ScheduledExecutorService asyncExecutor) {
|
||||
this.syncExecutor = syncExecutor;
|
||||
this.asyncExecutor = asyncExecutor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void runSync(@NotNull Runnable task, @NotNull ExecutorTrace trace) {
|
||||
syncExecutor.submit(wrapExceptions(task, trace));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void runDelayedSync(@NotNull Runnable task, long delay, @NotNull TimeUnit unit, @NotNull ExecutorTrace trace) {
|
||||
syncExecutor.schedule(wrapExceptions(task, trace), delay, unit);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void runRepeatingSync(@NotNull Runnable task, long interval, @NotNull TimeUnit unit, @NotNull ExecutorTrace trace) {
|
||||
syncExecutor.scheduleAtFixedRate(wrapExceptions(task, trace), 0L, interval, unit);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void runAsync(@NotNull Runnable task, @NotNull ExecutorTrace trace) {
|
||||
asyncExecutor.submit(wrapExceptions(task, trace));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void runDelayedAsync(@NotNull Runnable task, long delay, @NotNull TimeUnit unit, @NotNull ExecutorTrace trace) {
|
||||
asyncExecutor.schedule(wrapExceptions(task, trace), delay, unit);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void runRepeatingAsync(@NotNull Runnable task, long interval, @NotNull TimeUnit unit, @NotNull ExecutorTrace trace) {
|
||||
asyncExecutor.scheduleAtFixedRate(wrapExceptions(task, trace), 0L, interval, unit);
|
||||
}
|
||||
|
||||
public @NotNull ScheduledExecutorService getSyncExecutor() {
|
||||
return syncExecutor;
|
||||
}
|
||||
|
||||
public @NotNull ScheduledExecutorService getAsyncExecutor() {
|
||||
return asyncExecutor;
|
||||
}
|
||||
|
||||
public static ThreadPoolScheduler create(int nThreads) {
|
||||
return new ThreadPoolScheduler(Executors.newSingleThreadScheduledExecutor(), Executors.newScheduledThreadPool(nThreads));
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user