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/upgrade vertx #51

Merged
merged 5 commits into from
Jul 27, 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
33 changes: 20 additions & 13 deletions buildSrc/src/main/kotlin/Dependencies.kt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
private fun Map<Int, List<Int>>.ver(minor: Int, patch: Int):String = "${minor}.${this[minor]?.get(patch)}"
private fun Map<Int, List<Int>>.ver(minor: Int, patch: Int): String = "${minor}.${this[minor]?.get(patch)}"

object PlayioPlugin {

Expand All @@ -25,6 +25,16 @@ object UtilLibs {
const val jetbrainsAnnotations = "org.jetbrains:annotations:${Version.jetbrainsAnnotations}"
}

object LogLibs {

object Version {

const val logback = "1.4.8"
}

const val logback = "ch.qos.logback:logback-classic:${Version.logback}"
}

object JacksonLibs {

object Version {
Expand All @@ -34,7 +44,6 @@ object JacksonLibs {

const val annotations = "com.fasterxml.jackson.core:jackson-annotations:${Version.jackson}"
const val databind = "com.fasterxml.jackson.core:jackson-databind:${Version.jackson}"
const val datetime = "com.fasterxml.jackson.datatype:jackson-datatype-jsr310:${Version.jackson}"
}

object TestLibs {
Expand All @@ -55,22 +64,20 @@ object VertxLibs {

object Version {

private val pool = mapOf(2 to (0..7).toList(), 3 to (0..6).toList(), 4 to (0..0).toList())
@JvmField val vertxCore = "4.${pool.ver(3, 5)}"
@JvmField val vertxSQL = "4.${pool.ver(3, 5)}"
const val vertxJunit = "4.2.5"
private val pool = mapOf(2 to (0..7).toList(), 3 to (0..6).toList(), 4 to (0..4).toList())
@JvmField val defaultVersion = "4.${pool.ver(4, 4)}"
}

@JvmField val core = "io.vertx:vertx-core:${Version.vertxCore}"
@JvmField val junit5 = "io.vertx:vertx-junit5:${Version.vertxJunit}"
@JvmField val core = "io.vertx:vertx-core:${Version.defaultVersion}"
@JvmField val junit5 = "io.vertx:vertx-junit5:${Version.defaultVersion}"
@JvmField val rx3 = "io.vertx:vertx-rx-java3:${Version.defaultVersion}"
}

object ValidationLibs {
object MutinyLibs {
object Version {
const val api = "3.0.2"
const val hibernate = "8.0.0.Final"

const val mutiny = "2.27.0"
}

const val api = "jakarta.validation:jakarta.validation-api:${Version.api}"
const val hibernate = "org.hibernate.validator:hibernate-validator:${Version.hibernate}"
const val core = "io.smallrye.reactive:smallrye-mutiny-vertx-core:${Version.mutiny}"
}
27 changes: 16 additions & 11 deletions core/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,34 +1,39 @@
import cloud.playio.gradle.generator.codegen.SourceSetName

plugins {
`java-test-fixtures`
id(PlayioPlugin.codegen)
}


oss {
baseName.set("schedulerx")
title.set("Scheduler.x")
}
val vertxVersion = "4.0.0"
val vertxCore = "io.vertx:vertx-core:${vertxVersion}"
val vertx5Junit = "io.vertx:vertx-junit5:${vertxVersion}"

codegen {
vertx {
version.set(VertxLibs.Version.defaultVersion)
sources.addAll(arrayOf(SourceSetName.MAIN))
}
}

dependencies {
api(vertxCore)
api("org.slf4j:slf4j-api:1.7.30")
api(VertxLibs.core)
compileOnly(JacksonLibs.annotations)
compileOnly(JacksonLibs.databind)
compileOnly(UtilLibs.jetbrainsAnnotations)
annotationProcessor(UtilLibs.jetbrainsAnnotations)
codeGenerator(VertxLibs.rx3)
codeGenerator(MutinyLibs.core)

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

testFixturesApi(TestLibs.junit5Api)
testFixturesApi(TestLibs.junit5Engine)
testFixturesApi(TestLibs.junit5Vintage)
testFixturesApi(vertx5Junit)
testFixturesApi(VertxLibs.junit5)
testFixturesCompileOnly(UtilLibs.jetbrainsAnnotations)
testFixturesAnnotationProcessor(UtilLibs.jetbrainsAnnotations)
}

This file was deleted.

This file was deleted.

24 changes: 6 additions & 18 deletions core/src/main/java/io/github/zero88/schedulerx/TaskExecutor.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,39 +2,26 @@

import org.jetbrains.annotations.NotNull;

import io.vertx.core.Vertx;
import io.vertx.codegen.annotations.GenIgnore;
import io.vertx.codegen.annotations.VertxGen;
import io.vertx.core.WorkerExecutor;

/**
* Represents for an executor run {@code task} in conditional loop
*
* @see TriggerTaskExecutor
* @since 1.0.0
*/
public interface TaskExecutor {

/**
* Vertx
*
* @return vertx
*/
@NotNull Vertx vertx();
@VertxGen(concrete = false)
public interface TaskExecutor extends TaskExecutorProperties {

/**
* Task executor state
*
* @return task executor state
*/
@GenIgnore(GenIgnore.PERMITTED_TYPE)
@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}
*/
Expand All @@ -53,6 +40,7 @@ public interface TaskExecutor {
*
* @param executionContext execution context
*/
@GenIgnore(GenIgnore.PERMITTED_TYPE)
void executeTask(@NotNull TaskExecutionContext executionContext);

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

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

import io.vertx.core.impl.logging.Logger;
import io.vertx.core.impl.logging.LoggerFactory;

/**
* Represents for log monitor
* Represents for a log monitor that observes and do log on each lifecycle event of the task executor.
*
* @since 1.0.0
*/
public interface TaskExecutorLogMonitor extends TaskExecutorMonitor {

Logger LOGGER = LoggerFactory.getLogger(TaskExecutorLogMonitor.class);
TaskExecutorMonitor LOG_MONITOR = new TaskExecutorLogMonitor() {};
TaskExecutorLogMonitor LOG_MONITOR = new TaskExecutorLogMonitor() { };

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

@Override
default void onSchedule(@NotNull TaskResult result) {
if (result.isReschedule()) {
LOGGER.debug("TaskExecutor is rescheduled at [{}] round [{}]", result.rescheduledAt(), result.round());
LOGGER.debug(
"TaskExecutor is rescheduled at [" + result.rescheduledAt() + "] round [" + result.round() + "]");
} else {
LOGGER.debug("TaskExecutor is available at [{}]", result.availableAt());
LOGGER.debug("TaskExecutor is available at [" + result.availableAt() + "]");
}
}

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

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

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

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
import org.jetbrains.annotations.NotNull;

/**
* Represents for monitor that watches lifecycle event in executor
* Represents for a monitor that watches lifecycle event in executor.
* <p/>
* It can be used to persist or distribute the task result per each round.
*
* @see TaskResult
* @since 1.0.0
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package io.github.zero88.schedulerx;

import org.jetbrains.annotations.ApiStatus.Internal;
import org.jetbrains.annotations.NotNull;

import io.vertx.codegen.annotations.GenIgnore;
import io.vertx.codegen.annotations.VertxGen;
import io.vertx.core.Vertx;

/**
* Shared immutable fields between TaskExecutor and its builder
*
* @since 2.0.0
*/
@Internal
@VertxGen(concrete = false)
public interface TaskExecutorProperties {

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

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

/**
* Task to execute per round
*
* @return task
* @see Task
*/
@GenIgnore(GenIgnore.PERMITTED_TYPE)
@NotNull Task task();

/**
* Defines job data as input task data
*
* @return job data
* @see JobData
*/
@GenIgnore(GenIgnore.PERMITTED_TYPE)
@NotNull JobData jobData();

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@

import org.jetbrains.annotations.Nullable;

import io.github.zero88.schedulerx.impl.TaskResultBuilder;

/**
* Represents for task result will be pass on each event of {@link TaskExecutorMonitor}
*
Expand All @@ -15,8 +13,6 @@
*/
public interface TaskResult {

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

/**
* Only {@code not null} in {@link TaskExecutorMonitor#onUnableSchedule(TaskResult)}
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
*
* @param <T> Type of Trigger
* @see Trigger
* @see TaskExecutor
* @since 1.0.0
*/
public interface TriggerTaskExecutor<T extends Trigger> extends TaskExecutor {
Expand All @@ -20,20 +21,4 @@ public interface TriggerTaskExecutor<T extends Trigger> extends TaskExecutor {
*/
@NotNull T trigger();

/**
* Task to execute per round
*
* @return task
* @see Task
*/
@NotNull Task task();

/**
* Defines job data as input task data
*
* @return job data
* @see JobData
*/
@NotNull JobData jobData();

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import io.vertx.core.Vertx;

/**
* Represents for the high level of a builder that construct {@code TriggerTaskExecutor}
*
* @param <TRIGGER> Type of Trigger
* @param <EXECUTOR> Type of Trigger Task Executor
* @param <SELF> Type of Executor Builder
Expand All @@ -14,7 +16,10 @@
* @since 2.0.0
*/
public interface TriggerTaskExecutorBuilder<TRIGGER extends Trigger, EXECUTOR extends TriggerTaskExecutor<TRIGGER>,
SELF extends TriggerTaskExecutorBuilder<TRIGGER, EXECUTOR, SELF>> {
SELF extends TriggerTaskExecutorBuilder<TRIGGER, EXECUTOR, SELF>>
extends TaskExecutorProperties {

@NotNull TRIGGER trigger();

@NotNull SELF setVertx(@NotNull Vertx vertx);

Expand All @@ -26,16 +31,6 @@ public interface TriggerTaskExecutorBuilder<TRIGGER extends Trigger, EXECUTOR ex

@NotNull SELF setMonitor(@NotNull TaskExecutorMonitor monitor);

@NotNull Vertx vertx();

@NotNull Task task();

@NotNull TRIGGER trigger();

@NotNull JobData jobData();

@NotNull TaskExecutorMonitor monitor();

@NotNull EXECUTOR build();

}
Loading