How to remove or shutdown comet-actor?

146 views
Skip to first unread message

Abdhesh Kumar

unread,
Apr 17, 2014, 9:34:34 AM4/17/14
to lif...@googlegroups.com
Hi Lifter
I am facing some problem regarding lift-actor, I have mange lift-actor for per logged-in user but when i logged-out or close browser then logged-out user's lift-actor does not remove from Map of lift-actor, I am showing some code snippet.

final case class AddClient(userId: ObjectId, who: ABCClient)
final case class RemoveClient(who: ABCClient)

object ABCManager extends LiftActor with Loggable {
  var clients: Map[ObjectId, NotifyClient] = Map.empty// Here i have manage lift-actor for per user
}

class ABCClient extends CometActor with Loggable{
  val user = User.findCurrentUser
    override def localSetup(): Unit = {
    ABCManager ! AddClient(userId, this)
    super.localSetup()
  }

  override def localShutdown(): Unit = {
    ABCManager ! RemoveClient(this)
    super.localShutdown()
  }

override def lifespan: Box[TimeSpan] = Full(5 minutes)
}

When I logged-out  from web application, logged-out user's lift-actor does not remove from map
So do i really need to remove logged-out user's lift-actor from Map if yes then please tell me how? OR it would remove auto-matically from Map?


--
Best Regards | Abdhesh Kumar
Mobile No. +91-9958591897

Diego Medina

unread,
Apr 17, 2014, 10:24:17 AM4/17/14
to Lift
comet actors stay alive even after you close your browser, and stay for the duration of the session. you could set this in your comet actor

override def lifespan = Full(120 seconds)


and then they will shut down after 120 seconds after the browser window was closed (this is not an exact setting, may be a few more/less seconds).


120 is more or less the lowest you can set it to



--
--
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 the Google Groups "Lift" group.
To unsubscribe from this group and stop receiving emails from it, send an email to liftweb+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Diego Medina
Lift/Scala consultant
di...@fmpwizard.com
http://fmpwizard.telegr.am

Abdhesh Kumar

unread,
Apr 17, 2014, 2:35:33 PM4/17/14
to lif...@googlegroups.com
Yes Thanks Diego Medina for quick reply.
I already set comet lifspan override def lifespan: Box[TimeSpan] = Full(5 minutes) even comet does not shut down after logged out, lifespan goes out or even closing complete browser.
is it the right approach to remove lift-actor from map explicitly when user logged-out? or an any alternate solution to shutdown or remove lift-actor from map when user logged-out?

Antonio Salazar Cardozo

unread,
Apr 17, 2014, 3:07:22 PM4/17/14
to lif...@googlegroups.com
This seems unclear. Is the message handler for ABCManager implemented correctly? You didn't present it, so
it's hard to tell. The lifespan does work, but it will take a full 5 minutes from the last time the comet was seen on a
page to take effect (could take a little longer, since it's hard to tell when a page was closed on the client), or it
will require the session to be destroyed. Logging out doesn't necessarily destroy the associated session, mind you.
Thanks,
Antonio
To unsubscribe from this group and stop receiving emails from it, send an email to liftweb+unsubscribe@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--
Diego Medina
Lift/Scala consultant
di...@fmpwizard.com
http://fmpwizard.telegr.am

--
--
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 the Google Groups "Lift" group.
To unsubscribe from this group and stop receiving emails from it, send an email to liftweb+unsubscribe@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Abdhesh Kumar

unread,
Apr 17, 2014, 3:38:37 PM4/17/14
to lif...@googlegroups.com
Okey Antonio Salazar Cardozo.
This is  the complet code:

final case class AddClient(userId: ObjectId, who: ABCClient)
final case class RemoveClient(who: ABCClient)

object ABCManager extends LiftActor with Loggable {
  var clients: Map[ObjectId, ABCClient] = Map.empty   // Here i have manage lift-actor for logged-in per user

def messageHandler: PartialFunction[Any, Unit] = {
   
case AddClient(userId, who) => clients += (userId -> who)
    case RemoveClient(who) => clients = clients.filter(_ ne who)
  }
}

class ABCClient extends CometActor with Loggable{
  val user = User.findCurrentUser
    override def localSetup(): Unit = {
    ABCManager ! AddClient(userId, this)
    super.localSetup()
  }

  override def localShutdown(): Unit = {
    ABCManager ! RemoveClient(this)
    super.localShutdown()
  }

override def lifespan: Box[TimeSpan] = Full(5 minutes)
def render: RenderOut = {
//some html rendering
}
}

and I have initiate comet-actor after user logged-in like this
home.html
<span lift="comet?type=ABCClient">
//html rendering
</span>


To unsubscribe from this group and stop receiving emails from it, send an email to liftweb+u...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Antonio Salazar Cardozo

unread,
Apr 17, 2014, 7:10:04 PM4/17/14
to lif...@googlegroups.com
At a glance, that looks right. The following is the behavior it should cause:
 - When you close all pages that have that comet on them, after 6 minutes tops, you should no
   longer have that comet in the clients object.
 - If you just log out in a way that doesn't destroy the actual underlying LiftSession, and you have
   no pages with that comet on them, it will still take about 5-6 minutes for the comet to disappear
   from the clients object.
 - If you destroy the LiftSession programmatically in the server, then it should disappear from the
   clients object immediately.

If this is not the behavior you're seeing, please create an example project as per
Thanks,
Antonio
Reply all
Reply to author
Forward
0 new messages