Skip to content

Commit c5e16a2

Browse files
authored
Refine receive() aop advice and its triggers
* Remove redundant interface for class `CompoundTriggerAdvice` * Fix potential NPE in `DynamicPeriodicTrigger#nextExecution` * use if-else in critical path instead of `requireNonNullElse` Signed-off-by: Jiandong Ma <jiandong.ma.cn@gmail.com>
1 parent ab764a8 commit c5e16a2

File tree

4 files changed

+11
-7
lines changed

4 files changed

+11
-7
lines changed

spring-integration-core/src/main/java/org/springframework/integration/aop/CompoundTriggerAdvice.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,7 @@
3939
* @since 4.3
4040
*
4141
*/
42-
public class CompoundTriggerAdvice
43-
implements MessageSourceMutator, ReceiveMessageAdvice {
42+
public class CompoundTriggerAdvice implements MessageSourceMutator {
4443

4544
private final CompoundTrigger compoundTrigger;
4645

spring-integration-core/src/main/java/org/springframework/integration/aop/SimpleActiveIdleReceiveMessageAdvice.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
import org.springframework.util.Assert;
2626

2727
/**
28-
A simple advice that polls at one rate when messages exist and another when
28+
* A simple advice that polls at one rate when messages exist and another when
2929
* there are no messages.
3030
*
3131
* @author Gary Russell

spring-integration-core/src/main/java/org/springframework/integration/util/CompoundTrigger.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
import org.springframework.util.Assert;
2424

2525
/**
26-
* A {@link Trigger} that delegates the {@link #nextExecutionTime(TriggerContext)}
26+
* A {@link Trigger} that delegates the {@link #nextExecution(TriggerContext)}
2727
* to one of two Triggers. If the {@link #setOverride(Trigger) override} trigger is
2828
* {@code null}, the primary trigger is invoked; otherwise the override trigger is
2929
* invoked.

spring-integration-core/src/main/java/org/springframework/integration/util/DynamicPeriodicTrigger.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
package org.springframework.integration.util;
1818

19+
import java.time.Clock;
1920
import java.time.Duration;
2021
import java.time.Instant;
2122
import java.util.Objects;
@@ -130,14 +131,18 @@ public boolean isFixedRate() {
130131
@Override
131132
public Instant nextExecution(TriggerContext triggerContext) {
132133
Instant lastScheduled = triggerContext.lastScheduledExecution();
134+
Clock clock = triggerContext.getClock();
133135
if (lastScheduled == null) {
134-
return Instant.now().plus(this.initialDuration);
136+
return clock.instant().plus(this.initialDuration);
135137
}
136138
else if (this.fixedRate) {
137139
return lastScheduled.plus(this.duration);
138140
}
139-
return
140-
triggerContext.lastCompletion().plus(this.duration); // NOSONAR never null here
141+
Instant lastCompletion = triggerContext.lastCompletion();
142+
if (lastCompletion == null) {
143+
return clock.instant().plus(this.duration);
144+
}
145+
return lastCompletion.plus(this.duration);
141146
}
142147

143148
@Override

0 commit comments

Comments
 (0)