You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@camel.apache.org by "Claus Ibsen (JIRA)" <ji...@apache.org> on 2010/04/11 10:21:43 UTC

[jira] Created: (CAMEL-2631) Add time millis converter which can convert from String to long

Add time millis converter which can convert from String to long
---------------------------------------------------------------

                 Key: CAMEL-2631
                 URL: https://issues.apache.org/activemq/browse/CAMEL-2631
             Project: Apache Camel
          Issue Type: New Feature
          Components: camel-core
            Reporter: Claus Ibsen
            Priority: Minor


Its currently a bit annoying to set a delay by millis and if you need, like 1 hour 30 min period. What is this in millis?

We should add a TypeConverter for that which has a String notation such as:
{code}
1h30m
3h45m25s
10m
15m20s
30s
{code}


-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: https://issues.apache.org/activemq/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] Resolved: (CAMEL-2631) Add time millis converter which can convert from String to long

Posted by "Ashwin Karpe (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/activemq/browse/CAMEL-2631?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Ashwin Karpe resolved CAMEL-2631.
---------------------------------

    Fix Version/s: 2.3.0
       Resolution: Fixed

> Add time millis converter which can convert from String to long
> ---------------------------------------------------------------
>
>                 Key: CAMEL-2631
>                 URL: https://issues.apache.org/activemq/browse/CAMEL-2631
>             Project: Apache Camel
>          Issue Type: New Feature
>          Components: camel-core
>            Reporter: Claus Ibsen
>            Assignee: Ashwin Karpe
>            Priority: Minor
>             Fix For: 2.3.0
>
>         Attachments: time-pattern-converter-patch.diff
>
>
> Its currently a bit annoying to set a delay by millis and if you need, like 1 hour 30 min period. What is this in millis?
> We should add a TypeConverter for that which has a String notation such as:
> {code}
> 1h30m
> 3h45m25s
> 10m
> 15m20s
> 30s
> {code}

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (CAMEL-2631) Add time millis converter which can convert from String to long

Posted by "Ashwin Karpe (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/activemq/browse/CAMEL-2631?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=59148#action_59148 ] 

Ashwin Karpe commented on CAMEL-2631:
-------------------------------------

Committed as revision - r938630

> Add time millis converter which can convert from String to long
> ---------------------------------------------------------------
>
>                 Key: CAMEL-2631
>                 URL: https://issues.apache.org/activemq/browse/CAMEL-2631
>             Project: Apache Camel
>          Issue Type: New Feature
>          Components: camel-core
>            Reporter: Claus Ibsen
>            Assignee: Ashwin Karpe
>            Priority: Minor
>         Attachments: time-pattern-converter-patch.diff
>
>
> Its currently a bit annoying to set a delay by millis and if you need, like 1 hour 30 min period. What is this in millis?
> We should add a TypeConverter for that which has a String notation such as:
> {code}
> 1h30m
> 3h45m25s
> 10m
> 15m20s
> 30s
> {code}

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (CAMEL-2631) Add time millis converter which can convert from String to long

Posted by "Ashwin Karpe (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/activemq/browse/CAMEL-2631?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=59044#action_59044 ] 

Ashwin Karpe commented on CAMEL-2631:
-------------------------------------

Claus,

I think I have a nicer workaround for the above mentioned problem. I will submit a fresh patch with the workaround.

Cheers,

Ashwin...

> Add time millis converter which can convert from String to long
> ---------------------------------------------------------------
>
>                 Key: CAMEL-2631
>                 URL: https://issues.apache.org/activemq/browse/CAMEL-2631
>             Project: Apache Camel
>          Issue Type: New Feature
>          Components: camel-core
>            Reporter: Claus Ibsen
>            Assignee: Ashwin Karpe
>            Priority: Minor
>         Attachments: time-pattern-converter-patch3.diff
>
>
> Its currently a bit annoying to set a delay by millis and if you need, like 1 hour 30 min period. What is this in millis?
> We should add a TypeConverter for that which has a String notation such as:
> {code}
> 1h30m
> 3h45m25s
> 10m
> 15m20s
> 30s
> {code}

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Issue Comment Edited: (CAMEL-2631) Add time millis converter which can convert from String to long

Posted by "Claus Ibsen (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/activemq/browse/CAMEL-2631?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=59114#action_59114 ] 

Claus Ibsen edited comment on CAMEL-2631 at 4/27/10 12:47 AM:
--------------------------------------------------------------

Ashwin

Much better. Only a few more tweaks

1)
{code}
 try {
+            long milliseconds = TimePatternConverter.toMilliSeconds(source);
+        } catch (IllegalArgumentException e) {
+            LOG.debug("Following exception thrown: " + e.getMessage());
+            assertIsInstanceOf(IllegalArgumentException.class, e);
+        }
{code}

Here you need to add a fail check if the exception was NOT thrown
{code}
 try {
+            long milliseconds = TimePatternConverter.toMilliSeconds(source);
              fail("Should throw exception");
+        } catch (IllegalArgumentException e) {
+            LOG.debug("Following exception thrown: " + e.getMessage());
+            assertIsInstanceOf(IllegalArgumentException.class, e);
+        }
{code}


2)
And you catch an IllegalArgumentException which you then assert is the same instance :) You would often just have used
{code}
catch(Exception e)
         assertIsInstanceOf(IllegalArgumentException.class, e);
    assertEquals"The bla bla should have", e.getMessage());
{code}
And also check the error message is correct


3)
And we should documented in the source code of the converter that it will *also* be used for regular numbers. i.e. its a String -> long converter which does that for all Strings.


4)
The only problem which could occur is that *none* pattern matched, then you would return 0. I think we should add a fallback to let it use the following code
{code}
   // no pattern matched so fallback and let Long convert it
            return Long.valueOf(value);
{code}

      was (Author: davsclaus):
    Ashwin

Much better. Only one left.

{code}
 try {
+            long milliseconds = TimePatternConverter.toMilliSeconds(source);
+        } catch (IllegalArgumentException e) {
+            LOG.debug("Following exception thrown: " + e.getMessage());
+            assertIsInstanceOf(IllegalArgumentException.class, e);
+        }
{code}

Here you need to add a fail check if the exception was NOT thrown
{code}
 try {
+            long milliseconds = TimePatternConverter.toMilliSeconds(source);
              fail("Should throw exception");
+        } catch (IllegalArgumentException e) {
+            LOG.debug("Following exception thrown: " + e.getMessage());
+            assertIsInstanceOf(IllegalArgumentException.class, e);
+        }

And you catch an IllegalArgumentException which you then assert is the same instance :) You would often just have used
{code}
catch(Exception e)
         assertIsInstanceOf(IllegalArgumentException.class, e);
    assertEquals"The bla bla should have", e.getMessage());
{code}
And also check the error message is correct


