Google Groups

Re: [Lift] Getting port number

David Pollak Jul 13, 2011 5:59 AM
Posted in group: Lift
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:

   * Is this CometActor going to capture the initial Req
   * object?  If yes, override this method and return true
   * and override captureInitialReq to capture the Req.  Why
   * have to explicitly ask for the Req? In order to send Req
   * instances across threads, the Req objects must be snapshotted
   * which is the process of reading the POST or PUT body from the
   * HTTP request stream.  We don't want to do this unless we
   * have to, so by default the Req is not snapshotted/sent.  But
   * if you want it, you can have it.
  override def sendInitialReq_? : Boolean = true

And implementing:
   * Comet Actors live outside the HTTP request/response cycle.
   * However, it may be useful to know what Request led to the
   * creation of the CometActor.  You can override this method
   * and capture the initial Req object.  Note that keeping a reference
   * to the Req may lead to memory retention issues if the Req contains
   * large message bodies, etc.  It's optimal to capture the path
   * or capture any request parameters that you care about rather
   * the keeping the whole Req reference.
  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).

Your best bet is to create a SessionVar (or a few SessionVars) that hold the host and port.  Set those SessionVars from a snippet (if they are not already set).  Then access the SessionVars from your CometActors.

Hope this helps.



On Wed, Jul 13, 2011 at 4:24 AM, Channing <> wrote:
I need to be able to get the port number of the running app at runtime
and potentially from calls from Comet actors.  Using S doesn't work,
any other way?


You received this message because you are subscribed to the Google Groups "Lift" group.
To post to this group, send email to
To unsubscribe from this group, send email to
For more options, visit this group at

Lift, the simply functional web framework