Same number of LiftActors and CometActors?

20 views
Skip to first unread message

Andrzej Skalski

unread,
May 20, 2015, 12:20:33 PM5/20/15
to lif...@googlegroups.com
Hi,

in application I write there is a time consuming background process I need to perform once in a while (processing document uploaded by user).
I want the user to get a realtime feedback on how it goes, so I created a CometActor for this.

On the other hand, I expect multiple users to upload documents in the same time. It is different (correct me if I am wrong) than in most examples, where there is a singleton object (like "ChatServer" or "MasterClock"). Here, the object would be busy for most of it's time (preferably entire lifespan), just reporting back to a single CometActor.

So I guess that the "server" (the LiftActor to perform the job) should be a class, instead of object, and I should create as many instances as number of CometActors. Unless of course I can perform the expensive computation within the CometActor, without creating LiftActor for it...

The question is: how to do it properly and clean?

Kindest Regards

Antonio Salazar Cardozo

unread,
May 20, 2015, 1:52:06 PM5/20/15
to lif...@googlegroups.com, andrzej....@gmail.com
You can invoke Schedule(() => { ... code that does something and then sends a message to the comet }) to
schedule something to run on a background thread without needing to explicitly write a LiftActor subclass.
Thanks,
Antonio

Andrzej Skalski

unread,
May 21, 2015, 6:04:15 AM5/21/15
to lif...@googlegroups.com
Than you Antonio, this looks precisely like what I am looking for. However, I need to define "registerWith" method in my CometActor. Or should I use different comet mechanism?

Andrzej

--
--
Lift, the simply functional web framework: http://liftweb.net
Code: http://github.com/lift
Discussion: http://groups.google.com/group/liftweb
Stuck? Help us help you: https://www.assembla.com/wiki/show/liftweb/Posting_example_code

---
You received this message because you are subscribed to a topic in the Google Groups "Lift" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/liftweb/uuVEv_qdgRM/unsubscribe.
To unsubscribe from this group and all its topics, send an email to liftweb+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Antonio Salazar Cardozo

unread,
May 21, 2015, 3:48:55 PM5/21/15
to lif...@googlegroups.com, andrzej....@gmail.com
Not sure what you mean about registerWith… Should be unrelated to this. For example:

class MyCometActor extends CometActor {
  def lowPriority = {
    case DoSomethingExpensive =>
      Schedule(() => {
        val expensiveResult = doSomethingExpensive
        this ! SomethingExpensiveCompleted(expensiveResult)
      })

    case SomethingExpensiveCompleted(result) =>
      // do something with the result
  }
}

Hope that clarifies things!
Thanks,
Antonio
To unsubscribe from this group and all its topics, send an email to liftweb+unsubscribe@googlegroups.com.

Andrzej Skalski

unread,
May 21, 2015, 4:13:37 PM5/21/15
to lif...@googlegroups.com
Hi Antonio, you are absolutely right. For some reason my CometActor inherited CometListener as well, and the latter requires "registerWith" method. I thought that's an Actor's requirement.

Thank you!

W dniu 21.05.2015 o 21:48, Antonio Salazar Cardozo pisze:
To unsubscribe from this group and all its topics, send an email to liftweb+u...@googlegroups.com.

Antonio Salazar Cardozo

unread,
May 22, 2015, 11:28:35 AM5/22/15
to lif...@googlegroups.com, andrzej....@gmail.com
Awesome, glad to help!
Thanks,
Antonio
Reply all
Reply to author
Forward
0 new messages