-
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): First step for TriggerEvaluator
- Loading branch information
Showing
9 changed files
with
162 additions
and
73 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
32 changes: 32 additions & 0 deletions
32
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,32 @@ | ||
package io.github.zero88.schedulerx.impl; | ||
|
||
import io.github.zero88.schedulerx.trigger.TriggerEvaluator; | ||
import io.vertx.core.Future; | ||
|
||
public abstract class AbstractTriggerEvaluator implements TriggerEvaluator { | ||
|
||
public static TriggerEvaluator empty() { | ||
return new AbstractTriggerEvaluator() { | ||
@Override | ||
protected Future<TriggerTransitionContext> internalCheck(TriggerTransitionContext context) { | ||
return Future.succeededFuture(context); | ||
} | ||
}; | ||
} | ||
|
||
private TriggerEvaluator next; | ||
|
||
@Override | ||
public Future<TriggerTransitionContext> check(TriggerTransitionContext context) { | ||
return internalCheck(context).flatMap(ctx -> next == null ? Future.succeededFuture(ctx) : next.check(ctx)); | ||
} | ||
|
||
@Override | ||
public TriggerEvaluator andThen(TriggerEvaluator other) { | ||
this.next = other; | ||
return this; | ||
} | ||
|
||
protected abstract Future<TriggerTransitionContext> internalCheck(TriggerTransitionContext context); | ||
|
||
} |
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
29 changes: 29 additions & 0 deletions
29
core/src/main/java/io/github/zero88/schedulerx/trigger/EventTriggerEvaluator.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,29 @@ | ||
package io.github.zero88.schedulerx.trigger; | ||
|
||
import io.github.zero88.schedulerx.impl.AbstractTriggerEvaluator; | ||
import io.github.zero88.schedulerx.impl.TriggerContextFactory; | ||
import io.github.zero88.schedulerx.impl.TriggerTransitionContext; | ||
import io.github.zero88.schedulerx.trigger.TriggerCondition.ReasonCode; | ||
import io.vertx.core.Future; | ||
|
||
final class EventTriggerEvaluator<T> extends AbstractTriggerEvaluator { | ||
|
||
private final EventTrigger<T> trigger; | ||
|
||
EventTriggerEvaluator(EventTrigger<T> trigger) { this.trigger = trigger; } | ||
|
||
@Override | ||
@SuppressWarnings("unchecked") | ||
protected Future<TriggerTransitionContext> internalCheck(TriggerTransitionContext ctx) { | ||
try { | ||
if (ctx.condition().status() == TriggerCondition.TriggerStatus.READY && | ||
!trigger.getPredicate().test((T) ctx.info())) { | ||
return Future.succeededFuture(TriggerContextFactory.skip(ctx, ReasonCode.CONDITION_IS_NOT_MATCHED)); | ||
} | ||
} catch (Exception ex) { | ||
return Future.succeededFuture(EventSchedulerImpl.handleException(ctx, ex)); | ||
} | ||
return Future.succeededFuture(ctx); | ||
} | ||
|
||
} |
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.