Sharing a RequestVar Across CometActors

24 views
Skip to first unread message

Peter Robinett

unread,
Oct 12, 2009, 10:04:50 AM10/12/09
to Lift
Hi all,

I have a question about whether it's possible to access RequestVars in
CometActors (specifically, to access them in localSetup). I believe it
is, based upon a recent thread about sharing them among snippets[1]
and an older thread about Actors accessing S[2]. But first, some
background, as I may be going around this in totally the wrong way and
would appreciate your thoughts.

I am making a dashboard to display a bunch of data that will be coming
in (near) real-time and I want to use Comet to make sure the user
always sees the most update-to-date information in their dashboard. I
have a variety of different aggregate values to display that fall into
several categories together, so I can group the calculations together.
I think this sectioning will prove useful in the future, as I can
imagine wanting to display some but not all of these sections on
another page.

Because the CometActors all will need to know the dashboard to which
they belong, my thought was to share this Mapper instance via a
RequestVar.

I call my snippet like so:
<lift:Dashboard.display>
</lift:Dashboard.display>

The snippet defines a RequestVar called myDashboard and then returns a
NodeSeq:
<div>
<lift:comet type="DashboardHelper1">
</lift:comet>
// ....
<lift:comet type="DashboardHelperN">
</lift:comet>
</div>

While I can get this all to compile, myDashboard is empty in the
CometActors. I understand that CometActors basically exist outside of
the normal request cycle, so would this be the reason why my
RequestVar is always empty? I was hoping that it would still be in the
request cycle when localSetup is called, but I can see why that would
be unrealistic.

I just tried using SessionVar instead of a RequestVar and this works.
However, I'm worried about having to be more careful about emptying
the SessionVar if requesting a different dashboard than if I would if
I were using a RequestVar. Is this an unrealistic fear?

What do you think is the best way to proceed?

Thanks for your help,
Peter Robinett

[1]: http://groups.google.com/group/liftweb/browse_thread/thread/5cf4ae2ecd0d56b5
[2]: http://groups.google.com/group/liftweb/browse_thread/thread/274cfc9d25a1ab0b

David Pollak

unread,
Oct 12, 2009, 12:15:33 PM10/12/09
to lif...@googlegroups.com
On Mon, Oct 12, 2009 at 7:04 AM, Peter Robinett <pe...@bubblefoundry.com> wrote:

Hi all,

I have a question about whether it's possible to access RequestVars in
CometActors (specifically, to access them in localSetup). I believe it
is, based upon a recent thread about sharing them among snippets[1]
and an older thread about Actors accessing S[2]. But first, some
background, as I may be going around this in totally the wrong way and
would appreciate your thoughts.

I am making a dashboard to display a bunch of data that will be coming
in (near) real-time and I want to use Comet to make sure the user
always sees the most update-to-date information in their dashboard. I
have a variety of different aggregate values to display that fall into
several categories together, so I can group the calculations together.
I think this sectioning will prove useful in the future, as I can
imagine wanting to display some but not all of these sections on
another page.

Because the CometActors all will need to know the dashboard to which
they belong, my thought was to share this Mapper instance via a
RequestVar.

You can create messages to be sent to a CometActor upon setup:

for {
  session <- S.session
 } session.setupComet("Dashboard", Empty, ABunchOfInfo(sessionInfo))

When the "Dashboard" comet actor is created, it will be sent the ABunchOfInfo message.  In this way you can send current request state info to a CometActor.

Does this help?



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

Peter Robinett

unread,
Dec 8, 2009, 10:05:20 PM12/8/09
to Lift
This was from a while ago but I just wanted to note that it works
well, though I do have some issues with when render is then called,
since localSetup is no longer used.

Also, why does setupComet take a boxed name parameter?

Thanks,
Peter

On Oct 12, 8:15 am, David Pollak <feeder.of.the.be...@gmail.com>
wrote:
> >http://groups.google.com/group/liftweb/browse_thread/thread/5cf4ae2ec...
> > [2]:
> >http://groups.google.com/group/liftweb/browse_thread/thread/274cfc9d2...
>
> --
> Lift, the simply functional web frameworkhttp://liftweb.net
> Beginning Scalahttp://www.apress.com/book/view/1430219890

Peter Robinett

unread,
Dec 8, 2009, 10:28:32 PM12/8/09
to Lift
Specifically, I have:
case Setup(newDatacenter) => {
datacenter = Full(newDatacenter)
DatacenterBroker.datacenters(newDatacenter.id) ! AddAListener
(this)
DatacenterBroker.datacenters(newDatacenter.id) !? GetPackets
match {
case Packets(packets) => {
savePackets(packets)
reRender(true)
}
}
}

My problem is that reRender, while sending the data, doesn't seem to
be causing the new script code to be merged into the document's
<head>, leaving me with: <div><head><script>...</script></head></div>
in the body.

It's not clear to me whether the script contents are being evaluated
(I would think it shouldn't, since there should only be 1 head tag in
an HTML document) and, even if they are, whether anything happens
since they are all wrapped in a jQuery(document).ready() call.

Peter
Reply all
Reply to author
Forward
0 new messages