Is this correct way to implement GMail widget in Lift?

I'm trying to implement a GMail widget similar to those on iGoogle or Netvibse to practise how to use Comet in Lift web framework.

Currently what I have is the following code, its short and works amazingly.

But I'm not sure about is this best way to implement it. Because retrieve mails from GMail is a time-consuming job, and the following code only has one GMailListener, which will blocks when get mails from GMail.

I guess that means if there are two users on my website, for example UserA and UserB.

Although the following code is thread safe, but if they both on the page that using this Comet, UserB still have to wait until mail of UserA is processed to get his own result, right?

What is the best way to avoid the blocking?

import net.liftweb.util.Schedule
import net.liftweb.util.Helpers._
import net.liftweb.http.CometActor
import net.liftweb.http.js.JsCmds.SetHtml
import net.liftweb.http.js.jquery.JqJsCmds._

case class FetchGMail(userID: Int, sender: CometActor)
case class NewStuffs(mails: List[Stuff])

object GMailListener extends LiftActor
    def getMails(userID: Int) = {
        // Get Mails from GMail

    def messageHandler = {
        case FetchGMail(userID, sender) => 
            println("Get FetchMail request")
            sender ! NewStuffs(getMails(userID))
            Schedule.schedule(this, FetchGMail(userID, sender), 5 minutes)

class Inbox extends CometActor with JSImplicit
    def render = <div>Empty Inbox</div>

    GMailListener ! FetchGMail(1, this)

    override def lowPriority = {
        case NewStuffs(mails) => 
            println("get new mails")
            partialUpdate(AppendHtml("mails", <div>{mails}</div>))


Just keep in mind that an actor can only process one message at a time and will only consume resources when it is processing messages. Your GmailListener is a singleton, so it could be a bottleneck right now, but there is no reason you can't create an instance of GmailListener for each user. Each instance will only wake up and utilize a thread to do Gmail lookups when your schedule call dictates. Just make sure that you shut the corresponding GmailListener down when the Inbox shuts down. Take a look at net.liftweb.http.CometListener which I think should help with that.

Need Your Help

Creating two RoundedFields, JTextField and JPasswordField

java inheritance multiple-inheritance

Okay I have the following JTextField class. It creates a Rounded JTextField. Now I wanted to use the same setup for my JPasswordField since I thought that JPasswordField inherits from JTextField I ...

iOS cannot set UITextField text property in UITableViewCell

iphone ios objective-c cocoa-touch uitableview

I have a UITableView of 'people' for my iOS app. I have created an 'add' screen to add new people to my persistent store, which works perfectly.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.