This is an automated email from the ASF dual-hosted git repository. davsclaus pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/camel.git
commit 0dfe11736d0193f70d5437b473473606ee3193a8 Author: Claus Ibsen <claus.ib...@gmail.com> AuthorDate: Sun Mar 15 11:02:36 2020 +0100 CAMEL-14575: camel-core - TypeConverter from String to Long - drop time pattern --- .../camel-timer/src/main/docs/timer-component.adoc | 9 - .../camel/component/timer/TimerEndpoint.java | 10 +- .../converter/TimePatternConverterLoader.java | 36 --- .../camel/converter/TimePatternConverter.java | 38 --- .../camel/converter/TimePatternConverterTest.java | 263 --------------------- .../camel/support/ScheduledPollEndpoint.java | 10 +- .../modules/ROOT/pages/timer-component.adoc | 9 - docs/user-manual-nav.adoc.template | 1 - docs/user-manual/modules/ROOT/nav.adoc | 1 - docs/user-manual/modules/ROOT/pages/faq.adoc | 1 - ...ify-time-period-in-a-human-friendly-syntax.adoc | 55 ----- 11 files changed, 4 insertions(+), 429 deletions(-) diff --git a/components/camel-timer/src/main/docs/timer-component.adoc b/components/camel-timer/src/main/docs/timer-component.adoc index 8adb7f7..221019e 100644 --- a/components/camel-timer/src/main/docs/timer-component.adoc +++ b/components/camel-timer/src/main/docs/timer-component.adoc @@ -35,15 +35,6 @@ See also the xref:quartz-component.adoc[Quartz] component that supports much mor advanced scheduling. ==== -[TIP] -==== -*Specify time in human friendly format* - -You can specify the time in -xref:manual::faq/how-do-i-specify-time-period-in-a-human-friendly-syntax.adoc[human -friendly syntax]. -==== - == Options diff --git a/components/camel-timer/src/main/java/org/apache/camel/component/timer/TimerEndpoint.java b/components/camel-timer/src/main/java/org/apache/camel/component/timer/TimerEndpoint.java index e1d9490..72a0685 100644 --- a/components/camel-timer/src/main/java/org/apache/camel/component/timer/TimerEndpoint.java +++ b/components/camel-timer/src/main/java/org/apache/camel/component/timer/TimerEndpoint.java @@ -43,11 +43,9 @@ import org.apache.camel.support.DefaultEndpoint; public class TimerEndpoint extends DefaultEndpoint implements MultipleConsumersSupport { @UriPath @Metadata(required = true) private String timerName; - @UriParam(defaultValue = "1000", description = "If greater than 0, generate periodic events every period milliseconds." - + " You can also specify time values using units, such as 60s (60 seconds), 5m30s (5 minutes and 30 seconds), and 1h (1 hour).") + @UriParam(defaultValue = "1000", description = "If greater than 0, generate periodic events every period milliseconds.") private long period = 1000; - @UriParam(defaultValue = "1000", description = "Miliseconds before first event is triggered." - + " You can also specify time values using units, such as 60s (60 seconds), 5m30s (5 minutes and 30 seconds), and 1h (1 hour).") + @UriParam(defaultValue = "1000", description = "Milliseconds before first event is triggered.") private long delay = 1000; @UriParam(defaultValue = "0") private long repeatCount; @@ -151,8 +149,6 @@ public class TimerEndpoint extends DefaultEndpoint implements MultipleConsumersS * The number of milliseconds to wait before the first event is generated. Should not be used in conjunction with the time option. * <p/> * The default value is 1000. - * You can also specify time values using units, such as 60s (60 seconds), 5m30s (5 minutes and 30 seconds), and 1h (1 hour). - * @see <a href="http://camel.apache.org/how-do-i-specify-time-period-in-a-human-friendly-syntax.html">human friendly syntax</a> */ @ManagedAttribute(description = "Timer Delay") public void setDelay(long delay) { @@ -181,8 +177,6 @@ public class TimerEndpoint extends DefaultEndpoint implements MultipleConsumersS * If greater than 0, generate periodic events every period milliseconds. * <p/> * The default value is 1000. - * You can also specify time values using units, such as 60s (60 seconds), 5m30s (5 minutes and 30 seconds), and 1h (1 hour). - * @see <a href="http://camel.apache.org/how-do-i-specify-time-period-in-a-human-friendly-syntax.html">human friendly syntax</a> */ @ManagedAttribute(description = "Timer Period") public void setPeriod(long period) { diff --git a/core/camel-base/src/generated/java/org/apache/camel/converter/TimePatternConverterLoader.java b/core/camel-base/src/generated/java/org/apache/camel/converter/TimePatternConverterLoader.java deleted file mode 100644 index 4f26a00..0000000 --- a/core/camel-base/src/generated/java/org/apache/camel/converter/TimePatternConverterLoader.java +++ /dev/null @@ -1,36 +0,0 @@ -/* Generated by camel build tools - do NOT edit this file! */ -package org.apache.camel.converter; - -import org.apache.camel.Exchange; -import org.apache.camel.TypeConversionException; -import org.apache.camel.TypeConverterLoaderException; -import org.apache.camel.spi.TypeConverterLoader; -import org.apache.camel.spi.TypeConverterRegistry; -import org.apache.camel.support.SimpleTypeConverter; -import org.apache.camel.support.TypeConverterSupport; -import org.apache.camel.util.DoubleMap; - -/** - * Generated by camel build tools - do NOT edit this file! - */ -@SuppressWarnings("unchecked") -public final class TimePatternConverterLoader implements TypeConverterLoader { - - public TimePatternConverterLoader() { - } - - @Override - public void load(TypeConverterRegistry registry) throws TypeConverterLoaderException { - registerConverters(registry); - } - - private void registerConverters(TypeConverterRegistry registry) { - addTypeConverter(registry, long.class, java.lang.String.class, false, - (type, exchange, value) -> org.apache.camel.converter.TimePatternConverter.toMilliSeconds((java.lang.String) value)); - } - - private static void addTypeConverter(TypeConverterRegistry registry, Class<?> toType, Class<?> fromType, boolean allowNull, SimpleTypeConverter.ConversionMethod method) { - registry.addTypeConverter(toType, fromType, new SimpleTypeConverter(allowNull, method)); - } - -} diff --git a/core/camel-base/src/main/java/org/apache/camel/converter/TimePatternConverter.java b/core/camel-base/src/main/java/org/apache/camel/converter/TimePatternConverter.java deleted file mode 100644 index c809fed..0000000 --- a/core/camel-base/src/main/java/org/apache/camel/converter/TimePatternConverter.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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.apache.camel.converter; - -import org.apache.camel.Converter; -import org.apache.camel.util.TimeUtils; - -/** - * Converter from String syntax to milli seconds. - */ -@Converter(generateLoader = true) -public final class TimePatternConverter { - - /** - * Utility classes should not have a public constructor. - */ - private TimePatternConverter() { - } - - @Converter - public static long toMilliSeconds(String source) throws IllegalArgumentException { - return TimeUtils.toMilliSeconds(source); - } -} diff --git a/core/camel-core/src/test/java/org/apache/camel/converter/TimePatternConverterTest.java b/core/camel-core/src/test/java/org/apache/camel/converter/TimePatternConverterTest.java deleted file mode 100644 index 9029bfb..0000000 --- a/core/camel-core/src/test/java/org/apache/camel/converter/TimePatternConverterTest.java +++ /dev/null @@ -1,263 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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.apache.camel.converter; - -import org.apache.camel.ContextTestSupport; -import org.junit.Test; - -import static org.hamcrest.core.Is.is; - -public class TimePatternConverterTest extends ContextTestSupport { - - @Test - public void testMillisecondsTimePattern() throws Exception { - String source = "444"; - long milliseconds = TimePatternConverter.toMilliSeconds(source); - assertEquals(444, milliseconds); - } - - @Test - public void testMilliseconds2TimePattern() throws Exception { - String source = "-72"; - long milliseconds = TimePatternConverter.toMilliSeconds(source); - assertEquals(-72, milliseconds); - } - - @Test - public void testSTimePattern() throws Exception { - String source = "35s"; - long milliseconds = TimePatternConverter.toMilliSeconds(source); - assertEquals(35000, milliseconds); - } - - @Test - public void testSecTimePattern() throws Exception { - String source = "35sec"; - long milliseconds = TimePatternConverter.toMilliSeconds(source); - assertEquals(35000, milliseconds); - } - - @Test - public void testSecsTimePattern() throws Exception { - String source = "35secs"; - long milliseconds = TimePatternConverter.toMilliSeconds(source); - assertEquals(35000, milliseconds); - } - - @Test - public void testSecondTimePattern() throws Exception { - String source = "35second"; - long milliseconds = TimePatternConverter.toMilliSeconds(source); - assertEquals(35000, milliseconds); - } - - @Test - public void testSecondsTimePattern() throws Exception { - String source = "35seconds"; - long milliseconds = TimePatternConverter.toMilliSeconds(source); - assertEquals(35000, milliseconds); - } - - @Test - public void testConsiderLegalSTimePattern() throws Exception { - String source = "89s"; - long milliseconds = TimePatternConverter.toMilliSeconds(source); - assertEquals(89000, milliseconds); - } - - @Test - public void testMTimePattern() throws Exception { - String source = "28m"; - long milliseconds = TimePatternConverter.toMilliSeconds(source); - assertEquals(1680000, milliseconds); - } - - @Test - public void testMinTimePattern() throws Exception { - String source = "28min"; - long milliseconds = TimePatternConverter.toMilliSeconds(source); - assertEquals(1680000, milliseconds); - } - - @Test - public void testMinuteTimePattern() throws Exception { - String source = "28MINUTE"; - long milliseconds = TimePatternConverter.toMilliSeconds(source); - assertEquals(1680000, milliseconds); - } - - @Test - public void testMinutesTimePattern() throws Exception { - String source = "28Minutes"; - long milliseconds = TimePatternConverter.toMilliSeconds(source); - assertEquals(1680000, milliseconds); - } - - @Test - public void testConsiderLegalMTimePattern() throws Exception { - String source = "89m"; - long milliseconds = TimePatternConverter.toMilliSeconds(source); - assertEquals(5340000, milliseconds); - } - - @Test - public void testHTimePattern() throws Exception { - String source = "28h"; - long milliseconds = TimePatternConverter.toMilliSeconds(source); - assertEquals(100800000, milliseconds); - } - - @Test - public void testHourTimePattern() throws Exception { - String source = "28Hour"; - long milliseconds = TimePatternConverter.toMilliSeconds(source); - assertEquals(100800000, milliseconds); - } - - @Test - public void testHoursTimePattern() throws Exception { - String source = "28HOURS"; - long milliseconds = TimePatternConverter.toMilliSeconds(source); - assertEquals(100800000, milliseconds); - } - - @Test - public void testHMSTimePattern() throws Exception { - String source = "1h3m5s"; - long milliseconds = TimePatternConverter.toMilliSeconds(source); - assertEquals(3785000, milliseconds); - } - - @Test - public void testHMSTimePattern2() throws Exception { - String source = "1hours30minutes1second"; - long milliseconds = TimePatternConverter.toMilliSeconds(source); - assertEquals(5401000, milliseconds); - } - - @Test - public void testHMSTimePattern3() throws Exception { - String source = "1HOUR3m5s"; - long milliseconds = TimePatternConverter.toMilliSeconds(source); - assertEquals(3785000, milliseconds); - } - - @Test - public void testMSTimePattern() throws Exception { - String source = "30m55s"; - long milliseconds = TimePatternConverter.toMilliSeconds(source); - assertEquals(1855000, milliseconds); - } - - @Test - public void testHMTimePattern() throws Exception { - String source = "1h30m"; - long milliseconds = TimePatternConverter.toMilliSeconds(source); - assertEquals(5400000, milliseconds); - } - - @Test - public void testSTimePattern2() throws Exception { - String source = "15sec"; - long milliseconds = TimePatternConverter.toMilliSeconds(source); - assertEquals(15000, milliseconds); - } - - @Test - public void testMTimePattern2() throws Exception { - String source = "5min"; - long milliseconds = TimePatternConverter.toMilliSeconds(source); - assertEquals(300000, milliseconds); - } - - @Test - public void testMTimePattern3() throws Exception { - String source = "5MIN"; - long milliseconds = TimePatternConverter.toMilliSeconds(source); - assertEquals(300000, milliseconds); - } - - @Test - public void testMSTimePattern2() throws Exception { - String source = "4min2sec"; - long milliseconds = TimePatternConverter.toMilliSeconds(source); - assertEquals(242000, milliseconds); - } - - // Negative Tests - @Test - public void testIllegalHMSTimePattern() { - String source = "36h88m5s"; - checkForIllegalArgument(source, "Minutes should contain a valid value between 0 and 59: " + source); - } - - @Test - public void testHoursTwice() { - String source = "36h12hours"; - String expectedMessage = "Hours should not be specified more then once: " + source; - checkForIllegalArgument(source, expectedMessage); - } - - @Test - public void testMinutesTwice() { - String source = "36minute12min"; - String expectedMessage = "Minutes should not be specified more then once: " + source; - checkForIllegalArgument(source, expectedMessage); - } - - @Test - public void testSecondsTwice() { - String source = "36sec12second"; - String expectedMessage = "Seconds should not be specified more then once: " + source; - checkForIllegalArgument(source, expectedMessage); - } - - @Test - public void testIllegalMSTimePattern() { - String source = "55m75s"; - checkForIllegalArgument(source, "Seconds should contain a valid value between 0 and 59: " + source); - } - - @Test - public void testIllegalHMTimePattern() throws Exception { - String source = "1h89s"; - checkForIllegalArgument(source, "Seconds should contain a valid value between 0 and 59: " + source); - } - - @Test - public void testIllegalCharacters() throws Exception { - String source = "5ssegegegegqergerg"; - checkForIllegalArgument(source, "Illegal characters: " + source); - } - - @Test - public void testSsCharacters() throws Exception { - String source = "5ss"; - checkForIllegalArgument(source, "Illegal characters: " + source); - } - - private void checkForIllegalArgument(String source, String expectedMessage) { - try { - TimePatternConverter.toMilliSeconds(source); - fail("Should throw IllegalArgumentException"); - } catch (Exception e) { - assertIsInstanceOf(IllegalArgumentException.class, e); - assertThat(e.getMessage(), is(expectedMessage)); - } - } - -} diff --git a/core/camel-support/src/main/java/org/apache/camel/support/ScheduledPollEndpoint.java b/core/camel-support/src/main/java/org/apache/camel/support/ScheduledPollEndpoint.java index 21a5164..d85356e 100644 --- a/core/camel-support/src/main/java/org/apache/camel/support/ScheduledPollEndpoint.java +++ b/core/camel-support/src/main/java/org/apache/camel/support/ScheduledPollEndpoint.java @@ -43,12 +43,10 @@ public abstract class ScheduledPollEndpoint extends DefaultEndpoint { description = "Whether the scheduler should be auto started.") private boolean startScheduler = true; @UriParam(defaultValue = "1000", label = "consumer,scheduler", - description = "Milliseconds before the first poll starts." - + " You can also specify time values using units, such as 60s (60 seconds), 5m30s (5 minutes and 30 seconds), and 1h (1 hour).") + description = "Milliseconds before the first poll starts.") private long initialDelay = 1000; @UriParam(defaultValue = "500", label = "consumer,scheduler", - description = "Milliseconds before the next poll." - + " You can also specify time values using units, such as 60s (60 seconds), 5m30s (5 minutes and 30 seconds), and 1h (1 hour).") + description = "Milliseconds before the next poll.") private long delay = 500; @UriParam(defaultValue = "MILLISECONDS", label = "consumer,scheduler", description = "Time unit for initialDelay and delay options.") @@ -205,8 +203,6 @@ public abstract class ScheduledPollEndpoint extends DefaultEndpoint { * Milliseconds before the first poll starts. * <p/> * The default value is 1000. - * You can also specify time values using units, such as 60s (60 seconds), 5m30s (5 minutes and 30 seconds), and 1h (1 hour). - * @see <a href="http://camel.apache.org/how-do-i-specify-time-period-in-a-human-friendly-syntax.html">human friendly syntax</a> */ public void setInitialDelay(long initialDelay) { this.initialDelay = initialDelay; @@ -220,8 +216,6 @@ public abstract class ScheduledPollEndpoint extends DefaultEndpoint { * Milliseconds before the next poll. * <p/> * The default value is 500. - * You can also specify time values using units, such as 60s (60 seconds), 5m30s (5 minutes and 30 seconds), and 1h (1 hour). - * @see <a href="http://camel.apache.org/how-do-i-specify-time-period-in-a-human-friendly-syntax.html">human friendly syntax</a> */ public void setDelay(long delay) { this.delay = delay; diff --git a/docs/components/modules/ROOT/pages/timer-component.adoc b/docs/components/modules/ROOT/pages/timer-component.adoc index 0460a10..46dbf21 100644 --- a/docs/components/modules/ROOT/pages/timer-component.adoc +++ b/docs/components/modules/ROOT/pages/timer-component.adoc @@ -36,15 +36,6 @@ See also the xref:quartz-component.adoc[Quartz] component that supports much mor advanced scheduling. ==== -[TIP] -==== -*Specify time in human friendly format* - -You can specify the time in -xref:manual::faq/how-do-i-specify-time-period-in-a-human-friendly-syntax.adoc[human -friendly syntax]. -==== - == Options diff --git a/docs/user-manual-nav.adoc.template b/docs/user-manual-nav.adoc.template index 7a697b0..d7d41ee 100644 --- a/docs/user-manual-nav.adoc.template +++ b/docs/user-manual-nav.adoc.template @@ -114,7 +114,6 @@ ** xref:faq/how-do-i-reuse-the-contexttestsupport-class-in-my-unit-tests.adoc[How do I reuse the ContextTestSupport class in my unit tests?] ** xref:faq/how-do-i-run-activemq-and-camel-in-jboss.adoc[How do I run ActiveMQ and Camel in JBoss?] ** xref:faq/how-do-i-set-the-max-chars-when-debug-logging-messages-in-camel.adoc[How do I set the max chars when debug logging messages in Camel?] - ** xref:faq/how-do-i-specify-time-period-in-a-human-friendly-syntax.adoc[How do I specify time period in a human friendly syntax?] ** xref:faq/how-do-i-use-a-big-uber-jar.adoc[How do I use a big (uber) JAR?] ** xref:faq/how-do-i-use-camel-inside-servicemix.adoc[How do I use Camel inside ServiceMix?] ** xref:faq/how-do-i-use-spring-property-placeholder-with-camel-xml.adoc[How do I use Spring Property Placeholder with Camel XML?] diff --git a/docs/user-manual/modules/ROOT/nav.adoc b/docs/user-manual/modules/ROOT/nav.adoc index 174090d..cee82b6 100644 --- a/docs/user-manual/modules/ROOT/nav.adoc +++ b/docs/user-manual/modules/ROOT/nav.adoc @@ -183,7 +183,6 @@ ** xref:faq/how-do-i-reuse-the-contexttestsupport-class-in-my-unit-tests.adoc[How do I reuse the ContextTestSupport class in my unit tests?] ** xref:faq/how-do-i-run-activemq-and-camel-in-jboss.adoc[How do I run ActiveMQ and Camel in JBoss?] ** xref:faq/how-do-i-set-the-max-chars-when-debug-logging-messages-in-camel.adoc[How do I set the max chars when debug logging messages in Camel?] - ** xref:faq/how-do-i-specify-time-period-in-a-human-friendly-syntax.adoc[How do I specify time period in a human friendly syntax?] ** xref:faq/how-do-i-use-a-big-uber-jar.adoc[How do I use a big (uber) JAR?] ** xref:faq/how-do-i-use-camel-inside-servicemix.adoc[How do I use Camel inside ServiceMix?] ** xref:faq/how-do-i-use-spring-property-placeholder-with-camel-xml.adoc[How do I use Spring Property Placeholder with Camel XML?] diff --git a/docs/user-manual/modules/ROOT/pages/faq.adoc b/docs/user-manual/modules/ROOT/pages/faq.adoc index b56735c..004e73b 100644 --- a/docs/user-manual/modules/ROOT/pages/faq.adoc +++ b/docs/user-manual/modules/ROOT/pages/faq.adoc @@ -87,7 +87,6 @@ Questions on using Apache Camel * xref:faq/how-do-i-reuse-the-contexttestsupport-class-in-my-unit-tests.adoc[How do I reuse the ContextTestSupport class in my unit tests?] * xref:faq/how-do-i-run-activemq-and-camel-in-jboss.adoc[How do I run ActiveMQ and Camel in JBoss?] * xref:faq/how-do-i-set-the-max-chars-when-debug-logging-messages-in-camel.adoc[How do I set the max chars when debug logging messages in Camel?] -* xref:faq/how-do-i-specify-time-period-in-a-human-friendly-syntax.adoc[How do I specify time period in a human friendly syntax?] * xref:faq/how-do-i-use-a-big-uber-jar.adoc[How do I use a big (uber) JAR?] * xref:faq/how-do-i-use-camel-inside-servicemix.adoc[How do I use Camel inside ServiceMix?] * xref:faq/how-do-i-use-spring-property-placeholder-with-camel-xml.adoc[How do I use Spring Property Placeholder with Camel XML?] diff --git a/docs/user-manual/modules/ROOT/pages/faq/how-do-i-specify-time-period-in-a-human-friendly-syntax.adoc b/docs/user-manual/modules/ROOT/pages/faq/how-do-i-specify-time-period-in-a-human-friendly-syntax.adoc deleted file mode 100644 index 44f7afa..0000000 --- a/docs/user-manual/modules/ROOT/pages/faq/how-do-i-specify-time-period-in-a-human-friendly-syntax.adoc +++ /dev/null @@ -1,55 +0,0 @@ -[[HowdoIspecifytimeperiodinahumanfriendlysyntax-HowdoIspecifytimeperiodinahumanfriendlysyntax]] -= How do I specify time period in a human friendly syntax? - -*Since Camel 2.3* - -Some of the Camel xref:component.adoc[components] offers options to -specify a time period, which must be entered in milli second as unit. -This may be unfriendly to read as a human when the value is large such -as 45min = 2700000 millis. - -So in Camel 2.3 you can now configure any endpoint uri parameter using a -String syntax, which at runtime will get converted to millis (`long` -type). - -You can use the following short syntax, which is most common to use: - -[width="100%",cols="50%,50%",options="header",] -|============ -|Syntax |Unit -|h |hour -|m |minute -|s |second -|============ - -So for example the xref:components::timer-component.adoc[Timer] endpoint can be configured as -follows: - -[source,java] ----- -from("timer:foo?period=45m").to("log:foo"); ----- - -You can mix and match the units so you can do this as well: - -[source,java] ----- -from("timer:foo?period=1h15m").to("log:foo"); -from("timer:bar?period=2h30s").to("log:bar"); -from("timer:bar?period=3h45m58s").to("log:bar"); ----- - -However you can also use long syntax: - -[width="100%",cols="50%,50%",options="header",] -|========================= -|Syntax |Unit -|hour or hours |hour -|minute or minutes |minute -|second or seconds |second -|========================= - -[source,java] ----- -from("timer:foo?period=45minutes").to("log:foo"); -----