Protected
Protected

Comet - Streaming AJAX


Module stability: IN PROGRESS

Table of Contents


Akka supports push/streaming REST/AJAX using the Atmosphere framework, which works together with JAX-RSannotations to provide streaming RESTful components.

In order to turn the REST beans into Comet services you have to annotate them with the Atmosphere annotations (along with the JAX-RS annotations):
  • @Suspend
    Annotate an endpoint method with @Suspend, and any incoming requests to this endpoint will be listening for Broadcasted messages on the specified entity.

  • @Broadcast
    Annotate another endpoint method with @Broadcast on the same entity and have the result of the method propagated to all listeners for this entity.

  • @Cluster(Array(classOf[AkkaClusterBroadcastFilter])) { val name = "uniquename" }
    Annotate the same endpoint as @Broadcast and give it a unique name, and now your comet app is cluster aware

If you deploy Akka in another JEE container, don't forget to add Akkas initialization and cleanup hook:
<web-app>
...
  <listener>
    <listener-class>se.scalablesolutions.akka.servlet.Initializer</listener-class>
  </listener>
...
</web-app>


If you deploy Akka in another container and you get a comet support detection problem and you have 'se.scalablesolutions.akka.comet.AkkaServlet' in your 'web.xml' you can simply provide it with an 'init-param' to specify which comet support you want to use:

<servlet>
  ...
  <init-param>
    <param-name>cometSupport</param-name>
    <param-value>org.atmosphere.container.CLASS_GOES_HERE</param-value>
  </init-param>
  ...
</servlet>

Options:
  • BlockingIOCometSupport
  • GoogleAppEngineCometSupport
  • GrizzlyCometSupport
  • JBossWebCometSupport
  • Jetty7CometSupport
  • JettyCometSupport
  • Servlet30Support
  • TomcatCometSupport
  • WebLogicCometSupport

Here is a little example of creating a comet-based publish/subscribe REST-bean.

@Path("/pubsub/")
@Produces(Array("text/plain;charset=ISO-8859-1"))
class PubSub {
  @GET
  @Suspend
  @Path("/topic/{topic}/")
  def subscribe(@PathParam("topic") Broadcaster topic) : Broadcastable = new Broadcastable("", topic)
 
  @GET
  @Broadcast
  @Path("/topic/{topic}/{message}/")
  @Cluster(Array(classOf[AkkaClusterBroadcastFilter])) { val name = "foo" }
  def say(@PathParam("topic") Broadcaster topic, @PathParam("message") message: String): Broadcastable =
    new Broadcastable(message, topic)
}
Home
close
Loading...
Home Turn Off "Getting Started"
close
Loading...