Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/remove lombok #50

Merged
merged 5 commits into from
Jul 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -96,12 +96,12 @@ public interface TaskExecutorLogMonitor extends TaskExecutorMonitor {
TaskExecutorMonitor LOG_MONITOR = new TaskExecutorLogMonitor() {};

@Override
default void onUnableSchedule(@NonNull TaskResult result) {
default void onUnableSchedule(@NotNull TaskResult result) {
LOGGER.error("Unable schedule task at [{}] due to error", result.unscheduledAt(), result.error());
}

@Override
default void onSchedule(@NonNull TaskResult result) {
default void onSchedule(@NotNull TaskResult result) {
if (result.isReschedule()) {
LOGGER.debug("TaskExecutor is rescheduled at [{}] round [{}]", result.rescheduledAt(), result.round());
} else {
Expand All @@ -110,18 +110,18 @@ public interface TaskExecutorLogMonitor extends TaskExecutorMonitor {
}

@Override
default void onMisfire(@NonNull TaskResult result) {
default void onMisfire(@NotNull TaskResult result) {
LOGGER.debug("Misfire tick [{}] at [{}]", result.tick(), result.triggeredAt());
}

@Override
default void onEach(@NonNull TaskResult result) {
default void onEach(@NotNull TaskResult result) {
LOGGER.debug("Finish round [{}] - Is Error [{}] | Executed at [{}] - Finished at [{}]", result.round(),
result.isError(), result.executedAt(), result.finishedAt());
}

@Override
default void onCompleted(@NonNull TaskResult result) {
default void onCompleted(@NotNull TaskResult result) {
LOGGER.debug("Completed task in round [{}] at [{}]", result.round(), result.completedAt());
}

Expand All @@ -146,7 +146,7 @@ public class HttpClientTask implements Task {
}

@Override
public void execute(@NonNull JobData jobData, @NonNull TaskExecutionContext executionContext) {
public void execute(@NotNull JobData jobData, @NotNull TaskExecutionContext executionContext) {
final Vertx vertx = executionContext.vertx();
JsonObject url = (JsonObject) jobData.get();
vertx.createHttpClient().request(HttpMethod.GET, url.getString("host"), url.getString("path"), ar1 -> {
Expand Down
10 changes: 10 additions & 0 deletions buildSrc/src/main/kotlin/Dependencies.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,16 @@ object PlayioPlugin {
const val codegen = "cloud.playio.gradle.codegen"
}

object UtilLibs {

object Version {

const val jetbrainsAnnotations = "20.1.0"
}

const val jetbrainsAnnotations = "org.jetbrains:annotations:${Version.jetbrainsAnnotations}"
}

object JacksonLibs {

object Version {
Expand Down
35 changes: 14 additions & 21 deletions core/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -7,35 +7,28 @@ oss {
baseName.set("schedulerx")
title.set("Scheduler.x")
}

val lombok = "org.projectlombok:lombok:1.18.16"
val vertxVersion = "4.0.0"
val junit5Version = "4.0.0"
val junit5Api = "org.junit.jupiter:junit-jupiter-api:${junit5Version}"
val junit5Engine = "org.junit.jupiter:junit-jupiter-engine:${junit5Version}"
val vertxCore = "io.vertx:vertx-core:${vertxVersion}"
val vertx5Junit = "io.vertx:vertx-junit5:${vertxVersion}"
val jackson = "com.fasterxml.jackson.core:jackson-databind:2.12.0"

dependencies {
api("io.vertx:vertx-core:${vertxVersion}")
api(vertxCore)
api("org.slf4j:slf4j-api:1.7.30")
compileOnly(jackson)
compileOnly(lombok)
annotationProcessor(lombok)
compileOnly(JacksonLibs.databind)
compileOnly(UtilLibs.jetbrainsAnnotations)
annotationProcessor(UtilLibs.jetbrainsAnnotations)

testImplementation(junit5Api)
testImplementation(junit5Engine)
testImplementation(vertx5Junit)
testImplementation(vertx5Junit)
testImplementation(jackson)
testCompileOnly(lombok)
testAnnotationProcessor(lombok)
testImplementation(TestLibs.junit5Params)
testImplementation(JacksonLibs.databind)
testImplementation("ch.qos.logback:logback-classic:1.2.3")
testCompileOnly(UtilLibs.jetbrainsAnnotations)
testAnnotationProcessor(UtilLibs.jetbrainsAnnotations)

testFixturesApi("ch.qos.logback:logback-classic:1.2.3")
testFixturesApi(junit5Api)
testFixturesApi(junit5Engine)
testFixturesApi(TestLibs.junit5Api)
testFixturesApi(TestLibs.junit5Engine)
testFixturesApi(TestLibs.junit5Vintage)
testFixturesApi(vertx5Junit)
testFixturesCompileOnly(lombok)
testFixturesAnnotationProcessor(lombok)
testFixturesCompileOnly(UtilLibs.jetbrainsAnnotations)
testFixturesAnnotationProcessor(UtilLibs.jetbrainsAnnotations)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package io.github.zero88.schedulerx;

import io.github.zero88.schedulerx.impl.CronTaskExecutorBuilder;
import io.github.zero88.schedulerx.trigger.CronTrigger;

public interface CronTaskExecutor extends TriggerTaskExecutor<CronTrigger> {

static CronTaskExecutorBuilder builder() { return new CronTaskExecutorBuilder(); }

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package io.github.zero88.schedulerx;

import io.github.zero88.schedulerx.impl.IntervalTaskExecutorBuilder;
import io.github.zero88.schedulerx.trigger.IntervalTrigger;

public interface IntervalTaskExecutor extends TriggerTaskExecutor<IntervalTrigger> {

static IntervalTaskExecutorBuilder builder() { return new IntervalTaskExecutorBuilder(); }

}
6 changes: 3 additions & 3 deletions core/src/main/java/io/github/zero88/schedulerx/Task.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package io.github.zero88.schedulerx;

import io.github.zero88.schedulerx.trigger.Trigger;
import org.jetbrains.annotations.NotNull;

import lombok.NonNull;
import io.github.zero88.schedulerx.trigger.Trigger;

/**
* Represents for Task to run on each trigger time
Expand Down Expand Up @@ -31,6 +31,6 @@ default boolean isAsync() {
* @param executionContext task execution context
* @see TaskExecutionContext
*/
void execute(@NonNull JobData jobData, @NonNull TaskExecutionContext executionContext);
void execute(@NotNull JobData jobData, @NotNull TaskExecutionContext executionContext);

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

import java.time.Instant;

import io.vertx.core.Promise;
import io.vertx.core.Vertx;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import lombok.NonNull;
import io.vertx.core.Vertx;

/**
* Represents for a context per each execution round
Expand All @@ -14,24 +14,12 @@
*/
public interface TaskExecutionContext {

/**
* Setup task execution context
*
* @param promise promise
* @param executedAt execution at time
* @return a reference to this for fluent API
* @apiNote It will be invoked by system. In any attempts invoking, {@link IllegalStateException} will be
* thrown
* @see Promise
*/
@NonNull TaskExecutionContext setup(@NonNull Promise<Object> promise, @NonNull Instant executedAt);

/**
* Current vertx
*
* @return vertx
*/
@NonNull Vertx vertx();
@NotNull Vertx vertx();

/**
* Current execution round
Expand All @@ -45,14 +33,14 @@ public interface TaskExecutionContext {
*
* @return triggeredAt
*/
@NonNull Instant triggeredAt();
@NotNull Instant triggeredAt();

/**
* Executed at time
*
* @return executedAt
*/
@NonNull Instant executedAt();
@NotNull Instant executedAt();

/**
* Check whether force stop execution or not
Expand All @@ -72,14 +60,14 @@ public interface TaskExecutionContext {
* @param data object data
* @apiNote if task is {@code async} then it should be invoked in handling async result stage
*/
void complete(Object data);
void complete(@Nullable Object data);

/**
* Failed execution with error per each round
*
* @param throwable execution error
* @apiNote if task is {@code async} then it should be invoked in handling async result stage
*/
void fail(Throwable throwable);
void fail(@Nullable Throwable throwable);

}
25 changes: 15 additions & 10 deletions core/src/main/java/io/github/zero88/schedulerx/TaskExecutor.java
Original file line number Diff line number Diff line change
@@ -1,39 +1,44 @@
package io.github.zero88.schedulerx;

import org.jetbrains.annotations.NotNull;

import io.vertx.core.Vertx;
import io.vertx.core.WorkerExecutor;

import lombok.NonNull;

/**
* Represents for an executor run {@code task} in conditional loop
*
* @param <C> Type of TaskExecutionContext
* @see TriggerTaskExecutor
* @since 1.0.0
*/
public interface TaskExecutor<C extends TaskExecutionContext> {
public interface TaskExecutor {

/**
* Vertx
*
* @return vertx
*/
@NonNull Vertx vertx();
@NotNull Vertx vertx();

/**
* Task executor state
*
* @return task executor state
*/
@NonNull TaskExecutorState state();
@NotNull TaskExecutorState state();

/**
* Defines a task executor monitor
*
* @return task executor monitor
* @see TaskExecutorMonitor
*/
@NotNull TaskExecutorMonitor monitor();

/**
* Start and run in {@code Vertx worker thread pool}
*/
default void start() {
start(null);
}
default void start() { start(null); }

/**
* Start and run in a dedicated thread pool that is provided by a customized worker executor
Expand All @@ -48,7 +53,7 @@ default void start() {
*
* @param executionContext execution context
*/
void executeTask(@NonNull C executionContext);
void executeTask(@NotNull TaskExecutionContext executionContext);

/**
* Cancel executor
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
package io.github.zero88.schedulerx;

import org.jetbrains.annotations.NotNull;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import lombok.NonNull;

/**
* Represents for log monitor
*
Expand All @@ -16,12 +15,12 @@ public interface TaskExecutorLogMonitor extends TaskExecutorMonitor {
TaskExecutorMonitor LOG_MONITOR = new TaskExecutorLogMonitor() {};

@Override
default void onUnableSchedule(@NonNull TaskResult result) {
default void onUnableSchedule(@NotNull TaskResult result) {
LOGGER.error("Unable schedule task at [{}] due to error", result.unscheduledAt(), result.error());
}

@Override
default void onSchedule(@NonNull TaskResult result) {
default void onSchedule(@NotNull TaskResult result) {
if (result.isReschedule()) {
LOGGER.debug("TaskExecutor is rescheduled at [{}] round [{}]", result.rescheduledAt(), result.round());
} else {
Expand All @@ -30,18 +29,18 @@ default void onSchedule(@NonNull TaskResult result) {
}

@Override
default void onMisfire(@NonNull TaskResult result) {
default void onMisfire(@NotNull TaskResult result) {
LOGGER.debug("Misfire tick [{}] at [{}]", result.tick(), result.triggeredAt());
}

@Override
default void onEach(@NonNull TaskResult result) {
default void onEach(@NotNull TaskResult result) {
LOGGER.debug("Finish round [{}] - Is Error [{}] | Executed at [{}] - Finished at [{}]", result.round(),
result.isError(), result.executedAt(), result.finishedAt());
}

@Override
default void onCompleted(@NonNull TaskResult result) {
default void onCompleted(@NotNull TaskResult result) {
LOGGER.debug("Completed task in round [{}] at [{}]", result.round(), result.completedAt());
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package io.github.zero88.schedulerx;

import lombok.NonNull;
import org.jetbrains.annotations.NotNull;

/**
* Represents for monitor that watches lifecycle event in executor
Expand All @@ -16,34 +16,34 @@ public interface TaskExecutorMonitor {
* @param result task result
* @see TaskResult
*/
void onUnableSchedule(@NonNull TaskResult result);
void onUnableSchedule(@NotNull TaskResult result);

/**
* Invoke after executor is scheduled or rescheduled
*
* @param result task result
*/
void onSchedule(@NonNull TaskResult result);
void onSchedule(@NotNull TaskResult result);

/**
* Invoke when misfire the execution, one reason is due to task is still running when trigger a new round execution
*
* @param result task result
*/
void onMisfire(@NonNull TaskResult result);
void onMisfire(@NotNull TaskResult result);

/**
* Invoke after each round is finished regardless a round execution is success or fail
*
* @param result task result
*/
void onEach(@NonNull TaskResult result);
void onEach(@NotNull TaskResult result);

/**
* Invoke after executor is completed
*
* @param result task result
*/
void onCompleted(@NonNull TaskResult result);
void onCompleted(@NotNull TaskResult result);

}
Loading