-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* GH-8625: Add Duration support for `<poller>` Fixes #8625 The duration can be represented in a ISO 8601 format, e.g. `PT10S`, `P1D` etc. The `<poller>` and `@Poller` don't support such a format. * Introduce a `PeriodicTriggerFactoryBean` to accept string values for trigger options and parse them manually before creating the target `PeriodicTrigger` * Use this `PeriodicTriggerFactoryBean` in the `PollerParser` and `AbstractMethodAnnotationPostProcessor` where we parse options for the `PeriodicTrigger` * Modify tests to ensure that feature works * Document the duration option * Add more cross-links into polling docs * Fix typos in the affected doc files * Add `-parameters` for compiler options since SF 6.1 does not support `-debug` anymore for method parameter names discovery * Fix typos Co-authored-by: Gary Russell <grussell@vmware.com> --------- Co-authored-by: Gary Russell <grussell@vmware.com>
- Loading branch information
1 parent
ba417de
commit c70d7a6
Showing
13 changed files
with
210 additions
and
84 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
115 changes: 115 additions & 0 deletions
115
...core/src/main/java/org/springframework/integration/config/PeriodicTriggerFactoryBean.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,115 @@ | ||
/* | ||
* Copyright 2023 the original author or authors. | ||
* | ||
* 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 | ||
* | ||
* https://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.springframework.integration.config; | ||
|
||
import java.time.Duration; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
import org.springframework.beans.factory.FactoryBean; | ||
import org.springframework.lang.Nullable; | ||
import org.springframework.scheduling.support.PeriodicTrigger; | ||
import org.springframework.util.Assert; | ||
import org.springframework.util.StringUtils; | ||
|
||
/** | ||
* The {@link FactoryBean} to produce a {@link PeriodicTrigger} | ||
* based on parsing string values for its options. | ||
* This class is mostly driven by the XML configuration requirements for | ||
* {@link Duration} value representations for the respective attributes. | ||
* | ||
* @author Artem Bilan | ||
* | ||
* @since 6.2 | ||
*/ | ||
public class PeriodicTriggerFactoryBean implements FactoryBean<PeriodicTrigger> { | ||
|
||
@Nullable | ||
private String fixedDelayValue; | ||
|
||
@Nullable | ||
private String fixedRateValue; | ||
|
||
@Nullable | ||
private String initialDelayValue; | ||
|
||
@Nullable | ||
private TimeUnit timeUnit; | ||
|
||
public void setFixedDelayValue(String fixedDelayValue) { | ||
this.fixedDelayValue = fixedDelayValue; | ||
} | ||
|
||
public void setFixedRateValue(String fixedRateValue) { | ||
this.fixedRateValue = fixedRateValue; | ||
} | ||
|
||
public void setInitialDelayValue(String initialDelayValue) { | ||
this.initialDelayValue = initialDelayValue; | ||
} | ||
|
||
public void setTimeUnit(TimeUnit timeUnit) { | ||
this.timeUnit = timeUnit; | ||
} | ||
|
||
@Override | ||
public PeriodicTrigger getObject() { | ||
boolean hasFixedDelay = StringUtils.hasText(this.fixedDelayValue); | ||
boolean hasFixedRate = StringUtils.hasText(this.fixedRateValue); | ||
|
||
Assert.isTrue(hasFixedDelay ^ hasFixedRate, | ||
"One of the 'fixedDelayValue' or 'fixedRateValue' property must be provided but not both."); | ||
|
||
TimeUnit timeUnitToUse = this.timeUnit; | ||
if (timeUnitToUse == null) { | ||
timeUnitToUse = TimeUnit.MILLISECONDS; | ||
} | ||
|
||
Duration duration = toDuration(hasFixedDelay ? this.fixedDelayValue : this.fixedRateValue, timeUnitToUse); | ||
|
||
PeriodicTrigger periodicTrigger = new PeriodicTrigger(duration); | ||
periodicTrigger.setFixedRate(hasFixedRate); | ||
if (StringUtils.hasText(this.initialDelayValue)) { | ||
periodicTrigger.setInitialDelay(toDuration(this.initialDelayValue, timeUnitToUse)); | ||
} | ||
return periodicTrigger; | ||
} | ||
|
||
@Override | ||
public Class<?> getObjectType() { | ||
return PeriodicTrigger.class; | ||
} | ||
|
||
private static Duration toDuration(String value, TimeUnit timeUnit) { | ||
if (isDurationString(value)) { | ||
return Duration.parse(value); | ||
} | ||
return toDuration(Long.parseLong(value), timeUnit); | ||
} | ||
|
||
private static boolean isDurationString(String value) { | ||
return (value.length() > 1 && (isP(value.charAt(0)) || isP(value.charAt(1)))); | ||
} | ||
|
||
private static boolean isP(char ch) { | ||
return (ch == 'P' || ch == 'p'); | ||
} | ||
|
||
private static Duration toDuration(long value, TimeUnit timeUnit) { | ||
return Duration.of(value, timeUnit.toChronoUnit()); | ||
} | ||
|
||
} |
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
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
2 changes: 1 addition & 1 deletion
2
...test/java/org/springframework/integration/configuration/EnableIntegrationTests.properties
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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
message.history.tracked.components=input, publishedChannel, annotationTestService* | ||
poller.maxMessagesPerPoll=10 | ||
poller.interval=100 | ||
poller.interval=PT0.1S | ||
poller.receiveTimeout=10000 | ||
global.wireTap.pattern=input |
Oops, something went wrong.