A new project called atmosphere has popped up that aims to make writing and deploying cometd application really easy. You don't need to install any fancy web containers such as grizzly, just drop a war in whatever you are current using. It then appears to make use of facilities as they are available. (for example Servlet 3.0)
The basic examples look interesting; but where the power seems to come with when combined with Jersey. So you can write a service that looks like this:
@Suspend @GET @Produces("text/html") public String cometGet() { return "\n"; } @Broadcast @Consumes("application/x-www-form-urlencoded") @POST @Produces("text/html") public String cometPost(MultivaluedMapform) { String action = form.getFirst("action"); String name = form.getFirst("name"); if ("login".equals(action)) { return BEGIN_SCRIPT_TAG + toJsonp("System Message", name + " has joined.") + END_SCRIPT_TAG; } else if ("post".equals(action)) { return BEGIN_SCRIPT_TAG + toJsonp(name, form.getFirst("message")) + END_SCRIPT_TAG; } else { throw new WebApplicationException(422); } } @OnBroadcast public String cometPush(String s) { System.out.println("cometPush: " + s); return s; }
Hopefully the full text of this example will be up on the site as promised soon.
There is a BOF-5009 late Tuesday night which I will try to attend jet lag allowing. But this really does appear to make cometd service in Java real easy... now I wonder if it deploys to AppEngine yet...
No comments:
Post a Comment