Skip to content

Commit

Permalink
feat(#48): Add codegen for rx3/mutiny
Browse files Browse the repository at this point in the history
  • Loading branch information
zero88 committed Jul 27, 2023
1 parent f62bd89 commit df43280
Show file tree
Hide file tree
Showing 17 changed files with 249 additions and 110 deletions.
10 changes: 10 additions & 0 deletions buildSrc/src/main/kotlin/Dependencies.kt
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,14 @@ object VertxLibs {

@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 MutinyLibs {
object Version {

const val mutiny = "2.27.0"
}

const val core = "io.smallrye.reactive:smallrye-mutiny-vertx-core:${Version.mutiny}"
}
12 changes: 12 additions & 0 deletions core/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import cloud.playio.gradle.generator.codegen.SourceSetName

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


Expand All @@ -8,11 +11,20 @@ oss {
title.set("Scheduler.x")
}

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

dependencies {
api(VertxLibs.core)
compileOnly(JacksonLibs.annotations)
compileOnly(JacksonLibs.databind)
compileOnly(UtilLibs.jetbrainsAnnotations)
codeGenerator(VertxLibs.rx3)
codeGenerator(MutinyLibs.core)

testImplementation(TestLibs.junit5Params)
testImplementation(JacksonLibs.databind)
Expand Down
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
Expand Up @@ -3,7 +3,9 @@
import org.jetbrains.annotations.NotNull;

/**
* Represents for a 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 @@ -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 @@ -16,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 @@ -28,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();

}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/
@SuppressWarnings("unchecked")
public abstract class AbstractTaskExecutorBuilder<T extends Trigger, E extends TriggerTaskExecutor<T>,
B extends AbstractTaskExecutorBuilder<T, E, B>>
B extends TriggerTaskExecutorBuilder<T, E, B>>
implements TriggerTaskExecutorBuilder<T, E, B> {

private Vertx vertx;
Expand All @@ -27,44 +27,48 @@ public abstract class AbstractTaskExecutorBuilder<T extends Trigger, E extends T
private Task task;
private T trigger;

public @NotNull B setVertx(@NotNull Vertx vertx) {
this.vertx = Objects.requireNonNull(vertx, "Vertx instance is required");
return (B) this;
@Override
public @NotNull Vertx vertx() {
return Objects.requireNonNull(vertx, "Vertx instance is required");
}

public @NotNull B setMonitor(@NotNull TaskExecutorMonitor monitor) {
this.monitor = Objects.requireNonNull(monitor, "TaskExecutorMonitor is required");
return (B) this;
@Override
public @NotNull TaskExecutorMonitor monitor() {
return Objects.requireNonNull(monitor, "TaskExecutorMonitor is required");
}

public @NotNull B setJobData(@NotNull JobData jobData) {
this.jobData = Objects.requireNonNull(jobData, "JobData is required");
@Override
public @NotNull T trigger() { return Objects.requireNonNull(trigger, "Trigger is required"); }

@Override
public @NotNull Task task() { return Objects.requireNonNull(task, "Task is required"); }

@Override
public @NotNull JobData jobData() { return Objects.requireNonNull(jobData, "JobData is required"); }

public @NotNull B setVertx(@NotNull Vertx vertx) {
this.vertx = vertx;
return (B) this;
}

public @NotNull B setTask(@NotNull Task task) {
this.task = Objects.requireNonNull(task, "Task is required");
this.task = task;
return (B) this;
}

public @NotNull B setTrigger(@NotNull T trigger) {
this.trigger = Objects.requireNonNull(trigger, "Trigger is required");
this.trigger = trigger;
return (B) this;
}

@Override
public @NotNull Vertx vertx() { return vertx; }

@Override
public @NotNull TaskExecutorMonitor monitor() { return monitor; }

@Override
public @NotNull T trigger() { return trigger; }

@Override
public @NotNull Task task() { return task; }
public @NotNull B setMonitor(@NotNull TaskExecutorMonitor monitor) {
this.monitor = monitor;
return (B) this;
}

@Override
public @NotNull JobData jobData() { return jobData; }
public @NotNull B setJobData(@NotNull JobData jobData) {
this.jobData = jobData;
return (B) this;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,8 @@
* The scheduler.x core API
*/

@ModuleGen(name = "io-zero88-schedulerx", groupPackage = "io.github.zero88.schedulerx")
package io.github.zero88.schedulerx;

import io.vertx.codegen.annotations.ModuleGen;

Original file line number Diff line number Diff line change
@@ -1,15 +1,24 @@
package io.github.zero88.schedulerx.trigger;

import org.jetbrains.annotations.NotNull;

import io.github.zero88.schedulerx.TriggerTaskExecutor;
import io.vertx.codegen.annotations.GenIgnore;
import io.vertx.codegen.annotations.VertxGen;

/**
* Represents for the task executor has an execution loop based on the timer of cron expressions.
*
* @see CronTrigger
* @since 2.0.0
*/
@VertxGen
public interface CronTriggerExecutor extends TriggerTaskExecutor<CronTrigger> {

static CronTriggerExecutorBuilder builder() { return new CronTriggerExecutorBuilder(); }
static CronTriggerExecutorBuilder builder() { return new CronTriggerExecutorImpl.CronTriggerExecutorBuilderImpl(); }

@Override
@GenIgnore(GenIgnore.PERMITTED_TYPE)
@NotNull CronTrigger trigger();

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

import org.jetbrains.annotations.NotNull;

import io.github.zero88.schedulerx.impl.AbstractTaskExecutorBuilder;
import io.github.zero88.schedulerx.JobData;
import io.github.zero88.schedulerx.Task;
import io.github.zero88.schedulerx.TaskExecutorMonitor;
import io.github.zero88.schedulerx.TriggerTaskExecutorBuilder;
import io.vertx.codegen.annotations.Fluent;
import io.vertx.codegen.annotations.GenIgnore;
import io.vertx.codegen.annotations.VertxGen;
import io.vertx.core.Vertx;

/**
* Represents a builder that constructs {@link CronTriggerExecutor}
*
* @since 2.0.0
*/
public final class CronTriggerExecutorBuilder
extends AbstractTaskExecutorBuilder<CronTrigger, CronTriggerExecutor, CronTriggerExecutorBuilder> {
@VertxGen
public interface CronTriggerExecutorBuilder
extends TriggerTaskExecutorBuilder<CronTrigger, CronTriggerExecutor, CronTriggerExecutorBuilder> {

public @NotNull CronTriggerExecutor build() {
return new CronTriggerExecutorImpl(vertx(), monitor(), jobData(), task(), trigger());
}
@GenIgnore(GenIgnore.PERMITTED_TYPE)
@NotNull CronTrigger trigger();

@Fluent
@NotNull CronTriggerExecutorBuilder setVertx(@NotNull Vertx vertx);

@Fluent
@GenIgnore(GenIgnore.PERMITTED_TYPE)
@NotNull CronTriggerExecutorBuilder setTask(@NotNull Task task);

@Fluent
@GenIgnore(GenIgnore.PERMITTED_TYPE)
@NotNull CronTriggerExecutorBuilder setTrigger(@NotNull CronTrigger trigger);

@Fluent
@GenIgnore(GenIgnore.PERMITTED_TYPE)
@NotNull CronTriggerExecutorBuilder setJobData(@NotNull JobData jobData);

@Fluent
@GenIgnore(GenIgnore.PERMITTED_TYPE)
@NotNull CronTriggerExecutorBuilder setMonitor(@NotNull TaskExecutorMonitor monitor);

@NotNull CronTriggerExecutor build();

}
Loading

0 comments on commit df43280

Please sign in to comment.