Version 1, last updated by Peter Robinett at 19 Jan 21:18 UTC

A frequent question that users have is how to pass information to a CometActor. Several users attempt to access S.param("something") only to discover that it is not available within the CometActor.

As David Pollak explained on the mailing list:

CometActors exist outside of the HTTP request/response cycle. This means that during the processing of a message in a CometActor, you don’t get to see the Req because there’s never a Req available as part of message processing.

Contrary to some of the posts on this thread, the S context is available as are SessionVars (but not RequestVars because the CometActor is outside of the scope of a request).

If you use the Req instance by overriding:

override def sendInitialReq_? : Boolean = true

And implementing:

override protected def captureInitialReq(initialReq: Box[Req]) { /* do something here */ }

You will still not capture the underlying ServletRequest because the Req instance is a copy and that copy nulls out the underlying ServletRequest because some containers reuse ServletRequest instances and that causes problems across threads (and everything in a CometActor is done in the Actor pool threads).

This means that the initial request which creates the CometActor (e.g. to mycometpage.html?country=uk) will be captured and can be used and perhaps saved. However, saving request data to a SessionVar using another snippet earlier on the CometActor’s page is the recommend way to make request information available to a CometActor.

LiftSession

Note that LiftSession also has two methods, setupComet and sendCometActorMessage, that can be used to send messages to CometActors.

For instance, you might send a message like so:

for (
  session <- S.session
  message <- S.param("message")
) {
  session.setupComet("myCometActor", Some("unique name, if you want it"), message)
}