Commons SCXML
  1. Commons SCXML
  2. SCXML-73

Propose to evaluate delay expression in Send action before parsing

    Details

    • Type: Wish Wish
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 0.5, 0.6, 0.7, 0.8
    • Fix Version/s: 0.9
    • Labels:
      None

      Description

      I am using the Send action to schedule a future event. The current implementation for Send requires me to express delay either as a number or a string defined in CSS2 format. My delay can be as long as 1 month, which works out to:
      2678400s for Jan, Mar, May, Jul, Aug, Oct, Dec
      2592000s for Apr, Jun, Sep, Nov
      2419200s for Feb (non-leap years)

      A straightforward way for me to calculate the number of seconds for the current month is to tap on Java's calendar classes, so I created a helper object to perform that calculation and tried calling my object in the delay expression, i.e.
      <send event="charge" delay="time.ms(0,1,0,0,0,0)"/>

      But this doesn't work. I get the following error message:
      ERROR [log] For input string: "delay" java.lang.NumberFormatException: For input string: "time.ms(0,1,0,0,0,0)"

      Looking at the code for Send, I realize that the delay expression does not get evaluated by the evaluator, unlike the other attributes. I did a little experiment and modified the Send.execute method to evaluate the delay expression before parsing. ie.
      In execute(), I added:
      String delayString = (String) eval.eval(ctx, delay);
      long wait = parseDelay(delayString, appLog);

      I then modified parseDelay() to parse delayString instead of delay, i.e.
      private long parseDelay(final String delayString, final Log appLog) throws SCXMLExpressionException {
      long wait = 0L;
      long multiplier = 1L;
      if (!SCXMLHelper.isStringEmpty(delayString)) {
      String trimDelay = delayString.trim();
      String numericDelay = trimDelay;
      ....

      With these modifications, the above delay expression worked. Although this is a minor tweak, it is very useful for delay expressions that go beyond a couple of seconds or change under different scenarios.

      Can this feature be included in the next release for SCXML?

      Elaine

        Activity

        Transition Time In Source Status Execution Times Last Executer Last Execution Date
        Open Open Resolved Resolved
        16h 13m 1 Rahul Akolkar 17/Jun/08 23:09
        Resolved Resolved Closed Closed
        168d 22h 16m 1 Rahul Akolkar 03/Dec/08 20:26
        Rahul Akolkar made changes -
        Status Resolved [ 5 ] Closed [ 6 ]
        Hide
        Rahul Akolkar added a comment -

        Closing since 0.9 is released.

        Show
        Rahul Akolkar added a comment - Closing since 0.9 is released.
        Hide
        Elaine Wong added a comment -

        Hi Rahul,

        Thanks. I'll update my code from the repository.

        And you're welcome - SCXML is a neat effort.

        Elaine

        Show
        Elaine Wong added a comment - Hi Rahul, Thanks. I'll update my code from the repository. And you're welcome - SCXML is a neat effort. Elaine
        Rahul Akolkar made changes -
        Status Open [ 1 ] Resolved [ 5 ]
        Resolution Fixed [ 1 ]
        Hide
        Rahul Akolkar added a comment -

        I've applied a similar patch for this to trunk in r668848 and added you to the contributors list:

        http://svn.apache.org/viewvc?view=rev&revision=668848

        This will be included in the next release (v0.9), but there is no schedule for the next release yet. Until then, you can try building from SVN trunk.

        Thanks for the report.

        Show
        Rahul Akolkar added a comment - I've applied a similar patch for this to trunk in r668848 and added you to the contributors list: http://svn.apache.org/viewvc?view=rev&revision=668848 This will be included in the next release (v0.9), but there is no schedule for the next release yet. Until then, you can try building from SVN trunk. Thanks for the report.
        Rahul Akolkar made changes -
        Fix Version/s 0.7 [ 12312252 ]
        Fix Version/s 0.6 [ 12312019 ]
        Fix Version/s 0.5 [ 12312006 ]
        Rahul Akolkar made changes -
        Remaining Estimate 0.25h [ 900 ]
        Original Estimate 0.25h [ 900 ]
        Fix Version/s 1.0 [ 12312033 ]
        Affects Version/s 1.0 [ 12312033 ]
        Hide
        Rahul Akolkar added a comment -

        Indeed, the delay attribute is a value expression. I've set fix version to 0.9 (the next release). I'll get back to fixing this in a day or two. Thanks.

        Show
        Rahul Akolkar added a comment - Indeed, the delay attribute is a value expression. I've set fix version to 0.9 (the next release). I'll get back to fixing this in a day or two. Thanks.
        Rahul Akolkar made changes -
        Field Original Value New Value
        Fix Version/s 0.8 [ 12312883 ]
        Fix Version/s 0.9 [ 12313270 ]
        Elaine Wong created issue -

          People

          • Assignee:
            Unassigned
            Reporter:
            Elaine Wong
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development