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%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
> >>>
> >>> >
> >>>
> >>
> >> >>
> >>
> >
>
> >
>


-- 
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
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to