And we should documented in the source code of the converter that it will *also* be used for regular numbers. i.e. its a String -> long converter which does that for all Strings.
The only problem which could occur is that *none* pattern matched, then you would return 0. I think we should add a fallback to let it use the following code
{code}
   // no pattern matched so fallback and let Long convert it
            return Long.valueOf(value);
{code}
  
> Add time millis converter which can convert from String to long
> ---------------------------------------------------------------
>
>                 Key: CAMEL-2631
>                 URL: https://issues.apache.org/activemq/browse/CAMEL-2631
>             Project: Apache Camel
>          Issue Type: New Feature
>          Components: camel-core
>            Reporter: Claus Ibsen
>            Assignee: Ashwin Karpe
>            Priority: Minor
>         Attachments: time-pattern-converter-patch.diff
>
>
> Its currently a bit annoying to set a delay by millis and if you need, like 1 hour 30 min period. What is this in millis?
> We should add a TypeConverter for that which has a String notation such as:
> {code}
> 1h30m
> 3h45m25s
> 10m
> 15m20s
> 30s
> {code}

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (CAMEL-2631) Add time millis converter which can convert from String to long

Posted by "Claus Ibsen (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/activemq/browse/CAMEL-2631?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=58999#action_58999 ] 

Claus Ibsen commented on CAMEL-2631:
------------------------------------

Ah I was a bit misleading.

The Void.TYPE thingy only applies for @FallbackTypeConverters, where you can indicate that you do not know how to convert that particular type mapping combo.

So in our case as its a real type converter you HAVE to convert to a long to be returned. So if you get "444" as input, then output should be a 444 long value.
This is missing. 

And add a test for that also.


On a side note. I wonder if we should allow different abbreviations
- h | H | hour | Hour | hours | Hours
- m | M | min | Min | minute | Minute | minutes | Minutes
- s | S | sec | Sec | second | Second | seconds | Seconds

Maybe it improves readability
{code}
3hours2minutes1second
15sec
5min
4min2sec
{code}

> Add time millis converter which can convert from String to long
> ---------------------------------------------------------------
>
>                 Key: CAMEL-2631
>                 URL: https://issues.apache.org/activemq/browse/CAMEL-2631
>             Project: Apache Camel
>          Issue Type: New Feature
>          Components: camel-core
>            Reporter: Claus Ibsen
>            Assignee: Ashwin Karpe
>            Priority: Minor
>         Attachments: time-pattern-converter-patch2.diff
>
>
> Its currently a bit annoying to set a delay by millis and if you need, like 1 hour 30 min period. What is this in millis?
> We should add a TypeConverter for that which has a String notation such as:
> {code}
> 1h30m
> 3h45m25s
> 10m
> 15m20s
> 30s
> {code}

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Updated: (CAMEL-2631) Add time millis converter which can convert from String to long

Posted by "Ashwin Karpe (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/activemq/browse/CAMEL-2631?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Ashwin Karpe updated CAMEL-2631:
--------------------------------

    Attachment: time-pattern-converter-patch.diff

The final changes have been made. I have tested and source-checked the code and believe it to be ready for commit. I will do so shortly.

Cheers,

Ashwin...

> Add time millis converter which can convert from String to long
> ---------------------------------------------------------------
>
>                 Key: CAMEL-2631
>                 URL: https://issues.apache.org/activemq/browse/CAMEL-2631
>             Project: Apache Camel
>          Issue Type: New Feature
>          Components: camel-core
>            Reporter: Claus Ibsen
>            Assignee: Ashwin Karpe
>            Priority: Minor
>         Attachments: time-pattern-converter-patch.diff
>
>
> Its currently a bit annoying to set a delay by millis and if you need, like 1 hour 30 min period. What is this in millis?
> We should add a TypeConverter for that which has a String notation such as:
> {code}
> 1h30m
> 3h45m25s
> 10m
> 15m20s
> 30s
> {code}

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Updated: (CAMEL-2631) Add time millis converter which can convert from String to long

Posted by "Ashwin Karpe (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/activemq/browse/CAMEL-2631?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Ashwin Karpe updated CAMEL-2631:
--------------------------------

    Attachment: time-pattern-converter-patch.diff

Hi Claus,

Please find attached a TimePatternConverter that fulfills this requirement. 

Could you please review and let me know if I can go ahead and commit it to the core.

Cheers,

Ashwin...

> Add time millis converter which can convert from String to long
> ---------------------------------------------------------------
>
>                 Key: CAMEL-2631
>                 URL: https://issues.apache.org/activemq/browse/CAMEL-2631
>             Project: Apache Camel
>          Issue Type: New Feature
>          Components: camel-core
>            Reporter: Claus Ibsen
>            Assignee: Ashwin Karpe
>            Priority: Minor
>         Attachments: time-pattern-converter-patch.diff
>
>
> Its currently a bit annoying to set a delay by millis and if you need, like 1 hour 30 min period. What is this in millis?
> We should add a TypeConverter for that which has a String notation such as:
> {code}
> 1h30m
> 3h45m25s
> 10m
> 15m20s
> 30s
> {code}

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Issue Comment Edited: (CAMEL-2631) Add time millis converter which can convert from String to long

Posted by "Ashwin Karpe (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/activemq/browse/CAMEL-2631?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=59102#action_59102 ] 

Ashwin Karpe edited comment on CAMEL-2631 at 4/26/10 1:07 PM:
--------------------------------------------------------------

Hi Claus,

Please find the changes you suggested. I have added new tests cases to use the StopWatch and convertTo() functions.

Please also find the minor fixes you recommended. I will commit the changes if you agree with the incremental changes.

Cheers,

Ashwin...

      was (Author: akarpe):
    Hi Claus,

Please find the changes you suggested. I have added new tests cases to use the StopWatch and convertTo() functions.

Please also find the minor fixes you recommended. 

Cheers,

Ashwin...
  
> Add time millis converter which can convert from String to long
> ---------------------------------------------------------------
>
>                 Key: CAMEL-2631
>                 URL: https://issues.apache.org/activemq/browse/CAMEL-2631
>             Project: Apache Camel
>          Issue Type: New Feature
>          Components: camel-core
>            Reporter: Claus Ibsen
>            Assignee: Ashwin Karpe
>            Priority: Minor
>         Attachments: time-pattern-converter-patch5.diff
>
>
> Its currently a bit annoying to set a delay by millis and if you need, like 1 hour 30 min period. What is this in millis?
> We should add a TypeConverter for that which has a String notation such as:
> {code}
> 1h30m
> 3h45m25s
> 10m
> 15m20s
> 30s
> {code}

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (CAMEL-2631) Add time millis converter which can convert from String to long

Posted by "Claus Ibsen (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/activemq/browse/CAMEL-2631?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=59105#action_59105 ] 

