-
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(#103): add SchedulingCompositeMonitor
- Loading branch information
Showing
12 changed files
with
169 additions
and
102 deletions.
There are no files selected for viewing
28 changes: 28 additions & 0 deletions
28
core/src/main/java/io/github/zero88/schedulerx/SchedulingCompositeMonitor.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,28 @@ | ||
package io.github.zero88.schedulerx; | ||
|
||
import io.github.zero88.schedulerx.impl.SchedulingCompositeMonitorImpl; | ||
|
||
/** | ||
* Represents for a delegated monitor that holds multiple scheduling monitors. | ||
* <p/> | ||
* | ||
* @param <OUT> Type of job result data | ||
* @apiNote The holder keeps only one monitor per java class, if try to register many instances of same class, the | ||
* holder will keep the last one | ||
* @since 2.0.0 | ||
*/ | ||
public interface SchedulingCompositeMonitor<OUT> extends SchedulingMonitor<OUT> { | ||
|
||
static <O> SchedulingCompositeMonitor<O> create() { | ||
return new SchedulingCompositeMonitorImpl<>(); | ||
} | ||
|
||
/** | ||
* Register a new scheduling monitor. | ||
* | ||
* @param monitor the scheduling monitor | ||
* @return a reference to this for fluent API | ||
*/ | ||
SchedulingCompositeMonitor<OUT> register(SchedulingMonitor<OUT> monitor); | ||
|
||
} |
59 changes: 59 additions & 0 deletions
59
core/src/main/java/io/github/zero88/schedulerx/impl/SchedulingCompositeMonitorImpl.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,59 @@ | ||
package io.github.zero88.schedulerx.impl; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
import java.util.Objects; | ||
|
||
import org.jetbrains.annotations.NotNull; | ||
|
||
import io.github.zero88.schedulerx.ExecutionResult; | ||
import io.github.zero88.schedulerx.SchedulingCompositeMonitor; | ||
import io.github.zero88.schedulerx.SchedulingMonitor; | ||
import io.vertx.core.impl.logging.Logger; | ||
import io.vertx.core.impl.logging.LoggerFactory; | ||
|
||
public final class SchedulingCompositeMonitorImpl<OUT> extends SchedulingMonitorAbstract<OUT> | ||
implements SchedulingCompositeMonitor<OUT> { | ||
|
||
@SuppressWarnings("rawtypes") | ||
private final Map<Class<? extends SchedulingMonitor>, SchedulingMonitor<OUT>> monitors = new HashMap<>(); | ||
|
||
@Override | ||
protected Logger logger() { | ||
return LoggerFactory.getLogger(SchedulingCompositeMonitor.class); | ||
} | ||
|
||
@Override | ||
public SchedulingCompositeMonitor<OUT> register(SchedulingMonitor<OUT> monitor) { | ||
if (Objects.nonNull(monitor)) { | ||
this.monitors.put(monitor.getClass(), monitor); | ||
} | ||
return this; | ||
} | ||
|
||
@Override | ||
public void onUnableSchedule(@NotNull ExecutionResult<OUT> result) { | ||
monitors.forEach(((aClass, monitor) -> dispatch(aClass, monitor::onUnableSchedule, result))); | ||
} | ||
|
||
@Override | ||
public void onSchedule(@NotNull ExecutionResult<OUT> result) { | ||
monitors.forEach(((aClass, monitor) -> dispatch(aClass, monitor::onSchedule, result))); | ||
} | ||
|
||
@Override | ||
public void onMisfire(@NotNull ExecutionResult<OUT> result) { | ||
monitors.forEach(((aClass, monitor) -> dispatch(aClass, monitor::onMisfire, result))); | ||
} | ||
|
||
@Override | ||
public void onEach(@NotNull ExecutionResult<OUT> result) { | ||
monitors.forEach(((aClass, monitor) -> dispatch(aClass, monitor::onEach, result))); | ||
} | ||
|
||
@Override | ||
public void onCompleted(@NotNull ExecutionResult<OUT> result) { | ||
monitors.forEach(((aClass, monitor) -> dispatch(aClass, monitor::onCompleted, result))); | ||
} | ||
|
||
} |
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.