mirror of
https://github.com/tommyskeff/futur4j.git
synced 2026-01-17 23:16:01 +00:00
Initial commit
This commit is contained in:
2
.gitattributes
vendored
Normal file
2
.gitattributes
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
# Auto detect text files and perform LF normalization
|
||||
* text=auto
|
||||
42
.gitignore
vendored
Normal file
42
.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
|
||||
21
LICENSE
Normal file
21
LICENSE
Normal file
@@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2023 tommyskeff
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
10
README.md
Normal file
10
README.md
Normal file
@@ -0,0 +1,10 @@
|
||||
# Futur4J
|
||||
|
||||
Futur4J is a powerful and intuitive open-source Java library that simplifies asynchronous task scheduling, inspired by the concept of JavaScript promises.
|
||||
|
||||
## Getting Started
|
||||
Coming Soon
|
||||
|
||||
## Documentation
|
||||
Coming Soon
|
||||
|
||||
42
futur-api/.gitignore
vendored
Normal file
42
futur-api/.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-api/build.gradle.kts
Normal file
34
futur-api/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("org.slf4j:slf4j-api:2.0.9")
|
||||
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,7 @@
|
||||
package dev.tommyjs.futur.function;
|
||||
|
||||
public interface ExceptionalConsumer<T> {
|
||||
|
||||
void accept(T value) throws Exception;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package dev.tommyjs.futur.function;
|
||||
|
||||
public interface ExceptionalFunction<K, V> {
|
||||
|
||||
V apply(K value) throws Exception;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package dev.tommyjs.futur.function;
|
||||
|
||||
public interface ExceptionalRunnable {
|
||||
|
||||
void run() throws Exception;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package dev.tommyjs.futur.function;
|
||||
|
||||
public interface ExceptionalSupplier<T> {
|
||||
|
||||
T get() throws Exception;
|
||||
|
||||
}
|
||||
404
futur-api/src/main/java/dev/tommyjs/futur/promise/Promise.java
Normal file
404
futur-api/src/main/java/dev/tommyjs/futur/promise/Promise.java
Normal file
@@ -0,0 +1,404 @@
|
||||
package dev.tommyjs.futur.promise;
|
||||
|
||||
import dev.tommyjs.futur.function.ExceptionalConsumer;
|
||||
import dev.tommyjs.futur.function.ExceptionalFunction;
|
||||
import dev.tommyjs.futur.function.ExceptionalRunnable;
|
||||
import dev.tommyjs.futur.function.ExceptionalSupplier;
|
||||
import dev.tommyjs.futur.scheduler.Schedulers;
|
||||
import dev.tommyjs.futur.trace.ExecutorTrace;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.concurrent.ConcurrentLinkedQueue;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public class Promise<T> {
|
||||
|
||||
private static final String PACKAGE;
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(Promise.class);
|
||||
|
||||
static {
|
||||
String[] packageElements = Promise.class.getPackageName().split("\\.");
|
||||
int i = 0;
|
||||
|
||||
StringBuilder packageBuilder = new StringBuilder();
|
||||
while (i < 3) {
|
||||
packageBuilder.append(packageElements[i]);
|
||||
i++;
|
||||
}
|
||||
|
||||
PACKAGE = packageBuilder.toString();
|
||||
}
|
||||
|
||||
private final Collection<PromiseListener<T>> listeners;
|
||||
private final StackTraceElement[] stackTrace;
|
||||
|
||||
private @Nullable PromiseCompletion<T> completion;
|
||||
|
||||
public Promise() {
|
||||
this.listeners = new ConcurrentLinkedQueue<>();
|
||||
this.completion = null;
|
||||
this.stackTrace = Arrays.stream(Thread.currentThread().getStackTrace())
|
||||
.filter(v -> !v.getClassName().startsWith(PACKAGE))
|
||||
.toArray(StackTraceElement[]::new);
|
||||
}
|
||||
|
||||
public T join(long interval, long timeout) throws TimeoutException {
|
||||
long start = System.currentTimeMillis();
|
||||
while (!isCompleted()) {
|
||||
if (System.currentTimeMillis() > start + timeout)
|
||||
throw new TimeoutException("Promise timed out after " + timeout + "ms");
|
||||
|
||||
try {
|
||||
Thread.sleep(interval);
|
||||
} catch (InterruptedException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
PromiseCompletion<T> completion = getCompletion();
|
||||
if (completion == null) {
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
|
||||
if (completion.isError()) {
|
||||
throw new RuntimeException(completion.getException());
|
||||
}
|
||||
|
||||
return completion.getResult();
|
||||
}
|
||||
|
||||
public @NotNull Promise<Void> thenRunSync(@NotNull ExceptionalRunnable task) {
|
||||
return thenApplySync(result -> {
|
||||
task.run();
|
||||
return null;
|
||||
}, Schedulers.getTrace(task));
|
||||
}
|
||||
|
||||
public @NotNull Promise<Void> thenRunDelayedSync(@NotNull ExceptionalRunnable task, long delay, @NotNull TimeUnit unit) {
|
||||
return thenApplyDelayedSync(result -> {
|
||||
task.run();
|
||||
return null;
|
||||
}, delay, unit, Schedulers.getTrace(task));
|
||||
}
|
||||
|
||||
public @NotNull Promise<Void> thenAcceptSync(@NotNull ExceptionalConsumer<T> task) {
|
||||
return thenApplySync(result -> {
|
||||
task.accept(result);
|
||||
return null;
|
||||
}, Schedulers.getTrace(task));
|
||||
}
|
||||
|
||||
public @NotNull Promise<Void> thenAcceptDelayedSync(@NotNull ExceptionalConsumer<T> task, long delay, @NotNull TimeUnit unit) {
|
||||
return thenApplyDelayedSync(result -> {
|
||||
task.accept(result);
|
||||
return null;
|
||||
}, delay, unit, Schedulers.getTrace(task));
|
||||
}
|
||||
|
||||
public <V> @NotNull Promise<V> thenSupplySync(@NotNull ExceptionalSupplier<V> task) {
|
||||
return thenApplySync(result -> task.get(), Schedulers.getTrace(task));
|
||||
}
|
||||
|
||||
public <V> @NotNull Promise<V> thenSupplyDelayedSync(@NotNull ExceptionalSupplier<V> task, long delay, @NotNull TimeUnit unit) {
|
||||
return thenApplyDelayedSync(result -> task.get(), delay, unit, Schedulers.getTrace(task));
|
||||
}
|
||||
|
||||
public <V> @NotNull Promise<V> thenApplySync(@NotNull ExceptionalFunction<T, V> task, @NotNull ExecutorTrace trace) {
|
||||
Promise<V> promise = new Promise<>();
|
||||
addListener(ctx -> {
|
||||
if (ctx.isError()) {
|
||||
//noinspection ConstantConditions
|
||||
promise.completeExceptionally(ctx.getException());
|
||||
return;
|
||||
}
|
||||
|
||||
Runnable runnable = createRunnable(ctx, promise, task);
|
||||
Schedulers.runSync(runnable, trace);
|
||||
});
|
||||
|
||||
return promise;
|
||||
}
|
||||
|
||||
public <V> @NotNull Promise<V> thenApplySync(@NotNull ExceptionalFunction<T, V> task) {
|
||||
return thenApplySync(task, Schedulers.getTrace(task));
|
||||
}
|
||||
|
||||
public <V> @NotNull Promise<V> thenApplyDelayedSync(@NotNull ExceptionalFunction<T, V> task, long delay, @NotNull TimeUnit unit, @NotNull ExecutorTrace trace) {
|
||||
Promise<V> promise = new Promise<>();
|
||||
addListener(ctx -> {
|
||||
if (ctx.isError()) {
|
||||
//noinspection ConstantConditions
|
||||
promise.completeExceptionally(ctx.getException());
|
||||
return;
|
||||
}
|
||||
|
||||
Runnable runnable = createRunnable(ctx, promise, task);
|
||||
Schedulers.runDelayedSync(runnable, delay, unit, trace);
|
||||
});
|
||||
|
||||
return promise;
|
||||
}
|
||||
|
||||
public <V> @NotNull Promise<V> thenApplyDelayedSync(@NotNull ExceptionalFunction<T, V> task, long delay, @NotNull TimeUnit unit) {
|
||||
return thenApplyDelayedSync(task, delay, unit, Schedulers.getTrace(task));
|
||||
}
|
||||
|
||||
public <V> @NotNull Promise<V> thenComposeSync(@NotNull ExceptionalFunction<T, @NotNull Promise<V>> task) {
|
||||
Promise<V> promise = new Promise<>();
|
||||
thenApplySync(task, Schedulers.getTrace(task)).thenAcceptAsync(nestedPromise -> {
|
||||
nestedPromise.addListener(ctx1 -> {
|
||||
if (ctx1.isError()) {
|
||||
//noinspection ConstantConditions
|
||||
promise.completeExceptionally(ctx1.getException());
|
||||
return;
|
||||
}
|
||||
|
||||
promise.complete(ctx1.getResult());
|
||||
});
|
||||
}).addListener(ctx2 -> {
|
||||
if (ctx2.isError()) {
|
||||
//noinspection ConstantConditions
|
||||
promise.completeExceptionally(ctx2.getException());
|
||||
}
|
||||
});
|
||||
|
||||
return promise;
|
||||
}
|
||||
|
||||
public @NotNull Promise<Void> thenRunAsync(@NotNull ExceptionalRunnable task) {
|
||||
return thenApplyAsync(result -> {
|
||||
task.run();
|
||||
return null;
|
||||
}, Schedulers.getTrace(task));
|
||||
}
|
||||
|
||||
public @NotNull Promise<Void> thenRunDelayedAsync(@NotNull ExceptionalRunnable task, long delay, @NotNull TimeUnit unit) {
|
||||
return thenApplyDelayedAsync(result -> {
|
||||
task.run();
|
||||
return null;
|
||||
}, delay, unit, Schedulers.getTrace(task));
|
||||
}
|
||||
|
||||
public @NotNull Promise<Void> thenAcceptAsync(@NotNull ExceptionalConsumer<T> task) {
|
||||
return thenApplyAsync(result -> {
|
||||
task.accept(result);
|
||||
return null;
|
||||
}, Schedulers.getTrace(task));
|
||||
}
|
||||
|
||||
public @NotNull Promise<Void> thenAcceptDelayedAsync(@NotNull ExceptionalConsumer<T> task, long delay, @NotNull TimeUnit unit) {
|
||||
return thenApplyDelayedAsync(result -> {
|
||||
task.accept(result);
|
||||
return null;
|
||||
}, delay, unit, Schedulers.getTrace(task));
|
||||
}
|
||||
|
||||
public <V> @NotNull Promise<V> thenSupplyAsync(@NotNull ExceptionalSupplier<V> task) {
|
||||
return thenApplyAsync(result -> task.get(), Schedulers.getTrace(task));
|
||||
}
|
||||
|
||||
public <V> @NotNull Promise<V> thenSupplyDelayedAsync(@NotNull ExceptionalSupplier<V> task, long delay, @NotNull TimeUnit unit) {
|
||||
return thenApplyDelayedAsync(result -> task.get(), delay, unit, Schedulers.getTrace(task));
|
||||
}
|
||||
|
||||
public @NotNull Promise<T> thenPopulateReference(@NotNull AtomicReference<T> reference) {
|
||||
return thenApplyAsync((result) -> {
|
||||
reference.set(result);
|
||||
return result;
|
||||
});
|
||||
}
|
||||
|
||||
public <V> @NotNull Promise<V> thenApplyAsync(@NotNull ExceptionalFunction<T, V> task, @NotNull ExecutorTrace trace) {
|
||||
Promise<V> promise = new Promise<>();
|
||||
addListener(ctx -> {
|
||||
createRunnable(ctx, promise, task).run();
|
||||
});
|
||||
|
||||
return promise;
|
||||
}
|
||||
|
||||
public <V> @NotNull Promise<V> thenApplyAsync(@NotNull ExceptionalFunction<T, V> task) {
|
||||
return thenApplyAsync(task, Schedulers.getTrace(task));
|
||||
}
|
||||
|
||||
public <V> @NotNull Promise<V> thenApplyDelayedAsync(@NotNull ExceptionalFunction<T, V> task, long delay, @NotNull TimeUnit unit, @NotNull ExecutorTrace trace) {
|
||||
Promise<V> promise = new Promise<>();
|
||||
addListener(ctx -> {
|
||||
Runnable runnable = createRunnable(ctx, promise, task);
|
||||
Schedulers.runDelayedAsync(runnable, delay, unit, trace);
|
||||
});
|
||||
|
||||
return promise;
|
||||
}
|
||||
|
||||
public <V> @NotNull Promise<V> thenApplyDelayedAsync(@NotNull ExceptionalFunction<T, V> task, long delay, @NotNull TimeUnit unit) {
|
||||
return thenApplyDelayedAsync(task, delay, unit, Schedulers.getTrace(task));
|
||||
}
|
||||
|
||||
public <V> @NotNull Promise<V> thenCompose(@NotNull ExceptionalFunction<T, Promise<V>> task) {
|
||||
return this.thenComposeAsync(task);
|
||||
}
|
||||
|
||||
public <V> @NotNull Promise<V> thenComposeAsync(@NotNull ExceptionalFunction<T, Promise<V>> task) {
|
||||
Promise<V> promise = new Promise<>();
|
||||
thenApplyAsync(task, Schedulers.getTrace(task)).thenAcceptAsync(nestedPromise -> {
|
||||
nestedPromise.addListener(ctx1 -> {
|
||||
if (ctx1.isError()) {
|
||||
//noinspection ConstantConditions
|
||||
promise.completeExceptionally(ctx1.getException());
|
||||
return;
|
||||
}
|
||||
|
||||
promise.complete(ctx1.getResult());
|
||||
});
|
||||
}).addListener(ctx2 -> {
|
||||
if (ctx2.isError()) {
|
||||
//noinspection ConstantConditions
|
||||
promise.completeExceptionally(ctx2.getException());
|
||||
}
|
||||
});
|
||||
|
||||
return promise;
|
||||
}
|
||||
|
||||
private <V> @NotNull Runnable createRunnable(@NotNull PromiseCompletion<T> ctx, @NotNull Promise<V> promise, @NotNull ExceptionalFunction<T, V> task) {
|
||||
return () -> {
|
||||
if (ctx.isError()) {
|
||||
//noinspection ConstantConditions
|
||||
promise.completeExceptionally(ctx.getException());
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
V result = task.apply(ctx.getResult());
|
||||
promise.complete(result);
|
||||
} catch (Exception e) {
|
||||
promise.completeExceptionally(e, true);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public @NotNull Promise<T> logExceptions() {
|
||||
return addListener(ctx -> {
|
||||
if (ctx.isError()) {
|
||||
LOGGER.error("Exception caught in promise pipeline", ctx.getException());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public @NotNull Promise<T> addListener(@NotNull PromiseListener<T> listener) {
|
||||
if (isCompleted()) {
|
||||
Schedulers.runAsync(() -> {
|
||||
try {
|
||||
listener.handle(getCompletion());
|
||||
} catch (Exception e) {
|
||||
LOGGER.error("Exception caught in promise listener", e);
|
||||
}
|
||||
}, Schedulers.getTrace(listener));
|
||||
} else {
|
||||
getListeners().add(listener);
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public @NotNull Promise<T> timeout(long time, @NotNull TimeUnit unit) {
|
||||
Schedulers.runDelayedAsync(() -> {
|
||||
if (!isCompleted()) {
|
||||
completeExceptionally(new TimeoutException("Promise timed out after " + time + " " + unit), true);
|
||||
}
|
||||
}, time, unit);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public @NotNull Promise<T> timeout(long ms) {
|
||||
return timeout(ms, TimeUnit.MILLISECONDS);
|
||||
}
|
||||
|
||||
protected void handleCompletion(@NotNull PromiseCompletion<T> ctx) {
|
||||
if (this.isCompleted()) return;
|
||||
setCompletion(ctx);
|
||||
|
||||
Schedulers.runAsync(() -> {
|
||||
for (PromiseListener<T> listener : getListeners()) {
|
||||
if (!ctx.isActive()) return;
|
||||
|
||||
try {
|
||||
listener.handle(ctx);
|
||||
} catch (Exception e) {
|
||||
LOGGER.error("Exception caught in promise listener", e);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void complete(@Nullable T result) {
|
||||
handleCompletion(new PromiseCompletion<>(result));
|
||||
}
|
||||
|
||||
public void completeExceptionally(@NotNull Throwable result, boolean appendStacktrace) {
|
||||
if (appendStacktrace && this.stackTrace != null) {
|
||||
result.setStackTrace(Stream.of(result.getStackTrace(), this.stackTrace)
|
||||
.flatMap(Stream::of)
|
||||
.filter(v -> !v.getClassName().startsWith(PACKAGE))
|
||||
.filter(v -> !v.getClassName().startsWith("java.lang.Thread"))
|
||||
.filter(v -> !v.getClassName().startsWith("java.util.concurrent"))
|
||||
.toArray(StackTraceElement[]::new));
|
||||
}
|
||||
|
||||
handleCompletion(new PromiseCompletion<>(result));
|
||||
}
|
||||
|
||||
public void completeExceptionally(@NotNull Throwable result) {
|
||||
completeExceptionally(result, false);
|
||||
}
|
||||
|
||||
public boolean isCompleted() {
|
||||
return getCompletion() != null;
|
||||
}
|
||||
|
||||
protected Collection<PromiseListener<T>> getListeners() {
|
||||
return listeners;
|
||||
}
|
||||
|
||||
public @Nullable PromiseCompletion<T> getCompletion() {
|
||||
return completion;
|
||||
}
|
||||
|
||||
protected void setCompletion(@NotNull PromiseCompletion<T> completion) {
|
||||
this.completion = completion;
|
||||
}
|
||||
|
||||
public static <T> @NotNull Promise<T> resolve(T value) {
|
||||
Promise<T> promise = new Promise<>();
|
||||
promise.setCompletion(new PromiseCompletion<>(value));
|
||||
return promise;
|
||||
}
|
||||
|
||||
public static <T> @NotNull Promise<T> error(Throwable error) {
|
||||
Promise<T> promise = new Promise<>();
|
||||
promise.completeExceptionally(error);
|
||||
return promise;
|
||||
}
|
||||
|
||||
public static @NotNull Promise<Void> start() {
|
||||
return Promise.resolve(null);
|
||||
}
|
||||
|
||||
@Deprecated // use resolve()
|
||||
public static <T> @NotNull Promise<T> start(T start) {
|
||||
Promise<T> promise = new Promise<>();
|
||||
promise.complete(start);
|
||||
return promise;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
package dev.tommyjs.futur.promise;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class PromiseCompletion<T> {
|
||||
|
||||
private @Nullable T result;
|
||||
private @Nullable Throwable exception;
|
||||
private boolean active;
|
||||
|
||||
public PromiseCompletion(@Nullable T result) {
|
||||
this.result = result;
|
||||
this.active = true;
|
||||
}
|
||||
|
||||
public PromiseCompletion(@NotNull Throwable exception) {
|
||||
this.exception = exception;
|
||||
this.active = true;
|
||||
}
|
||||
|
||||
public PromiseCompletion() {
|
||||
this.result = null;
|
||||
this.active = true;
|
||||
}
|
||||
|
||||
public void markHandled() {
|
||||
this.active = false;
|
||||
}
|
||||
|
||||
public boolean isActive() {
|
||||
return active;
|
||||
}
|
||||
|
||||
public boolean isError() {
|
||||
return getException() != null;
|
||||
}
|
||||
|
||||
public @Nullable T getResult() {
|
||||
return result;
|
||||
}
|
||||
|
||||
public @Nullable Throwable getException() {
|
||||
return exception;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package dev.tommyjs.futur.promise;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public interface PromiseListener<T> {
|
||||
|
||||
void handle(@NotNull PromiseCompletion<T> ctx);
|
||||
|
||||
}
|
||||
173
futur-api/src/main/java/dev/tommyjs/futur/promise/Promises.java
Normal file
173
futur-api/src/main/java/dev/tommyjs/futur/promise/Promises.java
Normal file
@@ -0,0 +1,173 @@
|
||||
package dev.tommyjs.futur.promise;
|
||||
|
||||
import dev.tommyjs.futur.function.ExceptionalFunction;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.concurrent.locks.ReentrantLock;
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class Promises {
|
||||
|
||||
public static <K, V> @NotNull Promise<Map.Entry<K, V>> combine(@NotNull Promise<K> p1, @NotNull Promise<V> p2) {
|
||||
Promise<Map.Entry<K, V>> promise = new Promise<>();
|
||||
p1.addListener(ctx -> {
|
||||
if (ctx.isError()) {
|
||||
//noinspection ConstantConditions
|
||||
promise.completeExceptionally(ctx.getException());
|
||||
return;
|
||||
}
|
||||
|
||||
p2.addListener(ctx1 -> {
|
||||
if (ctx1.isError()) {
|
||||
//noinspection ConstantConditions
|
||||
promise.completeExceptionally(ctx1.getException());
|
||||
return;
|
||||
}
|
||||
|
||||
Map.Entry<K, V> result = new AbstractMap.SimpleEntry<>(ctx.getResult(), ctx1.getResult());
|
||||
promise.complete(result);
|
||||
});
|
||||
});
|
||||
|
||||
return promise;
|
||||
}
|
||||
|
||||
public static <K, V> @NotNull Promise<Map<K, V>> combine(@NotNull Map<K, Promise<V>> promises, long timeout, @Nullable BiConsumer<K, Throwable> exceptionHandler) {
|
||||
Map<K, V> map = new HashMap<>();
|
||||
if (promises.isEmpty()) return Promise.resolve(map);
|
||||
|
||||
ReentrantLock lock = new ReentrantLock();
|
||||
|
||||
Promise<Map<K, V>> promise = new Promise<>();
|
||||
for (Map.Entry<K, Promise<V>> entry : promises.entrySet()) {
|
||||
entry.getValue().addListener((ctx) -> {
|
||||
lock.lock();
|
||||
|
||||
try {
|
||||
if (ctx.isError()) {
|
||||
if (exceptionHandler == null) {
|
||||
//noinspection ConstantConditions
|
||||
promise.completeExceptionally(ctx.getException());
|
||||
} else {
|
||||
exceptionHandler.accept(entry.getKey(), ctx.getException());
|
||||
map.put(entry.getKey(), null);
|
||||
}
|
||||
} else {
|
||||
map.put(entry.getKey(), ctx.getResult());
|
||||
}
|
||||
if (map.size() == promises.size()) promise.complete(map);
|
||||
} finally {
|
||||
lock.unlock();
|
||||
}
|
||||
});
|
||||
}
|
||||
return promise.timeout(timeout);
|
||||
}
|
||||
|
||||
public static <K, V> @NotNull Promise<Map<K, V>> combine(@NotNull Map<K, Promise<V>> promises, long timeout, boolean strict) {
|
||||
return combine(promises, timeout, strict ? null : (_k, _v) -> {});
|
||||
}
|
||||
|
||||
public static <K, V> @NotNull Promise<Map<K, V>> combine(@NotNull Map<K, Promise<V>> promises, long timeout) {
|
||||
return combine(promises, timeout, true);
|
||||
}
|
||||
|
||||
public static <K, V> @NotNull Promise<Map<K, V>> combine(@NotNull Map<K, Promise<V>> promises) {
|
||||
return combine(promises, 1500L, true);
|
||||
}
|
||||
|
||||
public static <V> @NotNull Promise<List<V>> combine(@NotNull List<Promise<V>> promises, long timeout, boolean strict) {
|
||||
AtomicInteger index = new AtomicInteger();
|
||||
return combine(
|
||||
promises.stream()
|
||||
.collect(Collectors.toMap(s -> index.getAndIncrement(), v -> v)),
|
||||
timeout,
|
||||
strict
|
||||
).thenApplySync(v ->
|
||||
v.entrySet().stream()
|
||||
.sorted(Map.Entry.comparingByKey())
|
||||
.map(Map.Entry::getValue)
|
||||
.collect(Collectors.toList())
|
||||
);
|
||||
}
|
||||
|
||||
public static <V> @NotNull Promise<List<V>> combine(@NotNull List<Promise<V>> promises, long timeout) {
|
||||
return combine(promises, timeout, true);
|
||||
}
|
||||
|
||||
public static <V> @NotNull Promise<List<V>> combine(@NotNull List<Promise<V>> promises) {
|
||||
return combine(promises, 1500L, true);
|
||||
}
|
||||
|
||||
public static @NotNull Promise<Void> all(@NotNull List<Promise<?>> promises) {
|
||||
if (promises.isEmpty()) return Promise.start();
|
||||
|
||||
Promise<Void> promise = new Promise<>();
|
||||
for (Promise<?> p : promises) {
|
||||
p.addListener((ctx) -> {
|
||||
if (ctx.isError()) {
|
||||
//noinspection ConstantConditions
|
||||
promise.completeExceptionally(ctx.getException());
|
||||
} else if (promises.stream().allMatch(Promise::isCompleted)) {
|
||||
promise.complete(null);
|
||||
}
|
||||
});
|
||||
}
|
||||
return promise;
|
||||
}
|
||||
|
||||
public static @NotNull Promise<Void> all(@NotNull Promise<?>... promises) {
|
||||
return all(Arrays.asList(promises));
|
||||
}
|
||||
|
||||
public static <K, V> @NotNull Promise<Map<K, V>> combine(@NotNull Collection<K> keys, @NotNull ExceptionalFunction<K, V> mapper, long timeout, boolean strict) {
|
||||
Map<K, Promise<V>> promises = new HashMap<>();
|
||||
for (K key : keys) {
|
||||
Promise<V> promise = Promise.resolve(key).thenApplyAsync(mapper);
|
||||
promises.put(key, promise);
|
||||
}
|
||||
|
||||
return combine(promises, timeout, strict);
|
||||
}
|
||||
|
||||
public static <K, V> @NotNull Promise<Map<K, V>> combine(@NotNull Collection<K> keys, @NotNull ExceptionalFunction<K, V> mapper, long timeout) {
|
||||
return combine(keys, mapper, timeout, true);
|
||||
}
|
||||
|
||||
public static <K, V> @NotNull Promise<Map<K, V>> combine(@NotNull Collection<K> keys, @NotNull ExceptionalFunction<K, V> mapper) {
|
||||
return combine(keys, mapper, 1500L, true);
|
||||
}
|
||||
|
||||
public static @NotNull Promise<Void> erase(@NotNull Promise<?> p) {
|
||||
Promise<Void> promise = new Promise<>();
|
||||
p.addListener(ctx -> {
|
||||
if (ctx.isError()) {
|
||||
//noinspection ConstantConditions
|
||||
promise.completeExceptionally(ctx.getException());
|
||||
} else {
|
||||
promise.complete(null);
|
||||
}
|
||||
});
|
||||
|
||||
return promise;
|
||||
}
|
||||
|
||||
public static <T> @NotNull Promise<T> wrap(@NotNull CompletableFuture<T> future) {
|
||||
Promise<T> promise = new Promise<>();
|
||||
future.whenComplete((result, e) -> {
|
||||
if (e != null) {
|
||||
promise.completeExceptionally(e);
|
||||
} else {
|
||||
promise.complete(result);
|
||||
}
|
||||
});
|
||||
|
||||
return promise;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
package dev.tommyjs.futur.scheduler;
|
||||
|
||||
import dev.tommyjs.futur.trace.ExecutorTrace;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public interface Scheduler {
|
||||
|
||||
Logger LOGGER = LoggerFactory.getLogger(Scheduler.class);
|
||||
|
||||
void runSync(@NotNull Runnable task, @NotNull ExecutorTrace trace);
|
||||
|
||||
void runDelayedSync(@NotNull Runnable task, long delay, @NotNull TimeUnit unit, @NotNull ExecutorTrace trace);
|
||||
|
||||
void runRepeatingSync(@NotNull Runnable task, long interval, @NotNull TimeUnit unit, @NotNull ExecutorTrace trace);
|
||||
|
||||
void runAsync(@NotNull Runnable task, @NotNull ExecutorTrace trace);
|
||||
|
||||
void runDelayedAsync(@NotNull Runnable task, long delay, @NotNull TimeUnit unit, @NotNull ExecutorTrace trace);
|
||||
|
||||
void runRepeatingAsync(@NotNull Runnable task, long interval, @NotNull TimeUnit unit, @NotNull ExecutorTrace trace);
|
||||
|
||||
default @NotNull Runnable wrapExceptions(@NotNull Runnable task, @NotNull ExecutorTrace trace) {
|
||||
return () -> {
|
||||
try {
|
||||
task.run();
|
||||
} catch (Exception e) {
|
||||
LOGGER.error("Exception in scheduled task: {}", e.getClass().getName());
|
||||
LOGGER.error(trace.toString());
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,105 @@
|
||||
package dev.tommyjs.futur.scheduler;
|
||||
|
||||
import dev.tommyjs.futur.trace.ExecutorTrace;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
@SuppressWarnings("ConstantConditions")
|
||||
public class Schedulers {
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(Schedulers.class);
|
||||
|
||||
private static @Nullable Scheduler scheduler;
|
||||
|
||||
public static void runSync(@NotNull Runnable task, @NotNull ExecutorTrace trace) {
|
||||
ensureLoaded();
|
||||
getScheduler().runSync(task, trace);
|
||||
}
|
||||
|
||||
public static void runSync(@NotNull Runnable task) {
|
||||
ensureLoaded();
|
||||
getScheduler().runSync(task, Schedulers.getTrace(task));
|
||||
}
|
||||
|
||||
public static void runDelayedSync(@NotNull Runnable task, long delay, @NotNull TimeUnit unit, @NotNull ExecutorTrace trace) {
|
||||
ensureLoaded();
|
||||
getScheduler().runDelayedSync(task, delay, unit, trace);
|
||||
}
|
||||
|
||||
public static void runDelayedSync(@NotNull Runnable task, long delay, @NotNull TimeUnit unit) {
|
||||
ensureLoaded();
|
||||
getScheduler().runDelayedSync(task, delay, unit, Schedulers.getTrace(task));
|
||||
}
|
||||
|
||||
public static void runRepeatingSync(@NotNull Runnable task, long interval, @NotNull TimeUnit unit, @NotNull ExecutorTrace trace) {
|
||||
ensureLoaded();
|
||||
getScheduler().runRepeatingSync(task, interval, unit, trace);
|
||||
}
|
||||
|
||||
public static void runRepeatingSync(@NotNull Runnable task, long interval, @NotNull TimeUnit unit) {
|
||||
ensureLoaded();
|
||||
getScheduler().runRepeatingSync(task, interval, unit, Schedulers.getTrace(task));
|
||||
}
|
||||
|
||||
public static void runAsync(@NotNull Runnable task, @NotNull ExecutorTrace trace) {
|
||||
ensureLoaded();
|
||||
getScheduler().runAsync(task, trace);
|
||||
}
|
||||
|
||||
public static void runAsync(@NotNull Runnable task) {
|
||||
ensureLoaded();
|
||||
getScheduler().runAsync(task, Schedulers.getTrace(task));
|
||||
}
|
||||
|
||||
public static void runDelayedAsync(@NotNull Runnable task, long delay, TimeUnit unit, ExecutorTrace trace) {
|
||||
ensureLoaded();
|
||||
getScheduler().runDelayedAsync(task, delay, unit, trace);
|
||||
}
|
||||
|
||||
public static void runDelayedAsync(@NotNull Runnable task, long delay, @NotNull TimeUnit unit) {
|
||||
ensureLoaded();
|
||||
getScheduler().runDelayedAsync(task, delay, unit, Schedulers.getTrace(task));
|
||||
}
|
||||
|
||||
public static void runRepeatingAsync(@NotNull Runnable task, long interval, @NotNull TimeUnit unit, @NotNull ExecutorTrace trace) {
|
||||
ensureLoaded();
|
||||
getScheduler().runRepeatingAsync(task, interval, unit, trace);
|
||||
}
|
||||
|
||||
public static void runRepeatingAsync(@NotNull Runnable task, long interval, @NotNull TimeUnit unit) {
|
||||
ensureLoaded();
|
||||
getScheduler().runRepeatingAsync(task, interval, unit, Schedulers.getTrace(task));
|
||||
}
|
||||
|
||||
public static ExecutorTrace getTrace(@NotNull Object function) {
|
||||
return new ExecutorTrace(function.getClass(), Thread.currentThread().getStackTrace());
|
||||
}
|
||||
|
||||
public static void ensureLoaded() {
|
||||
if (getScheduler() == null) {
|
||||
LOGGER.warn("No scheduler loaded, falling back to default single threaded scheduler");
|
||||
setScheduler(SingleExecutorScheduler.create());
|
||||
}
|
||||
}
|
||||
|
||||
public static void loadDefaultScheduler() {
|
||||
|
||||
}
|
||||
|
||||
public static boolean isLoaded() {
|
||||
return getScheduler() != null;
|
||||
}
|
||||
|
||||
public static @Nullable Scheduler getScheduler() {
|
||||
return scheduler;
|
||||
}
|
||||
|
||||
public static void setScheduler(@NotNull Scheduler scheduler) {
|
||||
Schedulers.scheduler = scheduler;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
package dev.tommyjs.futur.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 SingleExecutorScheduler implements Scheduler {
|
||||
|
||||
private final ScheduledExecutorService service;
|
||||
|
||||
protected SingleExecutorScheduler(ScheduledExecutorService service) {
|
||||
this.service = service;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void runSync(@NotNull Runnable task, @NotNull ExecutorTrace trace) {
|
||||
service.submit(wrapExceptions(task, trace));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void runDelayedSync(@NotNull Runnable task, long delay, @NotNull TimeUnit unit, @NotNull ExecutorTrace trace) {
|
||||
service.schedule(wrapExceptions(task, trace), delay, unit);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void runRepeatingSync(@NotNull Runnable task, long interval, @NotNull TimeUnit unit, @NotNull ExecutorTrace trace) {
|
||||
service.scheduleAtFixedRate(wrapExceptions(task, trace), 0L, interval, unit);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void runAsync(@NotNull Runnable task, @NotNull ExecutorTrace trace) {
|
||||
runSync(task, trace);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void runDelayedAsync(@NotNull Runnable task, long delay, @NotNull TimeUnit unit, @NotNull ExecutorTrace trace) {
|
||||
runDelayedSync(task, delay, unit, trace);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void runRepeatingAsync(@NotNull Runnable task, long interval, @NotNull TimeUnit unit, @NotNull ExecutorTrace trace) {
|
||||
runRepeatingSync(task, interval, unit, trace);
|
||||
}
|
||||
|
||||
public static SingleExecutorScheduler create() {
|
||||
return new SingleExecutorScheduler(Executors.newSingleThreadScheduledExecutor());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
package dev.tommyjs.futur.trace;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class ExecutorTrace {
|
||||
|
||||
private final @NotNull Class<?> clazz;
|
||||
private final @NotNull StackTraceElement[] trace;
|
||||
|
||||
public ExecutorTrace(@NotNull Class<?> clazz, @NotNull StackTraceElement[] trace) {
|
||||
this.clazz = clazz;
|
||||
this.trace = trace;
|
||||
}
|
||||
|
||||
public @NotNull Class<?> getClazz() {
|
||||
return clazz;
|
||||
}
|
||||
|
||||
public @NotNull StackTraceElement[] getTrace() {
|
||||
return trace;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return Arrays.stream(trace).map(StackTraceElement::toString).collect(Collectors.joining("\n"));
|
||||
}
|
||||
|
||||
}
|
||||
42
futur-reactive-streams/.gitignore
vendored
Normal file
42
futur-reactive-streams/.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
|
||||
35
futur-reactive-streams/build.gradle.kts
Normal file
35
futur-reactive-streams/build.gradle.kts
Normal file
@@ -0,0 +1,35 @@
|
||||
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")))
|
||||
compileOnly("org.reactivestreams:reactive-streams:1.0.4")
|
||||
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,15 @@
|
||||
package dev.tommyjs.futur.reactivestreams;
|
||||
|
||||
import dev.tommyjs.futur.promise.Promise;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.reactivestreams.Publisher;
|
||||
|
||||
public class ReactiveTransformer {
|
||||
|
||||
public static <T> @NotNull Promise<T> wrapPublisher(@NotNull Publisher<T> publisher) {
|
||||
SingleAccumulatorSubscriber<T> subscriber = SingleAccumulatorSubscriber.create();
|
||||
publisher.subscribe(subscriber);
|
||||
return subscriber.getPromise();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
package dev.tommyjs.futur.reactivestreams;
|
||||
|
||||
import dev.tommyjs.futur.promise.Promise;
|
||||
import org.reactivestreams.Subscriber;
|
||||
import org.reactivestreams.Subscription;
|
||||
|
||||
public class SingleAccumulatorSubscriber<T> implements Subscriber<T> {
|
||||
|
||||
private final Promise<T> promise;
|
||||
|
||||
public SingleAccumulatorSubscriber(Promise<T> promise) {
|
||||
this.promise = promise;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSubscribe(Subscription s) {
|
||||
s.request(1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNext(T t) {
|
||||
promise.complete(t);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(Throwable t) {
|
||||
promise.completeExceptionally(t);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onComplete() {
|
||||
// ignore
|
||||
}
|
||||
|
||||
public Promise<T> getPromise() {
|
||||
return promise;
|
||||
}
|
||||
|
||||
public static <T> SingleAccumulatorSubscriber<T> create(Promise<T> promise) {
|
||||
return new SingleAccumulatorSubscriber<>(promise);
|
||||
}
|
||||
|
||||
public static <T> SingleAccumulatorSubscriber<T> create() {
|
||||
return create(new Promise<>());
|
||||
}
|
||||
|
||||
}
|
||||
42
futur-reactor/.gitignore
vendored
Normal file
42
futur-reactor/.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
|
||||
24
futur-reactor/build.gradle.kts
Normal file
24
futur-reactor/build.gradle.kts
Normal file
@@ -0,0 +1,24 @@
|
||||
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")))
|
||||
implementation("io.projectreactor:reactor-core:3.6.0")
|
||||
implementation(project(mapOf("path" to ":futur-reactive-streams")))
|
||||
testImplementation(platform("org.junit:junit-bom:5.9.1"))
|
||||
testImplementation("org.junit.jupiter:junit-jupiter")
|
||||
}
|
||||
|
||||
tasks.test {
|
||||
useJUnitPlatform()
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
package dev.tommyjs.futur.reactor;
|
||||
|
||||
import dev.tommyjs.futur.promise.Promise;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import reactor.core.publisher.Flux;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
public class ReactorTransformer {
|
||||
|
||||
public static <T> @NotNull Promise<T> wrapMono(@NotNull Mono<T> mono) {
|
||||
Promise<T> promise = new Promise<>();
|
||||
mono.doOnSuccess(promise::complete).doOnError(promise::completeExceptionally).subscribe();
|
||||
return promise;
|
||||
}
|
||||
|
||||
public static <T> @NotNull Promise<@NotNull List<T>> wrapFlux(@NotNull Flux<T> flux) {
|
||||
Promise<List<T>> promise = new Promise<>();
|
||||
AtomicReference<List<T>> out = new AtomicReference<>(new ArrayList<>());
|
||||
|
||||
flux.doOnNext(out.get()::add).subscribe();
|
||||
flux.doOnComplete(() -> promise.complete(out.get())).subscribe();
|
||||
flux.doOnError(promise::completeExceptionally).subscribe();
|
||||
|
||||
return promise;
|
||||
}
|
||||
|
||||
}
|
||||
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));
|
||||
}
|
||||
|
||||
}
|
||||
BIN
gradle/wrapper/gradle-wrapper.jar
vendored
Normal file
BIN
gradle/wrapper/gradle-wrapper.jar
vendored
Normal file
Binary file not shown.
6
gradle/wrapper/gradle-wrapper.properties
vendored
Normal file
6
gradle/wrapper/gradle-wrapper.properties
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
#Sun Nov 19 18:44:26 GMT 2023
|
||||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.0-bin.zip
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
||||
234
gradlew
vendored
Normal file
234
gradlew
vendored
Normal file
@@ -0,0 +1,234 @@
|
||||
#!/bin/sh
|
||||
|
||||
#
|
||||
# Copyright © 2015-2021 the original authors.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# https://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
##############################################################################
|
||||
#
|
||||
# Gradle start up script for POSIX generated by Gradle.
|
||||
#
|
||||
# Important for running:
|
||||
#
|
||||
# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is
|
||||
# noncompliant, but you have some other compliant shell such as ksh or
|
||||
# bash, then to run this script, type that shell name before the whole
|
||||
# command line, like:
|
||||
#
|
||||
# ksh Gradle
|
||||
#
|
||||
# Busybox and similar reduced shells will NOT work, because this script
|
||||
# requires all of these POSIX shell features:
|
||||
# * functions;
|
||||
# * expansions «$var», «${var}», «${var:-default}», «${var+SET}»,
|
||||
# «${var#prefix}», «${var%suffix}», and «$( cmd )»;
|
||||
# * compound commands having a testable exit status, especially «case»;
|
||||
# * various built-in commands including «command», «set», and «ulimit».
|
||||
#
|
||||
# Important for patching:
|
||||
#
|
||||
# (2) This script targets any POSIX shell, so it avoids extensions provided
|
||||
# by Bash, Ksh, etc; in particular arrays are avoided.
|
||||
#
|
||||
# The "traditional" practice of packing multiple parameters into a
|
||||
# space-separated string is a well documented source of bugs and security
|
||||
# problems, so this is (mostly) avoided, by progressively accumulating
|
||||
# options in "$@", and eventually passing that to Java.
|
||||
#
|
||||
# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS,
|
||||
# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly;
|
||||
# see the in-line comments for details.
|
||||
#
|
||||
# There are tweaks for specific operating systems such as AIX, CygWin,
|
||||
# Darwin, MinGW, and NonStop.
|
||||
#
|
||||
# (3) This script is generated from the Groovy template
|
||||
# https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
|
||||
# within the Gradle project.
|
||||
#
|
||||
# You can find Gradle at https://github.com/gradle/gradle/.
|
||||
#
|
||||
##############################################################################
|
||||
|
||||
# Attempt to set APP_HOME
|
||||
|
||||
# Resolve links: $0 may be a link
|
||||
app_path=$0
|
||||
|
||||
# Need this for daisy-chained symlinks.
|
||||
while
|
||||
APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path
|
||||
[ -h "$app_path" ]
|
||||
do
|
||||
ls=$( ls -ld "$app_path" )
|
||||
link=${ls#*' -> '}
|
||||
case $link in #(
|
||||
/*) app_path=$link ;; #(
|
||||
*) app_path=$APP_HOME$link ;;
|
||||
esac
|
||||
done
|
||||
|
||||
APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit
|
||||
|
||||
APP_NAME="Gradle"
|
||||
APP_BASE_NAME=${0##*/}
|
||||
|
||||
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
|
||||
|
||||
# Use the maximum available, or set MAX_FD != -1 to use that value.
|
||||
MAX_FD=maximum
|
||||
|
||||
warn () {
|
||||
echo "$*"
|
||||
} >&2
|
||||
|
||||
die () {
|
||||
echo
|
||||
echo "$*"
|
||||
echo
|
||||
exit 1
|
||||
} >&2
|
||||
|
||||
# OS specific support (must be 'true' or 'false').
|
||||
cygwin=false
|
||||
msys=false
|
||||
darwin=false
|
||||
nonstop=false
|
||||
case "$( uname )" in #(
|
||||
CYGWIN* ) cygwin=true ;; #(
|
||||
Darwin* ) darwin=true ;; #(
|
||||
MSYS* | MINGW* ) msys=true ;; #(
|
||||
NONSTOP* ) nonstop=true ;;
|
||||
esac
|
||||
|
||||
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
|
||||
|
||||
|
||||
# Determine the Java command to use to start the JVM.
|
||||
if [ -n "$JAVA_HOME" ] ; then
|
||||
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
|
||||
# IBM's JDK on AIX uses strange locations for the executables
|
||||
JAVACMD=$JAVA_HOME/jre/sh/java
|
||||
else
|
||||
JAVACMD=$JAVA_HOME/bin/java
|
||||
fi
|
||||
if [ ! -x "$JAVACMD" ] ; then
|
||||
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
|
||||
|
||||
Please set the JAVA_HOME variable in your environment to match the
|
||||
location of your Java installation."
|
||||
fi
|
||||
else
|
||||
JAVACMD=java
|
||||
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
||||
|
||||
Please set the JAVA_HOME variable in your environment to match the
|
||||
location of your Java installation."
|
||||
fi
|
||||
|
||||
# Increase the maximum file descriptors if we can.
|
||||
if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
|
||||
case $MAX_FD in #(
|
||||
max*)
|
||||
MAX_FD=$( ulimit -H -n ) ||
|
||||
warn "Could not query maximum file descriptor limit"
|
||||
esac
|
||||
case $MAX_FD in #(
|
||||
'' | soft) :;; #(
|
||||
*)
|
||||
ulimit -n "$MAX_FD" ||
|
||||
warn "Could not set maximum file descriptor limit to $MAX_FD"
|
||||
esac
|
||||
fi
|
||||
|
||||
# Collect all arguments for the java command, stacking in reverse order:
|
||||
# * args from the command line
|
||||
# * the main class name
|
||||
# * -classpath
|
||||
# * -D...appname settings
|
||||
# * --module-path (only if needed)
|
||||
# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables.
|
||||
|
||||
# For Cygwin or MSYS, switch paths to Windows format before running java
|
||||
if "$cygwin" || "$msys" ; then
|
||||
APP_HOME=$( cygpath --path --mixed "$APP_HOME" )
|
||||
CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" )
|
||||
|
||||
JAVACMD=$( cygpath --unix "$JAVACMD" )
|
||||
|
||||
# Now convert the arguments - kludge to limit ourselves to /bin/sh
|
||||
for arg do
|
||||
if
|
||||
case $arg in #(
|
||||
-*) false ;; # don't mess with options #(
|
||||
/?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath
|
||||
[ -e "$t" ] ;; #(
|
||||
*) false ;;
|
||||
esac
|
||||
then
|
||||
arg=$( cygpath --path --ignore --mixed "$arg" )
|
||||
fi
|
||||
# Roll the args list around exactly as many times as the number of
|
||||
# args, so each arg winds up back in the position where it started, but
|
||||
# possibly modified.
|
||||
#
|
||||
# NB: a `for` loop captures its iteration list before it begins, so
|
||||
# changing the positional parameters here affects neither the number of
|
||||
# iterations, nor the values presented in `arg`.
|
||||
shift # remove old arg
|
||||
set -- "$@" "$arg" # push replacement arg
|
||||
done
|
||||
fi
|
||||
|
||||
# Collect all arguments for the java command;
|
||||
# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of
|
||||
# shell script including quotes and variable substitutions, so put them in
|
||||
# double quotes to make sure that they get re-expanded; and
|
||||
# * put everything else in single quotes, so that it's not re-expanded.
|
||||
|
||||
set -- \
|
||||
"-Dorg.gradle.appname=$APP_BASE_NAME" \
|
||||
-classpath "$CLASSPATH" \
|
||||
org.gradle.wrapper.GradleWrapperMain \
|
||||
"$@"
|
||||
|
||||
# Use "xargs" to parse quoted args.
|
||||
#
|
||||
# With -n1 it outputs one arg per line, with the quotes and backslashes removed.
|
||||
#
|
||||
# In Bash we could simply go:
|
||||
#
|
||||
# readarray ARGS < <( xargs -n1 <<<"$var" ) &&
|
||||
# set -- "${ARGS[@]}" "$@"
|
||||
#
|
||||
# but POSIX shell has neither arrays nor command substitution, so instead we
|
||||
# post-process each arg (as a line of input to sed) to backslash-escape any
|
||||
# character that might be a shell metacharacter, then use eval to reverse
|
||||
# that process (while maintaining the separation between arguments), and wrap
|
||||
# the whole thing up as a single "set" statement.
|
||||
#
|
||||
# This will of course break if any of these variables contains a newline or
|
||||
# an unmatched quote.
|
||||
#
|
||||
|
||||
eval "set -- $(
|
||||
printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" |
|
||||
xargs -n1 |
|
||||
sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' |
|
||||
tr '\n' ' '
|
||||
)" '"$@"'
|
||||
|
||||
exec "$JAVACMD" "$@"
|
||||
89
gradlew.bat
vendored
Normal file
89
gradlew.bat
vendored
Normal file
@@ -0,0 +1,89 @@
|
||||
@rem
|
||||
@rem Copyright 2015 the original author or authors.
|
||||
@rem
|
||||
@rem Licensed under the Apache License, Version 2.0 (the "License");
|
||||
@rem you may not use this file except in compliance with the License.
|
||||
@rem You may obtain a copy of the License at
|
||||
@rem
|
||||
@rem https://www.apache.org/licenses/LICENSE-2.0
|
||||
@rem
|
||||
@rem Unless required by applicable law or agreed to in writing, software
|
||||
@rem distributed under the License is distributed on an "AS IS" BASIS,
|
||||
@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
@rem See the License for the specific language governing permissions and
|
||||
@rem limitations under the License.
|
||||
@rem
|
||||
|
||||
@if "%DEBUG%" == "" @echo off
|
||||
@rem ##########################################################################
|
||||
@rem
|
||||
@rem Gradle startup script for Windows
|
||||
@rem
|
||||
@rem ##########################################################################
|
||||
|
||||
@rem Set local scope for the variables with windows NT shell
|
||||
if "%OS%"=="Windows_NT" setlocal
|
||||
|
||||
set DIRNAME=%~dp0
|
||||
if "%DIRNAME%" == "" set DIRNAME=.
|
||||
set APP_BASE_NAME=%~n0
|
||||
set APP_HOME=%DIRNAME%
|
||||
|
||||
@rem Resolve any "." and ".." in APP_HOME to make it shorter.
|
||||
for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
|
||||
|
||||
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||
set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
|
||||
|
||||
@rem Find java.exe
|
||||
if defined JAVA_HOME goto findJavaFromJavaHome
|
||||
|
||||
set JAVA_EXE=java.exe
|
||||
%JAVA_EXE% -version >NUL 2>&1
|
||||
if "%ERRORLEVEL%" == "0" goto execute
|
||||
|
||||
echo.
|
||||
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
||||
echo.
|
||||
echo Please set the JAVA_HOME variable in your environment to match the
|
||||
echo location of your Java installation.
|
||||
|
||||
goto fail
|
||||
|
||||
:findJavaFromJavaHome
|
||||
set JAVA_HOME=%JAVA_HOME:"=%
|
||||
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
|
||||
|
||||
if exist "%JAVA_EXE%" goto execute
|
||||
|
||||
echo.
|
||||
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
|
||||
echo.
|
||||
echo Please set the JAVA_HOME variable in your environment to match the
|
||||
echo location of your Java installation.
|
||||
|
||||
goto fail
|
||||
|
||||
:execute
|
||||
@rem Setup the command line
|
||||
|
||||
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
|
||||
|
||||
|
||||
@rem Execute Gradle
|
||||
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
|
||||
|
||||
:end
|
||||
@rem End local scope for the variables with windows NT shell
|
||||
if "%ERRORLEVEL%"=="0" goto mainEnd
|
||||
|
||||
:fail
|
||||
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
|
||||
rem the _cmd.exe /c_ return code!
|
||||
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
|
||||
exit /b 1
|
||||
|
||||
:mainEnd
|
||||
if "%OS%"=="Windows_NT" endlocal
|
||||
|
||||
:omega
|
||||
5
settings.gradle.kts
Normal file
5
settings.gradle.kts
Normal file
@@ -0,0 +1,5 @@
|
||||
rootProject.name = "futur"
|
||||
include("futur-api")
|
||||
include("futur-standalone")
|
||||
include("futur-reactive-streams")
|
||||
include("futur-reactor")
|
||||
Reference in New Issue
Block a user