-
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.
Merge pull request #95 from zero88/feature/trigger-evaluation
Feature/trigger evaluation
- Loading branch information
Showing
30 changed files
with
589 additions
and
310 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,7 +12,6 @@ | |
* @param <T> Type of data | ||
* @since 1.0.0 | ||
*/ | ||
@FunctionalInterface | ||
public interface JobData<T> { | ||
|
||
/** | ||
|
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 |
---|---|---|
|
@@ -10,6 +10,7 @@ | |
* @since 1.0.0 | ||
*/ | ||
@Internal | ||
@FunctionalInterface | ||
public interface JobExecutor<OUT> { | ||
|
||
/** | ||
|
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
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
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
198 changes: 111 additions & 87 deletions
198
core/src/main/java/io/github/zero88/schedulerx/impl/AbstractScheduler.java
Large diffs are not rendered by default.
Oops, something went wrong.
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
70 changes: 70 additions & 0 deletions
70
core/src/main/java/io/github/zero88/schedulerx/impl/DefaultTriggerEvaluator.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,70 @@ | ||
package io.github.zero88.schedulerx.impl; | ||
|
||
import java.util.Optional; | ||
|
||
import org.jetbrains.annotations.ApiStatus.Internal; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
import io.github.zero88.schedulerx.trigger.AfterTriggerEvaluator; | ||
import io.github.zero88.schedulerx.trigger.BeforeTriggerEvaluator; | ||
import io.github.zero88.schedulerx.trigger.Trigger; | ||
import io.github.zero88.schedulerx.trigger.TriggerContext; | ||
import io.github.zero88.schedulerx.trigger.TriggerEvaluator; | ||
import io.vertx.core.Future; | ||
|
||
@Internal | ||
public class DefaultTriggerEvaluator implements TriggerEvaluator { | ||
|
||
private BeforeTriggerEvaluator before = (trigger, ctx, externalId) -> Future.succeededFuture(ctx); | ||
private AfterTriggerEvaluator after = (trigger, ctx, externalId, round) -> Future.succeededFuture(ctx); | ||
private TriggerEvaluator next; | ||
|
||
public DefaultTriggerEvaluator() { } | ||
|
||
DefaultTriggerEvaluator(BeforeTriggerEvaluator beforeEvaluator, AfterTriggerEvaluator afterEvaluator) { | ||
before = Optional.ofNullable(beforeEvaluator).orElse(before); | ||
after = Optional.ofNullable(afterEvaluator).orElse(after); | ||
} | ||
|
||
public static TriggerEvaluator init(BeforeTriggerEvaluator beforeEvaluator, AfterTriggerEvaluator afterEvaluator) { | ||
return new DefaultTriggerEvaluator(beforeEvaluator, afterEvaluator); | ||
} | ||
|
||
@Override | ||
public final @NotNull Future<TriggerContext> beforeTrigger(@NotNull Trigger trigger, | ||
@NotNull TriggerContext triggerContext, | ||
@Nullable Object externalId) { | ||
return this.internalBeforeTrigger(trigger, triggerContext, externalId) | ||
.flatMap(c -> next == null ? Future.succeededFuture(c) : next.beforeTrigger(trigger, c, externalId)); | ||
} | ||
|
||
@Override | ||
public final @NotNull Future<TriggerContext> afterTrigger(@NotNull Trigger trigger, | ||
@NotNull TriggerContext triggerContext, | ||
@Nullable Object externalId, long round) { | ||
// @formatter:off | ||
return this.internalAfterTrigger(trigger, triggerContext, externalId, round ) | ||
.flatMap(c -> next == null ? Future.succeededFuture(c) : next.afterTrigger(trigger, c, externalId, round)); | ||
// @formatter:on | ||
} | ||
|
||
@Override | ||
public final @NotNull TriggerEvaluator andThen(@Nullable TriggerEvaluator another) { | ||
this.next = another; | ||
return this; | ||
} | ||
|
||
protected Future<TriggerContext> internalBeforeTrigger(@NotNull Trigger trigger, | ||
@NotNull TriggerContext triggerContext, | ||
@Nullable Object externalId) { | ||
return before.beforeTrigger(trigger, triggerContext, externalId); | ||
} | ||
|
||
protected Future<TriggerContext> internalAfterTrigger(@NotNull Trigger trigger, | ||
@NotNull TriggerContext triggerContext, | ||
@Nullable Object externalId, long round) { | ||
return after.afterTrigger(trigger, triggerContext, externalId, round); | ||
} | ||
|
||
} |
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
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
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
Oops, something went wrong.