Claus Ibsen commented on CAMEL-2631:
------------------------------------

Still some comments

1)
Do not use new String, this is not best practice

2)
In this test TimePatternTypeConversionTest do not create the CamelContext yourself as you extend ContextTestSupport which creates the context for you

3)
You should add tests which test with JUST numbers, eg "444" to see that your get a long 444 value.
And double check that type converting a JUST number works out of the box. So there are no unforeseen side side effects.

4)
And remove code which should be removed (eg code which you have added // )

> Add time millis converter which can convert from String to long
> ---------------------------------------------------------------
>
>                 Key: CAMEL-2631
>                 URL: https://issues.apache.org/activemq/browse/CAMEL-2631
>             Project: Apache Camel
>          Issue Type: New Feature
>          Components: camel-core
>            Reporter: Claus Ibsen
>            Assignee: Ashwin Karpe
>            Priority: Minor
>         Attachments: time-pattern-converter-patch5.diff
>
>
> Its currently a bit annoying to set a delay by millis and if you need, like 1 hour 30 min period. What is this in millis?
> We should add a TypeConverter for that which has a String notation such as:
> {code}
> 1h30m
> 3h45m25s
> 10m
> 15m20s
> 30s
> {code}

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Updated: (CAMEL-2631) Add time millis converter which can convert from String to long

Posted by "Ashwin Karpe (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/activemq/browse/CAMEL-2631?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Ashwin Karpe updated CAMEL-2631:
--------------------------------

    Attachment:     (was: time-pattern-converter-patch2.diff)

> Add time millis converter which can convert from String to long
> ---------------------------------------------------------------
>
>                 Key: CAMEL-2631
>                 URL: https://issues.apache.org/activemq/browse/CAMEL-2631
>             Project: Apache Camel
>          Issue Type: New Feature
>          Components: camel-core
>            Reporter: Claus Ibsen
>            Assignee: Ashwin Karpe
>            Priority: Minor
>         Attachments: time-pattern-converter-patch3.diff
>
>
> Its currently a bit annoying to set a delay by millis and if you need, like 1 hour 30 min period. What is this in millis?
> We should add a TypeConverter for that which has a String notation such as:
> {code}
> 1h30m
> 3h45m25s
> 10m
> 15m20s
> 30s
> {code}

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Updated: (CAMEL-2631) Add time millis converter which can convert from String to long

Posted by "Ashwin Karpe (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/activemq/browse/CAMEL-2631?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Ashwin Karpe updated CAMEL-2631:
--------------------------------

    Attachment:     (was: time-pattern-converter-patch.diff)

> Add time millis converter which can convert from String to long
> ---------------------------------------------------------------
>
>                 Key: CAMEL-2631
>                 URL: https://issues.apache.org/activemq/browse/CAMEL-2631
>             Project: Apache Camel
>          Issue Type: New Feature
>          Components: camel-core
>            Reporter: Claus Ibsen
>            Assignee: Ashwin Karpe
>            Priority: Minor
>         Attachments: time-pattern-converter-patch2.diff
>
>
> Its currently a bit annoying to set a delay by millis and if you need, like 1 hour 30 min period. What is this in millis?
> We should add a TypeConverter for that which has a String notation such as:
> {code}
> 1h30m
> 3h45m25s
> 10m
> 15m20s
> 30s
> {code}

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Updated: (CAMEL-2631) Add time millis converter which can convert from String to long

Posted by "Ashwin Karpe (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/activemq/browse/CAMEL-2631?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Ashwin Karpe updated CAMEL-2631:
--------------------------------

    Attachment: time-pattern-converter-patch5.diff

Hi Claus,

Please find the changes you suggested. I have added new tests cases to use the StopWatch and convertTo() functions.

Please also find the minor fixes you recommended. 

Cheers,

Ashwin...

> Add time millis converter which can convert from String to long
> ---------------------------------------------------------------
>
>                 Key: CAMEL-2631
>                 URL: https://issues.apache.org/activemq/browse/CAMEL-2631
>             Project: Apache Camel
>          Issue Type: New Feature
>          Components: camel-core
>            Reporter: Claus Ibsen
>            Assignee: Ashwin Karpe
>            Priority: Minor
>         Attachments: time-pattern-converter-patch5.diff
>
>
> Its currently a bit annoying to set a delay by millis and if you need, like 1 hour 30 min period. What is this in millis?
> We should add a TypeConverter for that which has a String notation such as:
> {code}
> 1h30m
> 3h45m25s
> 10m
> 15m20s
> 30s
> {code}

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Issue Comment Edited: (CAMEL-2631) Add time millis converter which can convert from String to long

Posted by "Ashwin Karpe (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/activemq/browse/CAMEL-2631?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=59062#action_59062 ] 

Ashwin Karpe edited comment on CAMEL-2631 at 4/23/10 10:20 AM:
---------------------------------------------------------------

Hi Claus,

Just sending a long vale of 149 will not cause the TimePatternConverter to kick in... Same is true of negative Strings.

I will add a Test to discover the TypeConverter and add a stopwatch test to the Timer test

I have made the other changes :)

Cheers,

Ashwin...

      was (Author: akarpe):
    Hi Claus,

Just sending a long vale of 149 will not cause the TimePatternConverter to kick in... Same is true of negative Strings.

I will add a Test to discover the TypeConverter and add a stopwatch test to the Timer test

I have made the other changes 
  
> Add time millis converter which can convert from String to long
> ---------------------------------------------------------------
>
>                 Key: CAMEL-2631
>                 URL: https://issues.apache.org/activemq/browse/CAMEL-2631
>             Project: Apache Camel
>          Issue Type: New Feature
>          Components: camel-core
>            Reporter: Claus Ibsen
>            Assignee: Ashwin Karpe
>            Priority: Minor
>         Attachments: time-pattern-converter-patch4.diff
>
>
> Its currently a bit annoying to set a delay by millis and if you need, like 1 hour 30 min period. What is this in millis?
> We should add a TypeConverter for that which has a String notation such as:
> {code}
> 1h30m
> 3h45m25s
> 10m
> 15m20s
> 30s
> {code}

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (CAMEL-2631) Add time millis converter which can convert from String to long

Posted by "Ashwin Karpe (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/activemq/browse/CAMEL-2631?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=59062#action_59062 ] 

Ashwin Karpe commented on CAMEL-2631:
-------------------------------------

Hi Claus,

Just sending a long vale of 149 will not cause the TimePatternConverter to kick in... Same is true of negative Strings.

I will add a Test to discover the TypeConverter and add a stopwatch test to the Timer test

I have made the other changes 

