-
Notifications
You must be signed in to change notification settings - Fork 784
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement letter evaluation change and start/shutdown solution (WIP)
Introduce a dedicated letter evaluation trigger. This trigger should be able to run the evaluation task from the DeadLetteringEventHandlerInvoker. Also, it should be "triggerable" on various scenarios, like manual, fixed delay and on enqueue count. For it to be able to run the evaluation task it'll likely require moving the Executor to the "evaluator" implementation(s) in favor of the DeadLetteringEventHandlerInvoker. With this move, the start/shutdown process of the invoker should change to accommodate correct start/shutdown of the evaluation tasks. #2021
- Loading branch information
Showing
6 changed files
with
520 additions
and
33 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
90 changes: 90 additions & 0 deletions
90
...ing/src/main/java/org/axonframework/messaging/deadletter/AbstractDeadLetterEvaluator.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,90 @@ | ||
/* | ||
* Copyright (c) 2010-2022. Axon Framework | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.axonframework.messaging.deadletter; | ||
|
||
import java.util.concurrent.CompletableFuture; | ||
import java.util.concurrent.Executors; | ||
import java.util.concurrent.ScheduledExecutorService; | ||
import java.util.function.Supplier; | ||
|
||
import static org.axonframework.common.BuilderUtils.assertNonNull; | ||
|
||
/** | ||
* TODO JavaDoc | ||
* @author Steven van Beelen | ||
* @since 4.6.0 | ||
*/ | ||
public abstract class AbstractDeadLetterEvaluator implements DeadLetterEvaluator { | ||
|
||
protected final ScheduledExecutorService executor; | ||
private final boolean customExecutorService; | ||
|
||
protected Supplier<Runnable> taskBuilder; | ||
|
||
/** | ||
* | ||
* @param builder | ||
*/ | ||
public AbstractDeadLetterEvaluator(Builder<?> builder) { | ||
builder.validate(); | ||
this.executor = builder.scheduledExecutorService; | ||
this.customExecutorService = builder.customExecutorService; | ||
} | ||
|
||
@Override | ||
public void start(Supplier<Runnable> evaluationTaskBuilder) { | ||
this.taskBuilder = evaluationTaskBuilder; | ||
} | ||
|
||
@Override | ||
public CompletableFuture<Void> shutdown() { | ||
// If the Executor is customized we can expect the user to shut it down properly. | ||
return customExecutorService | ||
? CompletableFuture.completedFuture(null) | ||
: CompletableFuture.runAsync(executor::shutdown); | ||
} | ||
|
||
/** | ||
* | ||
* @param <B> | ||
*/ | ||
public static class Builder<B extends Builder<?>> { | ||
|
||
private ScheduledExecutorService scheduledExecutorService = Executors.newSingleThreadScheduledExecutor(); | ||
private boolean customExecutorService = false; | ||
|
||
/** | ||
* Sets the {@link ScheduledExecutorService} this {@link DeadLetterEvaluator evaluator} uses to evaluate | ||
* dead-letters. Defaults to a {@link Executors#newSingleThreadScheduledExecutor()}. | ||
* | ||
* @param scheduledExecutorService The scheduled executor used to evaluate dead-letters from a {@link | ||
* DeadLetterQueue}. | ||
* @return The current Builder instance, for fluent interfacing. | ||
*/ | ||
public B scheduledExecutorService(ScheduledExecutorService scheduledExecutorService) { | ||
assertNonNull(scheduledExecutorService, "The ScheduledExecutorService may not be null"); | ||
this.scheduledExecutorService = scheduledExecutorService; | ||
this.customExecutorService = true; | ||
//noinspection unchecked | ||
return (B) this; | ||
} | ||
|
||
public void validate() { | ||
// Method kept for overriding | ||
} | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
messaging/src/main/java/org/axonframework/messaging/deadletter/DeadLetterEvaluator.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,48 @@ | ||
/* | ||
* Copyright (c) 2010-2022. Axon Framework | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.axonframework.messaging.deadletter; | ||
|
||
import java.util.concurrent.CompletableFuture; | ||
import java.util.function.Supplier; | ||
|
||
// TODO: 24-01-22 the only thing making this dead letter specific is the enqueued method...is that enough? | ||
/** | ||
* TODO JavaDoc | ||
* @author Steven van Beelen | ||
* @since 4.6.0 | ||
*/ | ||
public interface DeadLetterEvaluator { | ||
|
||
/** | ||
* TODO: 21-01-22 original intent to construct new tasks, is to potentially allow parallel tasks | ||
* TODO: 24-01-22 replace the Runnable for an interface? | ||
* @param evaluationTaskBuilder | ||
*/ | ||
void start(Supplier<Runnable> evaluationTaskBuilder); | ||
|
||
/** | ||
* | ||
* @return | ||
*/ | ||
CompletableFuture<Void> shutdown(); | ||
|
||
/** | ||
* | ||
* @param letter | ||
*/ | ||
void enqueued(DeadLetterEntry<?> letter); | ||
} |
Oops, something went wrong.