Skip to content

Commit

Permalink
Closes lift#1162 Reacting to comet-timeouts
Browse files Browse the repository at this point in the history
  • Loading branch information
andreak committed Dec 15, 2011
1 parent e460bb9 commit f5774dc
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 2 deletions.
Expand Up @@ -72,8 +72,12 @@ object Comet extends DispatchSnippet with LazyLoggable {
case Full(AnswerRender(response, _, when, _)) =>
c.buildSpan(when, response.inSpan)

case _ =>
throw new CometTimeoutException("type: "+theType+" name: "+name)
case e =>
if (c.cometRenderTimeoutHandler().isDefined) {
c.cometRenderTimeoutHandler().open_!
} else {
throw new CometTimeoutException("type: "+theType+" name: "+name)
}
}}} openOr {
throw new CometNotFoundException("type: "+theType+" name: "+name)
}
Expand Down
32 changes: 32 additions & 0 deletions web/webkit/src/main/scala/net/liftweb/http/CometActor.scala
Expand Up @@ -403,6 +403,38 @@ trait LiftCometActor extends TypedActor[Any, Any] with ForwardableActor[Any, Any
*/
def cometProcessingTimeout = LiftRules.cometProcessingTimeout

/**
* This is to react to comet-requests timing out.
* When the timeout specified in {@link LiftRules#cometProcessingTimeout} occurs one may override
* this to send a message to the user informing of the timeout.
* <p/><p/>
* Do NOT manipulate actor-state here. If you want to manipulate state, send the actor a new message.
* <p/><p/>
* Typical example would be:
* <pre>
* override def cometTimeoutHandler(): JsCmd = {
* Alert("Timeout processing comet-request, timeout is: " + cometProcessingTimeout + "ms")
* }
* </pre>
*/
def cometProcessingTimeoutHandler(): JsCmd = Noop

/**
* This is to react to comet-actors timing out while initial rendering, calls to render().
* When the timeout specified in {@link LiftRules#cometRenderTimeout} occurs one may override
* this to customise the output.
* <p/><p/>
* Do NOT manipulate actor-state here. If you want to manipulate state, send the actor a new message.
* <p/><p/>
* Typical example would be:
* <pre>
* override def renderTimeoutHandler(): Box[NodeSeq] = {
* Full(&lt;div&gt;Comet {this.getClass} timed out, timeout is {cometRenderTimeout}ms&lt;/div&gt;)
* }
* </pre>
*/
def cometRenderTimeoutHandler(): Box[NodeSeq] = Empty

protected def initCometActor(theSession: LiftSession,
theType: Box[String],
name: Box[String],
Expand Down
Expand Up @@ -661,6 +661,7 @@ class LiftSession(private[http] val _contextPath: String, val uniqueId: String,
a.!?(a.cometProcessingTimeout, ActionMessageSet(f.map(i => buildFunc(i)), state)) match {
case Full(li: List[_]) => li
case li: List[_] => li
case Empty => Full(a.cometProcessingTimeoutHandler())
case other => Nil
})
case _ => f.map(i => buildFunc(i).apply())
Expand Down

0 comments on commit f5774dc

Please sign in to comment.