> Add time millis converter which can convert from String to long
> ---------------------------------------------------------------
>
>                 Key: CAMEL-2631
>                 URL: https://issues.apache.org/activemq/browse/CAMEL-2631
>             Project: Apache Camel
>          Issue Type: New Feature
>          Components: camel-core
>            Reporter: Claus Ibsen
>            Assignee: Ashwin Karpe
>            Priority: Minor
>         Attachments: time-pattern-converter-patch4.diff
>
>
> Its currently a bit annoying to set a delay by millis and if you need, like 1 hour 30 min period. What is this in millis?
> We should add a TypeConverter for that which has a String notation such as:
> {code}
> 1h30m
> 3h45m25s
> 10m
> 15m20s
> 30s
> {code}

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (CAMEL-2631) Add time millis converter which can convert from String to long

Posted by "Claus Ibsen (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/activemq/browse/CAMEL-2631?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=59132#action_59132 ] 

Claus Ibsen commented on CAMEL-2631:
------------------------------------

In the last fallback code why not test the {{foundFlag}} ?

{code}
if (!foundFlag) {
  // fallback to let Long convert it
  milliseconds = Long.valueOf(source).longValue();
}
{code}

And remember to add {{foundFlag=true}} in the {{SECONDS_REGEX_PATTERN}} part.

Otherwise +1

> Add time millis converter which can convert from String to long
> ---------------------------------------------------------------
>
>                 Key: CAMEL-2631
>                 URL: https://issues.apache.org/activemq/browse/CAMEL-2631
>             Project: Apache Camel
>          Issue Type: New Feature
>          Components: camel-core
>            Reporter: Claus Ibsen
>            Assignee: Ashwin Karpe
>            Priority: Minor
>         Attachments: time-pattern-converter-patch.diff
>
>
> Its currently a bit annoying to set a delay by millis and if you need, like 1 hour 30 min period. What is this in millis?
> We should add a TypeConverter for that which has a String notation such as:
> {code}
> 1h30m
> 3h45m25s
> 10m
> 15m20s
> 30s
> {code}

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (CAMEL-2631) Add time millis converter which can convert from String to long

Posted by "Ashwin Karpe (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/activemq/browse/CAMEL-2631?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=59035#action_59035 ] 

Ashwin Karpe commented on CAMEL-2631:
-------------------------------------

Hi Claus,

I got everything to work yesterday including the Timer component where the problem was that I had missed adding the @Conveter annotation at the method level.

In any case, I ran into a different issue.Camel's checkstyle sourcecheck did not like the Pattern without a ^ and $. I have to make some changes to the code to make it all go through without side-effects.

BTW, I also found another file component based test which fails sourcecheck. I did not look into it further but will do so at the earliest convenience following my fixes.

Cheers,

Ashwin... 

 

> Add time millis converter which can convert from String to long
> ---------------------------------------------------------------
>
>                 Key: CAMEL-2631
>                 URL: https://issues.apache.org/activemq/browse/CAMEL-2631
>             Project: Apache Camel
>          Issue Type: New Feature
>          Components: camel-core
>            Reporter: Claus Ibsen
>            Assignee: Ashwin Karpe
>            Priority: Minor
>         Attachments: time-pattern-converter-patch2.diff
>
>
> Its currently a bit annoying to set a delay by millis and if you need, like 1 hour 30 min period. What is this in millis?
> We should add a TypeConverter for that which has a String notation such as:
> {code}
> 1h30m
> 3h45m25s
> 10m
> 15m20s
> 30s
> {code}

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (CAMEL-2631) Add time millis converter which can convert from String to long

Posted by "Ashwin Karpe (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/activemq/browse/CAMEL-2631?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=59108#action_59108 ] 

Ashwin Karpe commented on CAMEL-2631:
-------------------------------------

Hi Claus,

Sorry about the earlier patch. I see that it was a rather hasty job. I will make all the changes, double-check everything and submit. 

Cheers,

Ashwin...


> Add time millis converter which can convert from String to long
> ---------------------------------------------------------------
>
>                 Key: CAMEL-2631
>                 URL: https://issues.apache.org/activemq/browse/CAMEL-2631
>             Project: Apache Camel
>          Issue Type: New Feature
>          Components: camel-core
>            Reporter: Claus Ibsen
>            Assignee: Ashwin Karpe
>            Priority: Minor
>         Attachments: time-pattern-converter-patch5.diff
>
>
> Its currently a bit annoying to set a delay by millis and if you need, like 1 hour 30 min period. What is this in millis?
> We should add a TypeConverter for that which has a String notation such as:
> {code}
> 1h30m
> 3h45m25s
> 10m
> 15m20s
> 30s
> {code}

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Updated: (CAMEL-2631) Add time millis converter which can convert from String to long

Posted by "Ashwin Karpe (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/activemq/browse/CAMEL-2631?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Ashwin Karpe updated CAMEL-2631:
--------------------------------

    Attachment:     (was: time-pattern-converter-patch.diff)

> Add time millis converter which can convert from String to long
> ---------------------------------------------------------------
>
>                 Key: CAMEL-2631
>                 URL: https://issues.apache.org/activemq/browse/CAMEL-2631
>             Project: Apache Camel
>          Issue Type: New Feature
>          Components: camel-core
>            Reporter: Claus Ibsen
>            Assignee: Ashwin Karpe
>            Priority: Minor
>         Attachments: time-pattern-converter-patch.diff
>
>
> Its currently a bit annoying to set a delay by millis and if you need, like 1 hour 30 min period. What is this in millis?
> We should add a TypeConverter for that which has a String notation such as:
> {code}
> 1h30m
> 3h45m25s
> 10m
> 15m20s
> 30s
> {code}

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (CAMEL-2631) Add time millis converter which can convert from String to long

Posted by "Claus Ibsen (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/activemq/browse/CAMEL-2631?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=59114#action_59114 ] 

Claus Ibsen commented on CAMEL-2631:
------------------------------------

Ashwin

Much better. Only one left.

{code}
 try {
+            long milliseconds = TimePatternConverter.toMilliSeconds(source);
+        } catch (IllegalArgumentException e) {
+            LOG.debug("Following exception thrown: " + e.getMessage());
+            assertIsInstanceOf(IllegalArgumentException.class, e);
+        }
{code}

Here you need to add a fail check if the exception was NOT thrown
{code}
 try {
+            long milliseconds = TimePatternConverter.toMilliSeconds(source);
              fail("Should throw exception");
+        } catch (IllegalArgumentException e) {
+            LOG.debug("Following exception thrown: " + e.getMessage());
+            assertIsInstanceOf(IllegalArgumentException.class, e);
+        }

And you catch an IllegalArgumentException which you then assert is the same instance :) You would often just have used
{code}
catch(Exception e)
         assertIsInstanceOf(IllegalArgumentException.class, e);
    assertEquals"The bla bla should have", e.getMessage());
{code}
And also check the error message is correct


