Initial commit

This commit is contained in:
tommyskeff
2023-11-19 20:55:02 +00:00
commit 08e97d81a4
34 changed files with 1807 additions and 0 deletions

42
futur-standalone/.gitignore vendored Normal file
View 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

View 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()
}

View File

@@ -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));
}
}

View File

@@ -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));
}
}