Maikel Linke created SCXML-167:
----------------------------------

             Summary: SimpleScheduler removes wrong Timer
                 Key: SCXML-167
                 URL: https://issues.apache.org/jira/browse/SCXML-167
             Project: Commons SCXML
          Issue Type: Bug
    Affects Versions: 0.9, 0.8, 0.7, 0.6, 0.5
         Environment: supersteps activated
            Reporter: Maikel Linke


The SimpleScheduler provides the execution of delayed events. Therefore it uses 
Timers, stored in a map under the senderid. The Timers start DelayedEventTasks. 
These tasks trigger the given event and then remove their Timer identified by 
the senderid. In the case that triggering the event processes a new <send> with 
the same senderid, the task will remove the wrong (new) Timer from the internal 
map. This new Timer is unreachable for canceling now. Of course, the senderid 
should be unique, but cannot be assigned by an expression and the following 
example fails:

    <state id="Timer">
        <onentry>
            <send event="'tick'" sendid="sendtick" delay="'1s'"/>
        </onentry>
        <transition event="tick" target="Timer"/>
        <transition event="stop" target="NoTimer"/>
        <onexit>
            <cancel sendid="sendtick"/>
        </onexit>
    </state>

The solution is very simple: just remove the Timer from the Map first and then 
trigger the event.

So this code:
        public void run() {
            try {
                executor.triggerEvent(new TriggerEvent(event,
                    TriggerEvent.SIGNAL_EVENT, payload));
            } catch (ModelException me) {
                log.error(me.getMessage(), me);
            }
            timers.remove(sendId);
            if (log.isDebugEnabled()) {
                log.debug("Fired event '" + event + "' as scheduled by "
                    + "<send> with id '" + sendId + "'");
            }
        }

Changes to:

        public void run() {
            timers.remove(sendId);
            try {
                executor.triggerEvent(new TriggerEvent(event,
                    TriggerEvent.SIGNAL_EVENT, payload));
            } catch (ModelException me) {
                log.error(me.getMessage(), me);
            }
            if (log.isDebugEnabled()) {
                log.debug("Fired event '" + event + "' as scheduled by "
                    + "<send> with id '" + sendId + "'");
            }
        }

It should not brake any logic applied to the internal private Map timers.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: 
https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

Reply via email to