And we should documented in the source code of the converter that it will *also* be used for regular numbers. i.e. its a String -> long converter which does that for all Strings.
The only problem which could occur is that *none* pattern matched, then you would return 0. I think we should add a fallback to let it use the following code
{code}
   // no pattern matched so fallback and let Long convert it
            return Long.valueOf(value);
{code}

> Add time millis converter which can convert from String to long
> ---------------------------------------------------------------
>
>                 Key: CAMEL-2631
>                 URL: https://issues.apache.org/activemq/browse/CAMEL-2631
>             Project: Apache Camel
>          Issue Type: New Feature
>          Components: camel-core
>            Reporter: Claus Ibsen
>            Assignee: Ashwin Karpe
>            Priority: Minor
>         Attachments: time-pattern-converter-patch.diff
>
>
> Its currently a bit annoying to set a delay by millis and if you need, like 1 hour 30 min period. What is this in millis?
> We should add a TypeConverter for that which has a String notation such as:
> {code}
> 1h30m
> 3h45m25s
> 10m
> 15m20s
> 30s
> {code}

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Updated: (CAMEL-2631) Add time millis converter which can convert from String to long

Posted by "Ashwin Karpe (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/activemq/browse/CAMEL-2631?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Ashwin Karpe updated CAMEL-2631:
--------------------------------

    Attachment:     (was: time-pattern-converter-patch3.diff)

> Add time millis converter which can convert from String to long
> ---------------------------------------------------------------
>
>                 Key: CAMEL-2631
>                 URL: https://issues.apache.org/activemq/browse/CAMEL-2631
>             Project: Apache Camel
>          Issue Type: New Feature
>          Components: camel-core
>            Reporter: Claus Ibsen
>            Assignee: Ashwin Karpe
>            Priority: Minor
>         Attachments: time-pattern-converter-patch4.diff
>
>
> Its currently a bit annoying to set a delay by millis and if you need, like 1 hour 30 min period. What is this in millis?
> We should add a TypeConverter for that which has a String notation such as:
> {code}
> 1h30m
> 3h45m25s
> 10m
> 15m20s
> 30s
> {code}

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Assigned: (CAMEL-2631) Add time millis converter which can convert from String to long

Posted by "Ashwin Karpe (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/activemq/browse/CAMEL-2631?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Ashwin Karpe reassigned CAMEL-2631:
-----------------------------------

    Assignee: Ashwin Karpe

> Add time millis converter which can convert from String to long
> ---------------------------------------------------------------
>
>                 Key: CAMEL-2631
>                 URL: https://issues.apache.org/activemq/browse/CAMEL-2631
>             Project: Apache Camel
>          Issue Type: New Feature
>          Components: camel-core
>            Reporter: Claus Ibsen
>            Assignee: Ashwin Karpe
>            Priority: Minor
>
> Its currently a bit annoying to set a delay by millis and if you need, like 1 hour 30 min period. What is this in millis?
> We should add a TypeConverter for that which has a String notation such as:
> {code}
> 1h30m
> 3h45m25s
> 10m
> 15m20s
> 30s
> {code}

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: https://issues.apache.org/activemq/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] Updated: (CAMEL-2631) Add time millis converter which can convert from String to long

Posted by "Ashwin Karpe (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/activemq/browse/CAMEL-2631?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Ashwin Karpe updated CAMEL-2631:
--------------------------------

    Attachment: time-pattern-converter-patch2.diff

Hi Claus,

I have updated the patch with the changes you suggested. Please let me know if you think I can go ahead and commit the change.

Cheers,

Ashwin...

> Add time millis converter which can convert from String to long
> ---------------------------------------------------------------
>
>                 Key: CAMEL-2631
>                 URL: https://issues.apache.org/activemq/browse/CAMEL-2631
>             Project: Apache Camel
>          Issue Type: New Feature
>          Components: camel-core
>            Reporter: Claus Ibsen
>            Assignee: Ashwin Karpe
>            Priority: Minor
>         Attachments: time-pattern-converter-patch2.diff
>
>
> Its currently a bit annoying to set a delay by millis and if you need, like 1 hour 30 min period. What is this in millis?
> We should add a TypeConverter for that which has a String notation such as:
> {code}
> 1h30m
> 3h45m25s
> 10m
> 15m20s
> 30s
> {code}

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Issue Comment Edited: (CAMEL-2631) Add time millis converter which can convert from String to long

Posted by "Ashwin Karpe (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/activemq/browse/CAMEL-2631?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=59137#action_59137 ] 

Ashwin Karpe edited comment on CAMEL-2631 at 4/27/10 4:06 PM:
--------------------------------------------------------------

The final changes have been made. I have used the foundFlag as the basis for the fallback conversion. I have tested and source-checked the code and believe it to be ready for commit. I will do so shortly.

Cheers,

Ashwin...

      was (Author: akarpe):
    The final changes have been made. I have tested and source-checked the code and believe it to be ready for commit. I will do so shortly.

Cheers,

Ashwin...
  
> Add time millis converter which can convert from String to long
> ---------------------------------------------------------------
>
>                 Key: CAMEL-2631
>                 URL: https://issues.apache.org/activemq/browse/CAMEL-2631
>             Project: Apache Camel
>          Issue Type: New Feature
>          Components: camel-core
>            Reporter: Claus Ibsen
>            Assignee: Ashwin Karpe
>            Priority: Minor
>         Attachments: time-pattern-converter-patch.diff
>
>
> Its currently a bit annoying to set a delay by millis and if you need, like 1 hour 30 min period. What is this in millis?
> We should add a TypeConverter for that which has a String notation such as:
> {code}
> 1h30m
> 3h45m25s
> 10m
> 15m20s
> 30s
> {code}

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Updated: (CAMEL-2631) Add time millis converter which can convert from String to long

Posted by "Ashwin Karpe (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/activemq/browse/CAMEL-2631?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Ashwin Karpe updated CAMEL-2631:
--------------------------------

    Attachment: time-pattern-converter-patch.diff

Hi Claus,

I have made the tweaks you suggested. Please let me know if everything is in order and whether I can go ahead and commit.

Cheers,

Ashwin..

> Add time millis converter which can convert from String to long
> ---------------------------------------------------------------
>
>                 Key: CAMEL-2631
>                 URL: https://issues.apache.org/activemq/browse/CAMEL-2631
>             Project: Apache Camel
>          Issue Type: New Feature
>          Components: camel-core
>            Reporter: Claus Ibsen
>            Assignee: Ashwin Karpe
>            Priority: Minor
>         Attachments: time-pattern-converter-patch.diff
>
>
> Its currently a bit annoying to set a delay by millis and if you need, like 1 hour 30 min period. What is this in millis?
> We should add a TypeConverter for that which has a String notation such as:
> {code}
> 1h30m
> 3h45m25s
> 10m
> 15m20s
> 30s
> {code}

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (CAMEL-2631) Add time millis converter which can convert from String to long

