[Lift] Re: Canceling a ActorPing.scheduleAtFixedRate task
So why not keep the method for the Lift-Actors branch? ... because there is no concept of linking actors there? Br's, Marius On Sep 24, 6:52 pm, David Pollak feeder.of.the.be...@gmail.com wrote: I strongly recommend against using scheduleAtFixedRate because: - Internally, it creates an actor that's linked to your actor and that leads one of the Scala Actor memory problems - The turning off issue that you've identified - On the Scala-Actor-free branch of Lift, I've removed the method. Instead, I'd suggest scheduling a new actorping each time you receive one. On Wed, Sep 23, 2009 at 2:17 PM, Xavi Ramirez xavi@gmail.com wrote: I think I figured out a way to get around this: class SomeCometActor extends CometActor { private var tempActor: Actor = null override def localSetup() { val cometActor = this var tempActor = actor{ loop { react { case TaskMessage = cometActor ! TaskMessage case UnSchedule = exit } } } ActorPing.scheduleAtFixedRate(tempActor, TaskMessage, 15 seconds, 15 seconds) } override def lowPriority = { case TaskMessage = DoSomething() if(someCondition) { tempActor ! UnSchedule } } } Instead of registering the comet actors for the scheduled task, I register a temporary actor. During its execution, scheduleAtFixedRate creates an actor. Let's call this the Scheduled Task Actor. The scheduled task actor is then linked(see http://www.scala-lang.org/docu/files/api/scala/actors/Actor.html#link... ) to the temporary actor i passed in. So now, when I need to stop the scheduled task actor, I can shutdown the temporary actor. This works because when an actor is shutdown, all actors it's linked to are shut down as well. This is kinda nuts, but I guess it works. I'm just sharing in case someone else runs into this problem. Thanks, Xavi On Wed, Sep 23, 2009 at 4:13 PM, Xavi Ramirez xavi@gmail.com wrote: There isn't much to show... but maybe an example clarify things. class SomeCometActor extends CometActor { override def localSetup() { ActorPing.scheduleAtFixedRate(this, TaskMessage, 15 seconds, 15 seconds) } override def lowPriority = { case TaskMessage = DoSomething() if(someCondition) { /* stop the scheduled task... What do I put here?*/ } } } If scheduleAtFixedRate returned either the Future or the Actor it creates, then stopping the scheduled task would be fairly straight forward. Then again, I might be missing something. Thanks, Xavi On Wed, Sep 23, 2009 at 3:54 PM, Timothy Perrett timo...@getintheloop.eu wrote: Xavi, Can you show some code? There might be a way of doing it depending what you have... Cheers, Tim Sent from my iPhone On 23 Sep 2009, at 20:50, Xavi Ramirez xavi@gmail.com wrote: Hello, Is there any way to cancel a task created with a ActorPing.scheduleAtFixedRate? From looking at the source ( http://scala-tools.org/scaladocs/liftweb/1.0/net/liftweb/util/ActorPi... ) it seem that scheduleAtFixedRate creates an actor which accepts an UnSchedule message. Unfortunately this actor is not returned to the caller. Thanks in advance, Xavi -- Lift, the simply functional web frameworkhttp://liftweb.net Beginning Scalahttp://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 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 -~--~~~~--~~--~--~---
[Lift] Re: Canceling a ActorPing.scheduleAtFixedRate task
Hi, When you call scheduleAtFixedRate that actor is sending your actor a Scheduled message, hence you can capture the correct sender. You don't need to create a different actor. David's points are quite valid regarding the correct Scala actors' state. Br's, Marius On Sep 23, 4:17 pm, Xavi Ramirez xavi@gmail.com wrote: I think I figured out a way to get around this: class SomeCometActor extends CometActor { private var tempActor: Actor = null override def localSetup() { val cometActor = this var tempActor = actor{ loop { react { case TaskMessage = cometActor ! TaskMessage case UnSchedule = exit } } } ActorPing.scheduleAtFixedRate(tempActor, TaskMessage, 15 seconds, 15 seconds) } override def lowPriority = { case TaskMessage = DoSomething() if(someCondition) { tempActor ! UnSchedule } } } Instead of registering the comet actors for the scheduled task, I register a temporary actor. During its execution, scheduleAtFixedRate creates an actor. Let's call this the Scheduled Task Actor. The scheduled task actor is then linked(seehttp://www.scala-lang.org/docu/files/api/scala/actors/Actor.html#link...) to the temporary actor i passed in. So now, when I need to stop the scheduled task actor, I can shutdown the temporary actor. This works because when an actor is shutdown, all actors it's linked to are shut down as well. This is kinda nuts, but I guess it works. I'm just sharing in case someone else runs into this problem. Thanks, Xavi On Wed, Sep 23, 2009 at 4:13 PM, Xavi Ramirez xavi@gmail.com wrote: There isn't much to show... but maybe an example clarify things. class SomeCometActor extends CometActor { override def localSetup() { ActorPing.scheduleAtFixedRate(this, TaskMessage, 15 seconds, 15 seconds) } override def lowPriority = { case TaskMessage = DoSomething() if(someCondition) { /* stop the scheduled task... What do I put here?*/ } } } If scheduleAtFixedRate returned either the Future or the Actor it creates, then stopping the scheduled task would be fairly straight forward. Then again, I might be missing something. Thanks, Xavi On Wed, Sep 23, 2009 at 3:54 PM, Timothy Perrett timo...@getintheloop.eu wrote: Xavi, Can you show some code? There might be a way of doing it depending what you have... Cheers, Tim Sent from my iPhone On 23 Sep 2009, at 20:50, Xavi Ramirez xavi@gmail.com wrote: Hello, Is there any way to cancel a task created with a ActorPing.scheduleAtFixedRate? From looking at the source (http://scala-tools.org/scaladocs/liftweb/1.0/net/liftweb/util/ActorPi... ) it seem that scheduleAtFixedRate creates an actor which accepts an UnSchedule message. Unfortunately this actor is not returned to the caller. Thanks in advance, Xavi --~--~-~--~~~---~--~~ 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 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 -~--~~~~--~~--~--~---
[Lift] Re: Canceling a ActorPing.scheduleAtFixedRate task
Xavi, Can you show some code? There might be a way of doing it depending what you have... Cheers, Tim Sent from my iPhone On 23 Sep 2009, at 20:50, Xavi Ramirez xavi@gmail.com wrote: Hello, Is there any way to cancel a task created with a ActorPing.scheduleAtFixedRate? From looking at the source (http://scala-tools.org/scaladocs/liftweb/1.0/net/liftweb/util/ActorPing.scala.html ) it seem that scheduleAtFixedRate creates an actor which accepts an UnSchedule message. Unfortunately this actor is not returned to the caller. Thanks in advance, Xavi --~--~-~--~~~---~--~~ 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 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 -~--~~~~--~~--~--~---
[Lift] Re: Canceling a ActorPing.scheduleAtFixedRate task
There isn't much to show... but maybe an example clarify things. class SomeCometActor extends CometActor { override def localSetup() { ActorPing.scheduleAtFixedRate(this, TaskMessage, 15 seconds, 15 seconds) } override def lowPriority = { case TaskMessage = DoSomething() if(someCondition) { /* stop the scheduled task... What do I put here?*/ } } } If scheduleAtFixedRate returned either the Future or the Actor it creates, then stopping the scheduled task would be fairly straight forward. Then again, I might be missing something. Thanks, Xavi On Wed, Sep 23, 2009 at 3:54 PM, Timothy Perrett timo...@getintheloop.eu wrote: Xavi, Can you show some code? There might be a way of doing it depending what you have... Cheers, Tim Sent from my iPhone On 23 Sep 2009, at 20:50, Xavi Ramirez xavi@gmail.com wrote: Hello, Is there any way to cancel a task created with a ActorPing.scheduleAtFixedRate? From looking at the source (http://scala-tools.org/scaladocs/liftweb/1.0/net/liftweb/util/ActorPing.scala.html ) it seem that scheduleAtFixedRate creates an actor which accepts an UnSchedule message. Unfortunately this actor is not returned to the caller. Thanks in advance, Xavi --~--~-~--~~~---~--~~ 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 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 -~--~~~~--~~--~--~---
[Lift] Re: Canceling a ActorPing.scheduleAtFixedRate task
I think I figured out a way to get around this: class SomeCometActor extends CometActor { private var tempActor: Actor = null override def localSetup() { val cometActor = this var tempActor = actor{ loop { react { case TaskMessage = cometActor ! TaskMessage case UnSchedule = exit } } } ActorPing.scheduleAtFixedRate(tempActor, TaskMessage, 15 seconds, 15 seconds) } override def lowPriority = { case TaskMessage = DoSomething() if(someCondition) { tempActor ! UnSchedule } } } Instead of registering the comet actors for the scheduled task, I register a temporary actor. During its execution, scheduleAtFixedRate creates an actor. Let's call this the Scheduled Task Actor. The scheduled task actor is then linked(see http://www.scala-lang.org/docu/files/api/scala/actors/Actor.html#link%28scala.actors.AbstractActor%29) to the temporary actor i passed in. So now, when I need to stop the scheduled task actor, I can shutdown the temporary actor. This works because when an actor is shutdown, all actors it's linked to are shut down as well. This is kinda nuts, but I guess it works. I'm just sharing in case someone else runs into this problem. Thanks, Xavi On Wed, Sep 23, 2009 at 4:13 PM, Xavi Ramirez xavi@gmail.com wrote: There isn't much to show... but maybe an example clarify things. class SomeCometActor extends CometActor { override def localSetup() { ActorPing.scheduleAtFixedRate(this, TaskMessage, 15 seconds, 15 seconds) } override def lowPriority = { case TaskMessage = DoSomething() if(someCondition) { /* stop the scheduled task... What do I put here?*/ } } } If scheduleAtFixedRate returned either the Future or the Actor it creates, then stopping the scheduled task would be fairly straight forward. Then again, I might be missing something. Thanks, Xavi On Wed, Sep 23, 2009 at 3:54 PM, Timothy Perrett timo...@getintheloop.eu wrote: Xavi, Can you show some code? There might be a way of doing it depending what you have... Cheers, Tim Sent from my iPhone On 23 Sep 2009, at 20:50, Xavi Ramirez xavi@gmail.com wrote: Hello, Is there any way to cancel a task created with a ActorPing.scheduleAtFixedRate? From looking at the source (http://scala-tools.org/scaladocs/liftweb/1.0/net/liftweb/util/ActorPing.scala.html ) it seem that scheduleAtFixedRate creates an actor which accepts an UnSchedule message. Unfortunately this actor is not returned to the caller. Thanks in advance, Xavi --~--~-~--~~~---~--~~ 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 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 -~--~~~~--~~--~--~---