I have a working Jersey/Atmosphere/Guice application which has two Atmosphere Resources. The first is pretty much a clone of the example chat application:
Just inject Broadcaster using the @PathParam annotation:
private @PathParam("topic") Broadcaster topic;
You can also use the @Context annotation. Hope that help.
-- Jeanfrancois
In the resource, suspend using the channel you want (the 'true' parameter to lookup() forces the channel to be created if it doesn't exist):
@Suspend( contentType = MediaType.APPLICATION_JSON, period = MAX_SUSPEND_MSEC )
@GET
public Broadcastable suspend( @Context final BroadcasterFactory factory )
{
return new Broadcastable( factory.lookup( MY_CHANNEL, true ) );
}
In the other code, which can be pretty much anywhere, broadcast to that channel:
Broadcaster broadcaster = BroadcasterFactory.getDefault().lookup( MY_CHANNEL );
if( broadcaster != null ) {
broadcaster.broadcast( message );
}
If you're going to be broadcasting from a resource method, you can annotate it instead (as shown in ChatResource's broadcast() method).