Posted by "Ashwin Karpe (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/activemq/browse/CAMEL-2631?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=59009#action_59009 ] 

Ashwin Karpe commented on CAMEL-2631:
-------------------------------------

Claus,

I am not sure if you want me to do anything with bullet 3 based on your final comment.

I will fix the remaining changes. In my earlier patch I had the log level set to trace but during testing I changed it to info which I missed reverting back :(. 

Cheers,

Ashwin...



.

> Add time millis converter which can convert from String to long
> ---------------------------------------------------------------
>
>                 Key: CAMEL-2631
>                 URL: https://issues.apache.org/activemq/browse/CAMEL-2631
>             Project: Apache Camel
>          Issue Type: New Feature
>          Components: camel-core
>            Reporter: Claus Ibsen
>            Assignee: Ashwin Karpe
>            Priority: Minor
>         Attachments: time-pattern-converter-patch2.diff
>
>
> Its currently a bit annoying to set a delay by millis and if you need, like 1 hour 30 min period. What is this in millis?
> We should add a TypeConverter for that which has a String notation such as:
> {code}
> 1h30m
> 3h45m25s
> 10m
> 15m20s
> 30s
> {code}

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Updated: (CAMEL-2631) Add time millis converter which can convert from String to long

Posted by "Ashwin Karpe (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/activemq/browse/CAMEL-2631?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Ashwin Karpe updated CAMEL-2631:
--------------------------------

    Attachment:     (was: time-pattern-converter-patch.diff)

> Add time millis converter which can convert from String to long
> ---------------------------------------------------------------
>
>                 Key: CAMEL-2631
>                 URL: https://issues.apache.org/activemq/browse/CAMEL-2631
>             Project: Apache Camel
>          Issue Type: New Feature
>          Components: camel-core
>            Reporter: Claus Ibsen
>            Assignee: Ashwin Karpe
>            Priority: Minor
>         Attachments: time-pattern-converter-patch.diff
>
>
> Its currently a bit annoying to set a delay by millis and if you need, like 1 hour 30 min period. What is this in millis?
> We should add a TypeConverter for that which has a String notation such as:
> {code}
> 1h30m
> 3h45m25s
> 10m
> 15m20s
> 30s
> {code}

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Updated: (CAMEL-2631) Add time millis converter which can convert from String to long

Posted by "Ashwin Karpe (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/activemq/browse/CAMEL-2631?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Ashwin Karpe updated CAMEL-2631:
--------------------------------

    Attachment: time-pattern-converter-patch4.diff

Claus,

I decided to normalize the payload first to a standard pattern and then apply the match finder. I like this version of the code much better than what I had earlier.

I have verified that all the tests work and it is sourcecheck safe. Could you please review and let me know. 

Cheers,

Ashwin...

> Add time millis converter which can convert from String to long
> ---------------------------------------------------------------
>
>                 Key: CAMEL-2631
>                 URL: https://issues.apache.org/activemq/browse/CAMEL-2631
>             Project: Apache Camel
>          Issue Type: New Feature
>          Components: camel-core
>            Reporter: Claus Ibsen
>            Assignee: Ashwin Karpe
>            Priority: Minor
>         Attachments: time-pattern-converter-patch4.diff
>
>
> Its currently a bit annoying to set a delay by millis and if you need, like 1 hour 30 min period. What is this in millis?
> We should add a TypeConverter for that which has a String notation such as:
> {code}
> 1h30m
> 3h45m25s
> 10m
> 15m20s
> 30s
> {code}

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Issue Comment Edited: (CAMEL-2631) Add time millis converter which can convert from String to long

Posted by "Claus Ibsen (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/activemq/browse/CAMEL-2631?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=59106#action_59106 ] 

Claus Ibsen edited comment on CAMEL-2631 at 4/26/10 1:47 PM:
-------------------------------------------------------------

And you can use fail in junit test in try .. catch to ensure an exception was thrown.
This is better than the boolean stuff you do.

And it would also be nice if you assert the message from IllegalArgumentException is what you expected.

{code}
try 
   // do some code here
  fail("Should have thrown exception);
} catch (Excpetion e) {
 // you can use assertIsInstanceOf to assert and type cast to an expected type
}
{code}

      was (Author: davsclaus):
    And you can use fail in junit test in try .. catch to ensure an exception was thrown.
This is better than the boolean stuff you do.

And it would also be nice if you assert the message from IllegalArgumentException is what you expected.

{code}
try 
   // do some code here
  fail("Should have thrown exception);
} catch (Excpetion e) {
 // you can use assertIsInstanceOf to assert and type cast to an expected type
}
  
> Add time millis converter which can convert from String to long
> ---------------------------------------------------------------
>
>                 Key: CAMEL-2631
>                 URL: https://issues.apache.org/activemq/browse/CAMEL-2631
>             Project: Apache Camel
>          Issue Type: New Feature
>          Components: camel-core
>            Reporter: Claus Ibsen
>            Assignee: Ashwin Karpe
>            Priority: Minor
>         Attachments: time-pattern-converter-patch5.diff
>
>
> Its currently a bit annoying to set a delay by millis and if you need, like 1 hour 30 min period. What is this in millis?
> We should add a TypeConverter for that which has a String notation such as:
> {code}
> 1h30m
> 3h45m25s
> 10m
> 15m20s
> 30s
> {code}

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (CAMEL-2631) Add time millis converter which can convert from String to long

Posted by "Claus Ibsen (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/activemq/browse/CAMEL-2631?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=59048#action_59048 ] 

Claus Ibsen commented on CAMEL-2631:
------------------------------------

5 more things

1)
Add a test where you pass in "149" to see if you get the long value of 149 in return.
Also test for a negative value such as "-72" to see if you get -72 long value

We must make sure that the type converter does not have a side effect of regular String -> long with plain numbers get returned as 0.

2)
Add tests where you let Camel use its type converter discover
etc something like this.

{code}
long val = context.getTypeConverter().convertTo(long.class, "149");

long val = context.getTypeConverter().convertTo(long.class, "5min");
{code}

3)
In the Timer test use the StopWatch to test that it takes that long to run, eg about 10 seconds.

4)
Check the links from Hadrian, we can use case insensitive mode on the reg exp so people can spell it HOUR etc and still have it converted.

5)
You do not need to reset the matcher, when you actually create a new instance of it for the next test. So its just a waste of code :)

