-
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(#93): TriggerEvaluator#beforeRun
- Loading branch information
Showing
10 changed files
with
231 additions
and
85 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
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
45 changes: 45 additions & 0 deletions
45
core/src/main/java/io/github/zero88/schedulerx/impl/AbstractTriggerEvaluator.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,45 @@ | ||
package io.github.zero88.schedulerx.impl; | ||
|
||
import org.jetbrains.annotations.ApiStatus.Internal; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
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 abstract class AbstractTriggerEvaluator implements TriggerEvaluator { | ||
|
||
static TriggerEvaluator noop() { | ||
return new AbstractTriggerEvaluator() { | ||
@Override | ||
protected Future<TriggerContext> internalCheck(@NotNull Trigger trigger, | ||
@NotNull TriggerContext triggerContext, | ||
@Nullable Object externalId) { | ||
return Future.succeededFuture(triggerContext); | ||
} | ||
}; | ||
} | ||
|
||
private TriggerEvaluator next; | ||
|
||
@Override | ||
public @NotNull Future<TriggerContext> beforeRun(@NotNull Trigger trigger, @NotNull TriggerContext triggerContext, | ||
@Nullable Object externalId) { | ||
return this.internalCheck(trigger, triggerContext, externalId) | ||
.flatMap(ctx -> next == null ? Future.succeededFuture(ctx) : next.beforeRun(trigger, ctx, externalId)); | ||
} | ||
|
||
@Override | ||
public @NotNull TriggerEvaluator andThen(@Nullable TriggerEvaluator another) { | ||
this.next = another; | ||
return this; | ||
} | ||
|
||
protected abstract Future<TriggerContext> internalCheck(@NotNull Trigger trigger, | ||
@NotNull TriggerContext triggerContext, | ||
@Nullable Object externalId); | ||
|
||
} |
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.