David Pollak schrieb: > > > On Mon, Nov 30, 2009 at 11:26 PM, Hannes <hannes.flo...@gmx.li > <mailto:hannes.flo...@gmx.li>> wrote: > > Hi David, > >> >> >> On Mon, Nov 30, 2009 at 12:11 AM, Hannes <hannes.flo...@gmx.li >> <mailto:hannes.flo...@gmx.li>> wrote: >> >> Hi David, >> >> In my LimitOrder Meta Object, I did: >> >> override def afterCreate >> >> to inform an Actor, everytime a new Order is created. The >> Actor than calls the joinOtherOrders method. >> # >> I think I understand it now. Cause I'm creating new orders >> inside the loop at some point. But still I don' t really >> know, why it gets called after the old scope of >> joinOtherOrders ends... >> >> >> Sounds to me like it's all in your application's logic. As >> others have pointed out, Thread.dumpStack will let you figure out >> where things are being called. > I think the biggest problem is, that its necessary in my logic to > inform the Actor, everytime a new order is created. This > while-loop is an exception to this rule. I don't think that it > would be a good idea, to change the behavior of how the Actor > responds to messages, just to fix this case, or? Or is there any > chance to tell a new order NOT to inform the Actor, even when its > defined in def afterCreate ? > > > Without seeing the whole of your application logic, it's difficult for > me to advise you. > > > >> >> Also, you might want to use recursion and pattern matching to >> replace your while loop (which is O(n^2) btw): >> >> def dealWithList(in: List[Something]): Unit = in match { >> case Nil => () // nothing left to do >> case x :: _ if x.condition1 => x.doThing1 >> case x :: _ if x.condition2 => x.doThing2 >> case x :: xs if x.condition3 => x.doThing3 ; dealWithList(xs) >> case _ :: xs => dealWithList(xs) >> } > I thought about pattern matching as well, but in my first > implementation, I just wanted to get it running and change it > afterwards. Something else: I think recursion is slower than a > while-loop as long as its not tail recursive, or? > > > This case is tail recursive, so it's as fast as a well written while > loop. But you've got an O(n ^ 2) construct in your app, so > performance doesn't seem to be paramount. No, performance is really important....but I'm going to improve this later on as well... :-)
thanks. > > Thanks, > > David > > > > thanks. > >> >> You have the same semantics of a while loop with the ability to >> break out, but the code is about your logic rather than about >> looping. >> >> >> >> thanks. >> >>> >>> >>> On Sun, Nov 29, 2009 at 7:24 AM, Hannes >>> <hannes.flo...@gmx.li <mailto:hannes.flo...@gmx.li>> wrote: >>> >>> Hey Lifters, >>> >>> >>> How is joinOtherOrders being invoked? >>> >>> >>> >>> I've some really strange things going on here. Please >>> consider this >>> method definition. I've put alot of print "debug" >>> statements between >>> other statements. There's a while-loop that only starts, >>> when the given >>> list (orders) is not empty. It stops when "done" is set >>> to true. So far, >>> so good. Than, have a look at the Lift output. I put in >>> a comment, >>> pointing out where the program runs into the while loop. >>> >>> What really shocks me, are these print statements : >>> >>> before done=false >>> after done=true >>> i += 1 >>> outside while >>> INFO - Service request (GET) / took 121 Milliseconds >>> start of joinAll! >>> >>> >>> The loop ends with "outside while" and than the method >>> gets called again >>> immediately! But who calls it? I don't.... >>> >>> Any ideas? >>> >>> thanks. >>> >>> >>> >>> ---------------------------- method definition >>> >>> -------------------------------------------------------------------------- >>> >>> def joinOtherOrders: Unit = { >>> >>> def joinAll(orders: List[LimitOrder]) = { >>> >>> println("start of joinAll!") >>> >>> var done = false >>> >>> var i = 0 >>> >>> while (!orders.isEmpty && !done) { >>> >>> println("i=" + i + ", " + >>> "orders.isEmpty=" + orders.isEmpty + ", " + "done=" + done) >>> >>> if (this.lots.is <http://this.lots.is> == >>> orders(i).lots.is <http://lots.is>){ >>> >>> println("case-1") >>> >>> println("this=" + this + ", >>> orders(i)=" + orders(i)) >>> >>> this.open(orders(i)) >>> >>> done = true >>> >>> } >>> >>> if (this.lots.is <http://this.lots.is> < >>> orders(i).lots.is <http://lots.is>){ >>> >>> println("case-2") >>> >>> println("this=" + this + ", >>> orders(i)=" + orders(i)) >>> >>> orders(i).reduceLots(this.lots.is >>> <http://this.lots.is>) >>> >>> val newOrder = >>> orders(i).cloneWith(this.lots.is <http://this.lots.is>) >>> >>> newOrder.save >>> >>> this.open(newOrder) >>> >>> println("before done=" + done) >>> >>> done = true >>> >>> println("after done=" + done) >>> >>> } >>> >>> if (this.lots.is <http://this.lots.is> > >>> orders(i).lots.is <http://lots.is>){ >>> >>> println("case-3") >>> >>> println("this=" + this + ", >>> orders(i)=" + orders(i)) >>> >>> this.reduceLots(orders(i).lots.is >>> <http://lots.is>) >>> >>> val newOrder = >>> this.cloneWith(orders(i).lots.is <http://lots.is>) >>> >>> newOrder.save >>> >>> newOrder.open(orders(i)) >>> >>> } >>> >>> i += 1 >>> >>> println("i += 1") >>> >>> } >>> >>> println("outside while") >>> >>> } >>> >>> def findLimitOrdersById: List[LimitOrder] = >>> >>> this.findCandidates.map(x => >>> LimitOrderMetaObj.findAll( >>> >>> By(LimitOrderMetaObj.id, x)).head) >>> >>> joinAll(findLimitOrdersById) >>> >>> } >>> >>> >>> ---------- Lift Output >>> >>> ------------------------------------------------------------------------------- >>> >>> >>> [INFO] Started Jetty Server >>> [INFO] Starting scanner at interval of 5 seconds. >>> INFO - Service request (GET) >>> /comet_request/54834680365/y7kybsmuyv1g took 64 Milliseconds >>> INFO - Service request (GET) >>> /comet_request/85319966940/y7kybsmuyv1g took 23 Milliseconds >>> INFO - Service request (GET) /favicon.ico took 86 >>> Milliseconds >>> INFO - Service request (GET) >>> /comet_request/41521581405/y7kybsmuyv1g took 48 Milliseconds >>> INFO - Service request (GET) >>> /comet_request/93176242746/y7kybsmuyv1g took 7 Milliseconds >>> INFO - Service request (GET) /favicon.ico took 38 >>> Milliseconds >>> INFO - Service request (GET) /favicon.ico took 5 >>> Milliseconds >>> INFO - Service request (GET) / took 551 Milliseconds >>> INFO - Service request (GET) >>> /comet_request/81361316835/y7kybsmuyv1g took 9 Milliseconds >>> INFO - Service request (GET) /favicon.ico took 16 >>> Milliseconds >>> INFO - Service request (GET) / took 61 Milliseconds >>> INFO - Service request (GET) >>> /comet_request/76898140873/y7kybsmuyv1g took 30 Milliseconds >>> INFO - Service request (GET) >>> /comet_request/e8jesgmo10oq/cometAjax.js took 14 >>> Milliseconds >>> INFO - Service request (GET) / took 354 Milliseconds >>> INFO - Service request (GET) / took 734 Milliseconds >>> INFO - Service request (GET) / took 484 Milliseconds >>> INFO - Service request (GET) /images/ajax-loader.gif >>> took 7 Milliseconds >>> INFO - Service request (GET) /favicon.ico took 4 >>> Milliseconds >>> INFO - Service request (GET) >>> /comet_request/78026241833/e8jesgmo10oq took 55 Milliseconds >>> INFO - Service request (GET) >>> /comet_request/28225538857/e8jesgmo10oq took 600 >>> Milliseconds >>> INFO - Service request (GET) /user_mgt/sign_up took 711 >>> Milliseconds >>> INFO - Service request (GET) /images/ajax-loader.gif >>> took 2 Milliseconds >>> INFO - Service request (GET) /user_mgt/login took 38 >>> Milliseconds >>> INFO - Service request (GET) /images/ajax-loader.gif >>> took 2 Milliseconds >>> INFO - Service request (POST) /user_mgt/login took 122 >>> Milliseconds >>> INFO - Service request (GET) / took 93 Milliseconds >>> INFO - Service request (GET) /images/ajax-loader.gif >>> took 1 Milliseconds >>> INFO - Service request (GET) >>> /comet_request/42818301584/e8jesgmo10oq took 1144 >>> Milliseconds >>> INFO - Service request (GET) /limitorder/list took 99 >>> Milliseconds >>> INFO - Service request (GET) /images/ajax-loader.gif >>> took 1 Milliseconds >>> INFO - Service request (GET) /limitorder/create took 77 >>> Milliseconds >>> INFO - Service request (GET) /images/ajax-loader.gif >>> took 2 Milliseconds >>> INFO - Service request (POST) /limitorder/create took >>> 134 Milliseconds >>> start of joinAll! >>> outside while >>> INFO - Service request (GET) /limitorder/list took 270 >>> Milliseconds >>> INFO - Service request (GET) /images/ajax-loader.gif >>> took 2 Milliseconds >>> INFO - Service request (GET) /limitorder/create took 51 >>> Milliseconds >>> INFO - Service request (GET) /images/ajax-loader.gif >>> took 2 Milliseconds >>> INFO - Service request (POST) /limitorder/create took 11 >>> Milliseconds >>> start of joinAll! >>> outside while >>> INFO - Service request (GET) /limitorder/list took 56 >>> Milliseconds >>> INFO - Service request (GET) /images/ajax-loader.gif >>> took 1 Milliseconds >>> INFO - Service request (GET) /user_mgt/logout took 21 >>> Milliseconds >>> INFO - The CometActor org.tobster.comet.mar...@c595bcd >>> Received Shutdown >>> INFO - Service request (GET) / took 82 Milliseconds >>> INFO - Service request (GET) /images/ajax-loader.gif >>> took 1 Milliseconds >>> INFO - Service request (GET) >>> /comet_request/16awv92sf1zgl/cometAjax.js took 2 >>> Milliseconds >>> INFO - Service request (GET) >>> /comet_request/21077236431/16awv92sf1zgl took 41 >>> Milliseconds >>> INFO - Service request (GET) >>> /comet_request/89548874922/16awv92sf1zgl took 817 >>> Milliseconds >>> INFO - Service request (GET) /user_mgt/sign_up took 325 >>> Milliseconds >>> INFO - Service request (GET) /images/ajax-loader.gif >>> took 1 Milliseconds >>> INFO - Service request (POST) /user_mgt/sign_up took 69 >>> Milliseconds >>> INFO - Service request (GET) / took 21 Milliseconds >>> INFO - Service request (GET) /images/ajax-loader.gif >>> took 1 Milliseconds >>> INFO - Service request (GET) >>> /comet_request/33304915285/16awv92sf1zgl took 2485 >>> Milliseconds >>> INFO - Service request (GET) /limitorder/create took 102 >>> Milliseconds >>> INFO - Service request (GET) /images/ajax-loader.gif >>> took 2 Milliseconds >>> INFO - Service request (POST) /limitorder/create took 33 >>> Milliseconds >>> start of joinAll! >>> outside while >>> INFO - Service request (GET) / took 42 Milliseconds >>> INFO - Service request (GET) /images/ajax-loader.gif >>> took 2 Milliseconds >>> INFO - Service request (GET) >>> /comet_request/43041247578/16awv92sf1zgl took 1270 >>> Milliseconds >>> INFO - Service request (GET) /limitorder/create took 72 >>> Milliseconds >>> INFO - Service request (GET) /images/ajax-loader.gif >>> took 2 Milliseconds >>> INFO - Service request (POST) /limitorder/create took 34 >>> Milliseconds >>> start of joinAll! >>> outside while >>> INFO - Service request (GET) / took 28 Milliseconds >>> INFO - Service request (GET) /images/ajax-loader.gif >>> took 1 Milliseconds >>> INFO - Service request (GET) >>> /comet_request/94649970499/16awv92sf1zgl took 2455 >>> Milliseconds >>> INFO - Service request (GET) /limitorder/create took 25 >>> Milliseconds >>> INFO - Service request (GET) /images/ajax-loader.gif >>> took 1 Milliseconds >>> INFO - Service request (POST) /limitorder/create took 10 >>> Milliseconds >>> >>> ####### Interesting things start here >>> ##################################### >>> >>> start of joinAll! >>> i=0, orders.isEmpty=false, done=false >>> case-3 >>> this={ owner=2, type=, lots=2, market= }, orders(i)={ >>> owner=1, type=SELL, lots=1, market=Beginner } >>> computeAndSetMarketValue >>> computeNewMarketValue >>> setMarketValue from ID=1 to: 10001 >>> findAndCloseOpenOrder: found=0 >>> findAndCloseOpenOrder: found=0 >>> i += 1 >>> i=1, orders.isEmpty=false, done=false >>> case-2 >>> this={ owner=2, type=, lots=1, market= }, orders(i)={ >>> owner=1, type=SELL, lots=2, market=Beginner } >>> computeAndSetMarketValue >>> computeNewMarketValue >>> setMarketValue from ID=1 to: 10001 >>> findAndCloseOpenOrder: found=0 >>> findAndCloseOpenOrder: found=0 >>> before done=false >>> after done=true >>> i += 1 >>> outside while >>> INFO - Service request (GET) / took 121 Milliseconds >>> start of joinAll! >>> i=0, orders.isEmpty=false, done=false >>> case-1 >>> this={ owner=2, type=BUY, lots=1, market=Beginner }, >>> orders(i)={ owner=1, type=SELL, lots=1, market=Beginner } >>> computeAndSetMarketValue >>> computeNewMarketValue >>> setMarketValue from ID=1 to: 10001 >>> findAndCloseOpenOrder: found=0 >>> findAndCloseOpenOrder: found=0 >>> i += 1 >>> outside while >>> start of joinAll! >>> outside while >>> INFO - Service request (GET) /images/ajax-loader.gif >>> took 1 Milliseconds >>> >>> -- >>> >>> You received this message because you are subscribed to >>> the Google Groups "Lift" group. >>> To post to this group, send email to >>> liftweb@googlegroups.com <mailto:liftweb@googlegroups.com>. >>> To unsubscribe from this group, send email to >>> liftweb+unsubscr...@googlegroups.com >>> <mailto:liftweb%2bunsubscr...@googlegroups.com>. >>> For more options, visit this group at >>> http://groups.google.com/group/liftweb?hl=en. >>> >>> >>> >>> >>> >>> -- >>> Lift, the simply functional web framework http://liftweb.net >>> Beginning Scala http://www.apress.com/book/view/1430219890 >>> Follow me: http://twitter.com/dpp >>> Surf the harmonics >>> >>> -- >>> >>> You received this message because you are subscribed to the >>> Google Groups "Lift" group. >>> To post to this group, send email to >>> liftweb@googlegroups.com <mailto:liftweb@googlegroups.com>. >>> To unsubscribe from this group, send email to >>> liftweb+unsubscr...@googlegroups.com >>> <mailto:liftweb+unsubscr...@googlegroups.com>. >>> For more options, visit this group at >>> http://groups.google.com/group/liftweb?hl=en. >> >> -- >> >> You received this message because you are subscribed to the >> Google Groups "Lift" group. >> To post to this group, send email to liftweb@googlegroups.com >> <mailto:liftweb@googlegroups.com>. >> To unsubscribe from this group, send email to >> liftweb+unsubscr...@googlegroups.com >> <mailto:liftweb%2bunsubscr...@googlegroups.com>. >> For more options, visit this group at >> http://groups.google.com/group/liftweb?hl=en. >> >> >> >> >> -- >> Lift, the simply functional web framework http://liftweb.net >> Beginning Scala http://www.apress.com/book/view/1430219890 >> Follow me: http://twitter.com/dpp >> Surf the harmonics >> >> -- >> >> You received this message because you are subscribed to the >> Google Groups "Lift" group. >> To post to this group, send email to liftweb@googlegroups.com >> <mailto:liftweb@googlegroups.com>. >> To unsubscribe from this group, send email to >> liftweb+unsubscr...@googlegroups.com >> <mailto:liftweb+unsubscr...@googlegroups.com>. >> For more options, visit this group at >> http://groups.google.com/group/liftweb?hl=en. > > -- > > You received this message because you are subscribed to the Google > Groups "Lift" group. > To post to this group, send email to liftweb@googlegroups.com > <mailto:liftweb@googlegroups.com>. > To unsubscribe from this group, send email to > liftweb+unsubscr...@googlegroups.com > <mailto:liftweb%2bunsubscr...@googlegroups.com>. > For more options, visit this group at > http://groups.google.com/group/liftweb?hl=en. > > > > > -- > Lift, the simply functional web framework http://liftweb.net > Beginning Scala http://www.apress.com/book/view/1430219890 > Follow me: http://twitter.com/dpp > Surf the harmonics > > -- > > You received this message because you are subscribed to the Google > Groups "Lift" group. > To post to this group, send email to lift...@googlegroups.com. > To unsubscribe from this group, send email to > liftweb+unsubscr...@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/liftweb?hl=en. -- You received this message because you are subscribed to the Google Groups "Lift" group. To post to this group, send email to lift...@googlegroups.com. To unsubscribe from this group, send email to liftweb+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/liftweb?hl=en.