> Add time millis converter which can convert from String to long
> ---------------------------------------------------------------
>
>                 Key: CAMEL-2631
>                 URL: https://issues.apache.org/activemq/browse/CAMEL-2631
>             Project: Apache Camel
>          Issue Type: New Feature
>          Components: camel-core
>            Reporter: Claus Ibsen
>            Assignee: Ashwin Karpe
>            Priority: Minor
>         Attachments: time-pattern-converter-patch4.diff
>
>
> Its currently a bit annoying to set a delay by millis and if you need, like 1 hour 30 min period. What is this in millis?
> We should add a TypeConverter for that which has a String notation such as:
> {code}
> 1h30m
> 3h45m25s
> 10m
> 15m20s
> 30s
> {code}

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (CAMEL-2631) Add time millis converter which can convert from String to long

Posted by "Ashwin Karpe (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/activemq/browse/CAMEL-2631?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=58973#action_58973 ] 

Ashwin Karpe commented on CAMEL-2631:
-------------------------------------

No problem. I will make the changes and submit a fresh patch.

Cheers,

Ashwin...

> Add time millis converter which can convert from String to long
> ---------------------------------------------------------------
>
>                 Key: CAMEL-2631
>                 URL: https://issues.apache.org/activemq/browse/CAMEL-2631
>             Project: Apache Camel
>          Issue Type: New Feature
>          Components: camel-core
>            Reporter: Claus Ibsen
>            Assignee: Ashwin Karpe
>            Priority: Minor
>         Attachments: time-pattern-converter-patch.diff
>
>
> Its currently a bit annoying to set a delay by millis and if you need, like 1 hour 30 min period. What is this in millis?
> We should add a TypeConverter for that which has a String notation such as:
> {code}
> 1h30m
> 3h45m25s
> 10m
> 15m20s
> 30s
> {code}

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Updated: (CAMEL-2631) Add time millis converter which can convert from String to long

Posted by "Ashwin Karpe (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/activemq/browse/CAMEL-2631?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Ashwin Karpe updated CAMEL-2631:
--------------------------------

    Attachment:     (was: time-pattern-converter-patch4.diff)

> Add time millis converter which can convert from String to long
> ---------------------------------------------------------------
>
>                 Key: CAMEL-2631
>                 URL: https://issues.apache.org/activemq/browse/CAMEL-2631
>             Project: Apache Camel
>          Issue Type: New Feature
>          Components: camel-core
>            Reporter: Claus Ibsen
>            Assignee: Ashwin Karpe
>            Priority: Minor
>         Attachments: time-pattern-converter-patch5.diff
>
>
> Its currently a bit annoying to set a delay by millis and if you need, like 1 hour 30 min period. What is this in millis?
> We should add a TypeConverter for that which has a String notation such as:
> {code}
> 1h30m
> 3h45m25s
> 10m
> 15m20s
> 30s
> {code}

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (CAMEL-2631) Add time millis converter which can convert from String to long

Posted by "Claus Ibsen (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/activemq/browse/CAMEL-2631?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=59033#action_59033 ] 

Claus Ibsen commented on CAMEL-2631:
------------------------------------

Hiram told me in AMQ they got a couple of PropertyEditors which can convert for you

[13:49]  <chirino> https://svn.apache.org/repos/asf/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/util/MemoryIntPropertyEditor.java
[13:49]  <chirino> and https://svn.apache.org/repos/asf/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/util/MemoryPropertyEditor.java

We may use them as well.

There is a PropertyEditorTypeConverter in Camel which looks through all the registered property editors.
So it should in theory just be to install those 2 from AMQ

> Add time millis converter which can convert from String to long
> ---------------------------------------------------------------
>
>                 Key: CAMEL-2631
>                 URL: https://issues.apache.org/activemq/browse/CAMEL-2631
>             Project: Apache Camel
>          Issue Type: New Feature
>          Components: camel-core
>            Reporter: Claus Ibsen
>            Assignee: Ashwin Karpe
>            Priority: Minor
>         Attachments: time-pattern-converter-patch2.diff
>
>
> Its currently a bit annoying to set a delay by millis and if you need, like 1 hour 30 min period. What is this in millis?
> We should add a TypeConverter for that which has a String notation such as:
> {code}
> 1h30m
> 3h45m25s
> 10m
> 15m20s
> 30s
> {code}

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Updated: (CAMEL-2631) Add time millis converter which can convert from String to long

Posted by "Ashwin Karpe (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/activemq/browse/CAMEL-2631?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Ashwin Karpe updated CAMEL-2631:
--------------------------------

    Attachment: time-pattern-converter-patch3.diff

Hi Claus,

I have made the changes you suggested (TraceEnabled() etc) . I found out that I cannot apply the [h|H|hour|Hour|hours|hours] rule since Regex pattern matches are of the eager variety and cause side-effects (each character to be independently evaluated like 'h''o''u''r''s').

In any case all of the patterns you need supported work with the pattern set I have created. I have also added a Timer based test as you recommended with a timer period set to 5s. This can be anything in the supported TimerPatternConverter.

Please let me know whether there is anything else you need before I commit the feature.  

Cheers,

Ashwin...

> Add time millis converter which can convert from String to long
> ---------------------------------------------------------------
>
>                 Key: CAMEL-2631
>                 URL: https://issues.apache.org/activemq/browse/CAMEL-2631
>             Project: Apache Camel
>          Issue Type: New Feature
>          Components: camel-core
>            Reporter: Claus Ibsen
>            Assignee: Ashwin Karpe
>            Priority: Minor
>         Attachments: time-pattern-converter-patch3.diff
>
>
> Its currently a bit annoying to set a delay by millis and if you need, like 1 hour 30 min period. What is this in millis?
> We should add a TypeConverter for that which has a String notation such as:
> {code}
> 1h30m
> 3h45m25s
> 10m
> 15m20s
> 30s
> {code}

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Updated: (CAMEL-2631) Add time millis converter which can convert from String to long

Posted by "Ashwin Karpe (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/activemq/browse/CAMEL-2631?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Ashwin Karpe updated CAMEL-2631:
--------------------------------

    Attachment: time-pattern-converter-patch.diff

Hi Claus,

Could you please check this out. I have made all the changes you are looking for and it should be in much better shape. 

Sorry about the couple of small slip-up in my earlier patch. I have also added the tests to check for no side-effects and fixed negative tests to use assertIsInstanceOf()... 

Cheers,

Ashwin...

> Add time millis converter which can convert from String to long
> ---------------------------------------------------------------
>
>                 Key: CAMEL-2631
>                 URL: https://issues.apache.org/activemq/browse/CAMEL-2631
>             Project: Apache Camel
>          Issue Type: New Feature
>          Components: camel-core
>            Reporter: Claus Ibsen
>            Assignee: Ashwin Karpe
>            Priority: Minor
>         Attachments: time-pattern-converter-patch.diff
>
>
> Its currently a bit annoying to set a delay by millis and if you need, like 1 hour 30 min period. What is this in millis?
> We should add a TypeConverter for that which has a String notation such as:
> {code}
> 1h30m
> 3h45m25s
> 10m
> 15m20s
> 30s
> {code}

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (CAMEL-2631) Add time millis converter which can convert from String to long

