From user-return-25058-apmail-commons-user-archive=commons.apache.org@commons.apache.org Tue Sep 28 14:32:18 2010 Return-Path: Delivered-To: apmail-commons-user-archive@www.apache.org Received: (qmail 87370 invoked from network); 28 Sep 2010 14:32:18 -0000 Received: from unknown (HELO mail.apache.org) (140.211.11.3) by 140.211.11.9 with SMTP; 28 Sep 2010 14:32:18 -0000 Received: (qmail 57096 invoked by uid 500); 28 Sep 2010 14:32:17 -0000 Delivered-To: apmail-commons-user-archive@commons.apache.org Received: (qmail 56784 invoked by uid 500); 28 Sep 2010 14:32:14 -0000 Mailing-List: contact user-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: "Commons Users List" Delivered-To: mailing list user@commons.apache.org Received: (qmail 56775 invoked by uid 99); 28 Sep 2010 14:32:13 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 28 Sep 2010 14:32:13 +0000 X-ASF-Spam-Status: No, hits=0.0 required=10.0 tests=FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: domain of rahul.akolkar@gmail.com designates 74.125.82.171 as permitted sender) Received: from [74.125.82.171] (HELO mail-wy0-f171.google.com) (74.125.82.171) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 28 Sep 2010 14:32:08 +0000 Received: by wyf19 with SMTP id 19so5510949wyf.30 for ; Tue, 28 Sep 2010 07:31:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:received:in-reply-to :references:date:message-id:subject:from:to:content-type :content-transfer-encoding; bh=gOWZWo0ACmdHoizDGCTb44iQEAdn6jUn/xW4ntu6Kpg=; b=je5Wx4a1j1eOmcEd5AuT/Lb39XqHciMuvDwJk2BoUJ9yfeWj/Au5RW9F7TQyln9tuH ZrZzBSZ9ekou62uwPmmUQuh7cQEf3wqSbEVMUeax5jVKNQy6TXzWZ5FHyRI0KeAmOkQA IbKNB1lNmkeaLklxWy1Y5kV3cr74UiX0ksYxA= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type:content-transfer-encoding; b=dGF9iDSl/f6eCPR7+63E0Jqrz4dwpKcPVaZWXtwTNluJl0ub6mAb9OttNcP03XbzIl r3OwYuc27E1+203AyGtblXZVr+l3dFf6cbsOrzigTmP+oeTuQDd1BnaRevsDvK1wbGJK yM9Al8amlKXi0froNyOAskKkeLraqxNzq66lc= MIME-Version: 1.0 Received: by 10.227.132.146 with SMTP id b18mr7972870wbt.148.1285684307062; Tue, 28 Sep 2010 07:31:47 -0700 (PDT) Received: by 10.227.127.205 with HTTP; Tue, 28 Sep 2010 07:31:46 -0700 (PDT) In-Reply-To: References: <4C9CC4FE.5010106@sysvision.de> <4CA0749A.4020907@sysvision.de> Date: Tue, 28 Sep 2010 10:31:46 -0400 Message-ID: Subject: Re: [scxml] Too many state navigation causes StackOverflowException From: Rahul Akolkar To: Commons Users List Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable On Tue, Sep 28, 2010 at 10:29 AM, Rahul Akolkar w= rote: > On Mon, Sep 27, 2010 at 6:40 AM, Lorenz Schumann | Sysvision GmbH > wrote: >> Hi Rahul, >> >> i took over a project in development and took the implementation as the >> correct way to do it. >> But after i read your response (thank you very much by the way!) i re-re= ad >> everything in the documentation. >> >> I want to control a phone application with what scxml can offer me. >> But when i look at the stopwatch example i see a huge difference to our >> approach: When controlling a stopwatch the states change on user action >> (mostly). The user interface sends the events to the statemachine. >> But in our phone application the states change depending on what happens >> inside the invoked code. So we trigger the events inside the invoked cod= e. >> I know there is some fraction of the puzzle i am missing and i cannot se= e >> how to fire the events from outside to control the statemachine. >> > > > I think part of it is that you have started with one of the most > flexible and thereby, harder constructs i.e. invoke to work with. If > the code that you are invoking isn't long running, then you are better > off using constructs that allow for easier synchronous usage for > triggering events. > > >> I also couldn't find any helpful examples. Anything that helps is >> appreciated! >> > > > There is an example (related to mobile apps) linked from the home > page, see "Who is using it?" section: > > =A0http://commons.apache.org/scxml/ > > Some details here, code is invoked using custom actions (not using invoke= ): > > =A0http://mymobileweb.morfeo-project.org/mymobileweb/mymw-tech/scxml > Or this instead: http://forge.morfeo-project.org/wiki_en/index.php/SCXML_Getting_Started -Rahul > I pointed to the guide in the previous email, which has more on custom ac= tions. > > >> Thanks in advance! >> >> Lorenz >> >> P.S.: I decided to create a minimal example of how i use it right now. M= aybe >> it helps... >> >> >> > initial=3D"enter_pin"> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> --------------------- >> >> =A0 =A0 =A0 =A0SCXML scxml =3D >> SCXMLParser.parse(ClassLoader.getSystemResource("sc.xml"), new >> SimpleErrorHandler()); >> =A0 =A0 =A0 =A0SCXMLExecutor executor =3D new SCXMLExecutor(new JexlEval= uator(), new >> SimpleDispatcher(), new SimpleErrorReporter()); >> =A0 =A0 =A0 =A0executor.setRootContext(new JexlContext(new HashMap())); >> =A0 =A0 =A0 =A0executor.setStateMachine(scxml); >> // ReflectiveInvoker calls "EnterPin", "HandlePinFailed", etc. by reflec= tion >> =A0 =A0 =A0 =A0executor.registerInvokerClass("java", ReflectiveInvoker.c= lass); >> =A0 =A0 =A0 =A0executor.go(); >> >> --------------------- >> >> Now the most likely completely wrong usage: >> > > > Likely, yes. See note at bottom of interface Javadocs: > > =A0http://commons.apache.org/scxml/0.9/apidocs/org/apache/commons/scxml/i= nvoke/Invoker.html > > -Rahul > > > >> public class EnterPin { >> =A0 =A0public void handle(SCInstance sc) { >> =A0 =A0 =A0 =A0... >> =A0 =A0 =A0 =A0if (success) { >> =A0 =A0 =A0 =A0 =A0 =A0sc.getExecutor().triggerEvent(new TriggerEvent("s= ucc", >> TriggerEvent.SIGNAL_EVENT)); >> =A0 =A0 =A0 =A0} >> =A0 =A0 =A0 =A0else { >> =A0 =A0 =A0 =A0 =A0 =A0sc.getExecutor().triggerEvent(new TriggerEvent("f= ail", >> TriggerEvent.SIGNAL_EVENT)); >> =A0 =A0 =A0 =A0} >> =A0 =A0} >> } >> >> >>> On Fri, Sep 24, 2010 at 11:34 AM, Lorenz Schumann | Sysvision GmbH >>> =A0wrote: >>> >>>> >>>> Hi, >>>> >>>> i am using Commons SCXML for the first time and am overall new to the >>>> Statechart paradigm. >>>> But i am working on a software where a statemachine is needed and the >>>> first >>>> choice fell on commons. >>>> So much for the introduction. >>>> >>>> Now what we discovered is that when you navigate from state to state v= ia >>>> triggering events there is a recursion that makes the method-stack hig= her >>>> and higher and will at some point throw an StackOverflowError. >>>> This is what the important part of a stacktrace looks like: >>>> >>>> =A0 =A0at >>>> >>>> org.apache.commons.scxml.semantics.SCXMLSemanticsImpl.initiateInvokes(= SCXMLSemanticsImpl.java:847) >>>> =A0 =A0at >>>> >>>> org.apache.commons.scxml.SCXMLExecutor.triggerEvents(SCXMLExecutor.jav= a:142) >>>> =A0 =A0at >>>> >>>> org.apache.commons.scxml.SCXMLExecutor.triggerEvent(SCXMLExecutor.java= :160) >>>> =A0 =A0at MyInvoker.invoke(MyInvoker.java:23) >>>> =A0 =A0at >>>> >>>> org.apache.commons.scxml.semantics.SCXMLSemanticsImpl.initiateInvokes(= SCXMLSemanticsImpl.java:847) >>>> =A0 =A0at >>>> >>>> org.apache.commons.scxml.SCXMLExecutor.triggerEvents(SCXMLExecutor.jav= a:142) >>>> =A0 =A0at >>>> >>>> org.apache.commons.scxml.SCXMLExecutor.triggerEvent(SCXMLExecutor.java= :160) >>>> =A0 =A0at MyInvoker.invoke(MyInvoker.java:23) >>>> =A0 =A0at >>>> >>>> org.apache.commons.scxml.semantics.SCXMLSemanticsImpl.initiateInvokes(= SCXMLSemanticsImpl.java:847) >>>> =A0 =A0at >>>> >>>> org.apache.commons.scxml.SCXMLExecutor.triggerEvents(SCXMLExecutor.jav= a:142) >>>> =A0 =A0at >>>> >>>> org.apache.commons.scxml.SCXMLExecutor.triggerEvent(SCXMLExecutor.java= :160) >>>> =A0 =A0at MyInvoker.invoke(MyInvoker.java:23) >>>> >>>> Are we using it as it is meant to be? Is there a way that the executio= n >>>> of >>>> states is not beeing stacked? >>>> >>>> >>> >>> >>> >>> The invoke paradigm is broadly about asynchronously initiating and >>> interacting with external processes. From the trace it looks like your >>> invoker may be synchronously triggering an event on the state machine >>> (which may be initiating the invoke again and so on ad infinitum). >>> Instead, invoke should simply initiate external processing >>> asynchronously and then trigger an event back when the processing is >>> done (or when it fails). >>> >>> Some background on usage is here [1]. >>> >>> If what you are trying to do can be modeled as sending events to >>> existing external processes, you can take a look at =A0and the >>> EventDispatcher instead. >>> >>> If what you are trying to do can be modeled as inherently synchronous >>> executable content within the state machine's, =A0or >>> , then you can have a look a custom actions [2] instead. >>> >>> -Rahul >>> >>> [1] http://commons.apache.org/scxml/guide/using-commons-scxml.html >>> [2] http://commons.apache.org/scxml/guide/custom-actions.html >>> >>> >>> >>> >>>> >>>> Help is much appreciated. >>>> >>>> Lorenz >>>> > --------------------------------------------------------------------- To unsubscribe, e-mail: user-unsubscribe@commons.apache.org For additional commands, e-mail: user-help@commons.apache.org