-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(#105): Add reactive Job interface
- Loading branch information
Showing
7 changed files
with
175 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
core/src/main/java/io/github/zero88/schedulerx/CompletionStageJob.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package io.github.zero88.schedulerx; | ||
|
||
import java.util.concurrent.CompletionStage; | ||
|
||
import org.jetbrains.annotations.NotNull; | ||
|
||
import io.vertx.core.Future; | ||
|
||
/** | ||
* Job interface for java concurrent {@link CompletionStage}. | ||
* | ||
* @since 2.0.0 | ||
*/ | ||
public interface CompletionStageJob<INPUT, OUTPUT> | ||
extends FuturableJob<INPUT, OUTPUT, CompletionStage<OUTPUT>, ExecutionContext<OUTPUT>> { | ||
|
||
@Override | ||
default ExecutionContext<OUTPUT> transformContext(@NotNull ExecutionContext<OUTPUT> executionContext) { | ||
return executionContext; | ||
} | ||
|
||
@Override | ||
default Future<OUTPUT> transformResult(CompletionStage<OUTPUT> result) { | ||
return Future.fromCompletionStage(result); | ||
} | ||
|
||
CompletionStage<OUTPUT> doAsync(@NotNull JobData<INPUT> jobData, | ||
@NotNull ExecutionContext<OUTPUT> executionContext); | ||
|
||
} |
54 changes: 54 additions & 0 deletions
54
core/src/main/java/io/github/zero88/schedulerx/FuturableJob.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package io.github.zero88.schedulerx; | ||
|
||
import org.jetbrains.annotations.NotNull; | ||
|
||
import io.vertx.core.Future; | ||
|
||
/** | ||
* An interface supports reactive version for {@code Job}. | ||
* <p/> | ||
* This interface bridges you to write a new {@code Job} that based on your flavor async coding style and the reactive | ||
* library such as <a href="https://reactivex.io/">#reactivex</a> or | ||
* <a href="https://smallrye.io/smallrye-mutiny">#mutiny</a> | ||
* | ||
* @param <INPUT> Type of job input | ||
* @param <OUTPUT> Type of job output | ||
* @param <R> Type of {@code Rxified} execution result | ||
* @param <CTX> Type of {@code Rxified} execution context | ||
* @since 2.0.0 | ||
*/ | ||
public interface FuturableJob<INPUT, OUTPUT, R, CTX> extends AsyncJob<INPUT, OUTPUT> { | ||
|
||
@Override | ||
default Future<OUTPUT> asyncExecute(@NotNull JobData<INPUT> jobData, | ||
@NotNull ExecutionContext<OUTPUT> executionContext) { | ||
return transformResult(doAsync(jobData, transformContext(executionContext))); | ||
} | ||
|
||
/** | ||
* Transform execution context to {@code Rxified} execution context | ||
* | ||
* @param executionContext job execution context | ||
* @return {@code Rxified} execution context | ||
* @see ExecutionContext | ||
*/ | ||
CTX transformContext(@NotNull ExecutionContext<OUTPUT> executionContext); | ||
|
||
/** | ||
* Transform the {@code Rxified} execution result to {@code Vert.x} {@link Future} version | ||
* | ||
* @param result {@code Rxified} execution result | ||
* @return the execution result in {@link Future} | ||
*/ | ||
Future<OUTPUT> transformResult(R result); | ||
|
||
/** | ||
* Async execute | ||
* | ||
* @param jobData job data | ||
* @param executionContext job execution context | ||
* @return the {@code Rxified} execution result | ||
*/ | ||
R doAsync(@NotNull JobData<INPUT> jobData, @NotNull CTX executionContext); | ||
|
||
} |
30 changes: 30 additions & 0 deletions
30
core/src/main/java/io/github/zero88/schedulerx/mutiny/MutinyJob.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package io.github.zero88.schedulerx.mutiny; | ||
|
||
import org.jetbrains.annotations.NotNull; | ||
|
||
import io.github.zero88.schedulerx.FuturableJob; | ||
import io.github.zero88.schedulerx.JobData; | ||
import io.smallrye.mutiny.Uni; | ||
import io.smallrye.mutiny.vertx.UniHelper; | ||
import io.vertx.core.Future; | ||
|
||
/** | ||
* Job interface for {@link Uni} in <a href="https://smallrye.io/smallrye-mutiny">#mutiny</a> version. | ||
* | ||
* @since 2.0.0 | ||
*/ | ||
public interface MutinyJob<INPUT, OUTPUT> extends FuturableJob<INPUT, OUTPUT, Uni<OUTPUT>, ExecutionContext<OUTPUT>> { | ||
|
||
@Override | ||
default ExecutionContext<OUTPUT> transformContext( | ||
@NotNull io.github.zero88.schedulerx.ExecutionContext<OUTPUT> executionContext) { | ||
return ExecutionContext.newInstance(executionContext); | ||
} | ||
|
||
@Override | ||
default Future<OUTPUT> transformResult(Uni<OUTPUT> result) { return UniHelper.toFuture(result); } | ||
|
||
Uni<OUTPUT> asyncExecute(@NotNull JobData<INPUT> jobData, | ||
@NotNull io.github.zero88.schedulerx.mutiny.ExecutionContext<OUTPUT> executionContext); | ||
|
||
} |
15 changes: 15 additions & 0 deletions
15
core/src/main/java/io/github/zero88/schedulerx/rxjava3/Rx3Job.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package io.github.zero88.schedulerx.rxjava3; | ||
|
||
import org.jetbrains.annotations.NotNull; | ||
|
||
import io.github.zero88.schedulerx.FuturableJob; | ||
|
||
interface Rx3Job<INPUT, OUTPUT, T> extends FuturableJob<INPUT, OUTPUT, T, ExecutionContext<OUTPUT>> { | ||
|
||
@Override | ||
default ExecutionContext<OUTPUT> transformContext( | ||
io.github.zero88.schedulerx.@NotNull ExecutionContext<OUTPUT> executionContext) { | ||
return ExecutionContext.newInstance(executionContext); | ||
} | ||
|
||
} |
23 changes: 23 additions & 0 deletions
23
core/src/main/java/io/github/zero88/schedulerx/rxjava3/Rx3MaybeJob.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package io.github.zero88.schedulerx.rxjava3; | ||
|
||
import org.jetbrains.annotations.NotNull; | ||
|
||
import io.github.zero88.schedulerx.JobData; | ||
import io.reactivex.rxjava3.core.Maybe; | ||
import io.vertx.core.Future; | ||
import io.vertx.rxjava3.MaybeHelper; | ||
|
||
/** | ||
* Job interface for {@link Maybe} in <a href="https://reactivex.io/">#reactivex</a> version. | ||
* | ||
* @since 2.0.0 | ||
*/ | ||
public interface Rx3MaybeJob<INPUT, OUTPUT> extends Rx3Job<INPUT, OUTPUT, Maybe<OUTPUT>> { | ||
|
||
@Override | ||
default Future<OUTPUT> transformResult(Maybe<OUTPUT> result) { return MaybeHelper.toFuture(result); } | ||
|
||
Maybe<OUTPUT> asyncExecute(@NotNull JobData<INPUT> jobData, | ||
@NotNull io.github.zero88.schedulerx.rxjava3.ExecutionContext<OUTPUT> executionContext); | ||
|
||
} |
23 changes: 23 additions & 0 deletions
23
core/src/main/java/io/github/zero88/schedulerx/rxjava3/Rx3SingleJob.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package io.github.zero88.schedulerx.rxjava3; | ||
|
||
import org.jetbrains.annotations.NotNull; | ||
|
||
import io.github.zero88.schedulerx.JobData; | ||
import io.reactivex.rxjava3.core.Single; | ||
import io.vertx.core.Future; | ||
import io.vertx.rxjava3.SingleHelper; | ||
|
||
/** | ||
* Job interface for {@link Single} in <a href="https://reactivex.io/">#reactivex</a> version. | ||
* | ||
* @since 2.0.0 | ||
*/ | ||
public interface Rx3SingleJob<INPUT, OUTPUT> extends Rx3Job<INPUT, OUTPUT, Single<OUTPUT>> { | ||
|
||
@Override | ||
default Future<OUTPUT> transformResult(Single<OUTPUT> result) { return SingleHelper.toFuture(result); } | ||
|
||
Single<OUTPUT> asyncExecute(@NotNull JobData<INPUT> jobData, | ||
@NotNull io.github.zero88.schedulerx.rxjava3.ExecutionContext<OUTPUT> executionContext); | ||
|
||
} |