You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by Daniel Schwager <Da...@dtnet.de> on 2008/07/11 18:25:35 UTC

[SCXML] scxml-listener will not process in a defined order (problem: SCXMLExecutor.addListener based on Set)

Hi Rahul,

i'm running in a problem: i add two listeners to my SCXMLExecutor instance
	- the first one should run some business-methods using reflection (like you do in your watchclock-example)
	- the second one should check the current state and maybe trigger some other fsm's 

The order of execution of the listeners is important, because 
 - FIRST I want to process the business-methods  and
 - SECOND I want to inform other compontents of reaching+processing of business-methods is done

Your implementation of remember the listeners based on java.util.Set - the order in a 
Set is not defined (because it's not an ordered element) - so, regardless of the sequence
Of adding my two listeners, your code executes the listeners in the wrong order (-:

Did I miss something or is this a feature request ?

Regards
Danny



SCXMLExecutor: 
   public void addListener(final SCXML scxml, final SCXMLListener listener) {
        Object observable = scxml;
        scInstance.getNotificationRegistry().addListener(observable, listener);
    }


NotificationRegistry
   private synchronized void fireOnEntry(final Object source,
            final TransitionTarget state) {

// ***** SET !!! not a Vector ..
        Set entries = (Set) regs.get(source);							
// ***** SET !!! not a Vector ..

        if (entries != null) {
            for (Iterator iter = entries.iterator(); iter.hasNext();) {
                SCXMLListener lst = (SCXMLListener) iter.next();
                lst.onEntry(state);
            }
        }
    }

Viele Gruesse

Daniel Schwager

-------------------------------------------------------------------
DT Netsolution GmbH   -   Taläckerstr. 30    -    D-70437 Stuttgart
Geschäftsführer: Daniel Schwager, Stefan Hörz - HRB Stuttgart 19870
Tel: +49-711-849910-32, Fax: -932 - Mailto:daniel.schwager@dtnet.de


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org


Re: [SCXML] scxml-listener will not process in a defined order (problem: SCXMLExecutor.addListener based on Set)

Posted by Rahul Akolkar <ra...@gmail.com>.
On Thu, Jul 17, 2008 at 4:46 PM, Daniel Schwager
<Da...@dtnet.de> wrote:
>> -----Ursprüngliche Nachricht-----
>> Von: Rahul Akolkar [mailto:rahul.akolkar@gmail.com]
>
>
>> However, in terms of implementation, its good to have predictable
>> order. So while I still wouldn't recommend listeners that depend on
>> order (earlier ones could have failed, its not a pipeline or a chain,
>> various issues), lets make things predictable.
>>
>> Please open an improvement request in JIRA (and you can attach a patch
>> [1] if you'd like, its probably not more than a line or two close to
>
> Here we are - with an attached (working) patch for this.
>
> https://issues.apache.org/jira/browse/SCXML-78
>
<snip/>

Great, I'll look at it early next week.

-Rahul


> regards
> Danny
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org


AW: [SCXML] scxml-listener will not process in a defined order (problem: SCXMLExecutor.addListener based on Set)

Posted by Daniel Schwager <Da...@dtnet.de>.
> -----Ursprüngliche Nachricht-----
> Von: Rahul Akolkar [mailto:rahul.akolkar@gmail.com]


> However, in terms of implementation, its good to have predictable
> order. So while I still wouldn't recommend listeners that depend on
> order (earlier ones could have failed, its not a pipeline or a chain,
> various issues), lets make things predictable.
> 
> Please open an improvement request in JIRA (and you can attach a patch
> [1] if you'd like, its probably not more than a line or two close to

Here we are - with an attached (working) patch for this.

https://issues.apache.org/jira/browse/SCXML-78

regards
Danny



---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org


Re: [SCXML] scxml-listener will not process in a defined order (problem: SCXMLExecutor.addListener based on Set)

Posted by Rahul Akolkar <ra...@gmail.com>.
On 7/11/08, Daniel Schwager <Da...@dtnet.de> wrote:
> Hi Rahul,
>
>  i'm running in a problem: i add two listeners to my SCXMLExecutor instance
>         - the first one should run some business-methods using reflection (like you do in your watchclock-example)
>         - the second one should check the current state and maybe trigger some other fsm's
>
>  The order of execution of the listeners is important, because
>   - FIRST I want to process the business-methods  and
>   - SECOND I want to inform other compontents of reaching+processing of business-methods is done
>
>  Your implementation of remember the listeners based on java.util.Set - the order in a
>  Set is not defined (because it's not an ordered element) - so, regardless of the sequence
>  Of adding my two listeners, your code executes the listeners in the wrong order (-:
>
>  Did I miss something or is this a feature request ?
>
<snip/>

In terms of the philosophy behind that piece of code, listeners
shouldn't depend on the order in which they are invoked. Its possible
to think about the scenario you describe as being only one listener,
which you've broken up into two based on some usecase for convenience.

However, in terms of implementation, its good to have predictable
order. So while I still wouldn't recommend listeners that depend on
order (earlier ones could have failed, its not a pipeline or a chain,
various issues), lets make things predictable.

Please open an improvement request in JIRA (and you can attach a patch
[1] if you'd like, its probably not more than a line or two close to
the bits you've identified below -- we'd want a LinkedHashSet, not a
Vector).

-Rahul

[1] http://commons.apache.org/patches.html


>  Regards
>  Danny
>
>
>
>  SCXMLExecutor:
>    public void addListener(final SCXML scxml, final SCXMLListener listener) {
>         Object observable = scxml;
>         scInstance.getNotificationRegistry().addListener(observable, listener);
>     }
>
>
>  NotificationRegistry
>    private synchronized void fireOnEntry(final Object source,
>             final TransitionTarget state) {
>
>  // ***** SET !!! not a Vector ..
>         Set entries = (Set) regs.get(source);
>  // ***** SET !!! not a Vector ..
>
>         if (entries != null) {
>             for (Iterator iter = entries.iterator(); iter.hasNext();) {
>                 SCXMLListener lst = (SCXMLListener) iter.next();
>                 lst.onEntry(state);
>             }
>         }
>     }
>
>  Viele Gruesse
>
>  Daniel Schwager
>
>  -------------------------------------------------------------------
>  DT Netsolution GmbH   -   Taläckerstr. 30    -    D-70437 Stuttgart
>  Geschäftsführer: Daniel Schwager, Stefan Hörz - HRB Stuttgart 19870
>  Tel: +49-711-849910-32, Fax: -932 - Mailto:daniel.schwager@dtnet.de
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org