Posted by "Claus Ibsen (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/activemq/browse/CAMEL-2631?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=59106#action_59106 ] 

Claus Ibsen commented on CAMEL-2631:
------------------------------------

And you can use fail in junit test in try .. catch to ensure an exception was thrown.
This is better than the boolean stuff you do.

And it would also be nice if you assert the message from IllegalArgumentException is what you expected.

{code}
try 
   // do some code here
  fail("Should have thrown exception);
} catch (Excpetion e) {
 // you can use assertIsInstanceOf to assert and type cast to an expected type
}

> Add time millis converter which can convert from String to long
> ---------------------------------------------------------------
>
>                 Key: CAMEL-2631
>                 URL: https://issues.apache.org/activemq/browse/CAMEL-2631
>             Project: Apache Camel
>          Issue Type: New Feature
>          Components: camel-core
>            Reporter: Claus Ibsen
>            Assignee: Ashwin Karpe
>            Priority: Minor
>         Attachments: time-pattern-converter-patch5.diff
>
>
> Its currently a bit annoying to set a delay by millis and if you need, like 1 hour 30 min period. What is this in millis?
> We should add a TypeConverter for that which has a String notation such as:
> {code}
> 1h30m
> 3h45m25s
> 10m
> 15m20s
> 30s
> {code}

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Updated: (CAMEL-2631) Add time millis converter which can convert from String to long

Posted by "Ashwin Karpe (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/activemq/browse/CAMEL-2631?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Ashwin Karpe updated CAMEL-2631:
--------------------------------

    Attachment:     (was: time-pattern-converter-patch5.diff)

> Add time millis converter which can convert from String to long
> ---------------------------------------------------------------
>
>                 Key: CAMEL-2631
>                 URL: https://issues.apache.org/activemq/browse/CAMEL-2631
>             Project: Apache Camel
>          Issue Type: New Feature
>          Components: camel-core
>            Reporter: Claus Ibsen
>            Assignee: Ashwin Karpe
>            Priority: Minor
>         Attachments: time-pattern-converter-patch.diff
>
>
> Its currently a bit annoying to set a delay by millis and if you need, like 1 hour 30 min period. What is this in millis?
> We should add a TypeConverter for that which has a String notation such as:
> {code}
> 1h30m
> 3h45m25s
> 10m
> 15m20s
> 30s
> {code}

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Work started: (CAMEL-2631) Add time millis converter which can convert from String to long

Posted by "Ashwin Karpe (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/activemq/browse/CAMEL-2631?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Work on CAMEL-2631 started by Ashwin Karpe.

> Add time millis converter which can convert from String to long
> ---------------------------------------------------------------
>
>                 Key: CAMEL-2631
>                 URL: https://issues.apache.org/activemq/browse/CAMEL-2631
>             Project: Apache Camel
>          Issue Type: New Feature
>          Components: camel-core
>            Reporter: Claus Ibsen
>            Assignee: Ashwin Karpe
>            Priority: Minor
>
> Its currently a bit annoying to set a delay by millis and if you need, like 1 hour 30 min period. What is this in millis?
> We should add a TypeConverter for that which has a String notation such as:
> {code}
> 1h30m
> 3h45m25s
> 10m
> 15m20s
> 30s
> {code}

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: https://issues.apache.org/activemq/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] Commented: (CAMEL-2631) Add time millis converter which can convert from String to long

Posted by "Claus Ibsen (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/activemq/browse/CAMEL-2631?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=58994#action_58994 ] 

Claus Ibsen commented on CAMEL-2631:
------------------------------------

1) Do not use {{new String}} but just {{" xxx"}}

2)
Do not log INFO but do that as TRACE since the type converters can be invoked a lot.
And use ifTraceEnabled.

3)
I think the return type should be {{Long}} and if the String input does *not* match any patterns, then you should return {{Void.TYPE}} to indicate you cannot convert this.
Then Camel will let other type converters try, which for example can be a String -> Long which can convert "444" to 444 as long value.

4)
Add unit test for bullet #3. Eg to have Camel convert at regular number to a Long.
And then afterwards have Camel convert "5m2s" to Long to see that it uses your new type converter
And then try a regular "444" to 444 afterwards to ensure it still works

5)
And could you add an unit test with the timer component that has a {{period}} option in the URI using your new syntax, eg {{period=2s}} to indicate 2 seconds.


> Add time millis converter which can convert from String to long
> ---------------------------------------------------------------
>
>                 Key: CAMEL-2631
>                 URL: https://issues.apache.org/activemq/browse/CAMEL-2631
>             Project: Apache Camel
>          Issue Type: New Feature
>          Components: camel-core
>            Reporter: Claus Ibsen
>            Assignee: Ashwin Karpe
>            Priority: Minor
>         Attachments: time-pattern-converter-patch2.diff
>
>
> Its currently a bit annoying to set a delay by millis and if you need, like 1 hour 30 min period. What is this in millis?
> We should add a TypeConverter for that which has a String notation such as:
> {code}
> 1h30m
> 3h45m25s
> 10m
> 15m20s
> 30s
> {code}

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (CAMEL-2631) Add time millis converter which can convert from String to long

Posted by "Claus Ibsen (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/activemq/browse/CAMEL-2631?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=58964#action_58964 ] 

Claus Ibsen commented on CAMEL-2631:
------------------------------------

I wonder if it makes sense to force minutes and seconds to be 0..59?

What if you want to say 520 seconds? Having to do that as: 8m40s is not easy to figure out.
Its not a 24h clock you are setting.

But yeah it maybe makes sense to validate it if you have multiple units, eg H and M
2h5m is valid, where as 2h98m is not.

So maybe if we have this rule
- if only 1 unit, then there is no limitations, eg you can say 520s for 520 seconds, or 99m for 99 minutes
- if 2+ units then minutes and seconds should be 0..59

In terms of the code
1) Do not use new String
2) Throw IllegalArgumentException as its the most appropriate exception to thrown when invalid input.



> Add time millis converter which can convert from String to long
> ---------------------------------------------------------------
>
>                 Key: CAMEL-2631
>                 URL: https://issues.apache.org/activemq/browse/CAMEL-2631
>             Project: Apache Camel
>          Issue Type: New Feature
>          Components: camel-core
>            Reporter: Claus Ibsen
>            Assignee: Ashwin Karpe
>            Priority: Minor
>         Attachments: time-pattern-converter-patch.diff
>
>
> Its currently a bit annoying to set a delay by millis and if you need, like 1 hour 30 min period. What is this in millis?
> We should add a TypeConverter for that which has a String notation such as:
> {code}
> 1h30m
> 3h45m25s
> 10m
> 15m20s
> 30s
> {code}

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.