Skip to content

Commit

Permalink
Fix Atmosphere broadcast.
Browse files Browse the repository at this point in the history
  • Loading branch information
dboissin committed Apr 24, 2011
1 parent 7d32ce2 commit af03eca
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 10 deletions.
27 changes: 27 additions & 0 deletions poc-scalatra/src/main/scala/poc/scalatra/dto/SimpleDTO.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package poc.scalatra.dto;

import java.io.Serializable;


public class SimpleDTO implements Serializable {

public SimpleDTO() {

}

public SimpleDTO(String content) {
this.content = content;
}

public String getContent() {
return content;
}

public void setContent(String content) {
this.content = content;
}

private String content;


}
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,35 @@ import org.atmosphere.annotation.Broadcast
import org.atmosphere.annotation.Suspend
import org.atmosphere.cpr.Broadcaster
import org.atmosphere.cpr.BroadcasterFactory
import org.atmosphere.cpr.DefaultBroadcaster
import org.atmosphere.jersey.JerseyBroadcaster
import org.atmosphere.jersey.Broadcastable
import org.codehaus.jettison.json.JSONException
import org.codehaus.jettison.json.JSONObject

import javax.ws.rs.GET
import javax.ws.rs.POST
import javax.ws.rs.Path
import javax.ws.rs.PathParam
import javax.ws.rs.FormParam
import javax.ws.rs.Produces
import poc.scalatra.dto.SimpleDTO

@Path("/topic")
@com.google.inject.Singleton
@Produces(Array("application/json"))
class MessageResource {


@GET
def titi(): String = {
"{blalfksl: 'felf'}"
@GET
@Suspend(outputComments = false, resumeOnBroadcast = false)
def listen():Broadcastable = {
val broadcaster = BroadcasterFactory.getDefault().lookup(classOf[JerseyBroadcaster], "topic", true)
new Broadcastable(new SimpleDTO("Connected !"), broadcaster)
}

@POST
@Broadcast
def publish(@FormParam("msg") message: String):Broadcastable = {
val broadcaster = BroadcasterFactory.getDefault().lookup(classOf[JerseyBroadcaster], "topic", true)
new Broadcastable(new SimpleDTO("Message : " + message), broadcaster)
}
// @Suspend(outputComments = true, resumeOnBroadcast = false)
// def listen():Broadcastable = {
// val broadcaster = BroadcasterFactory.getDefault().lookup(classOf[DefaultBroadcaster], "titi", true)
// new Broadcastable(new JSONObject().put("from", "system").put("msg", "Connected !"), broadcaster)
// }
}

0 comments on commit af03eca

Please sign in to comment.