title: Atmosphere/Jersey bidirectional conversation
body: <p>I've seen a number of Atmosphere examples including pub-sub. I want to do something like pub-sub (client subscribes to a channel that is unique to that client; server periodically publishes to that channel), except that the client will send data to the server as well. The client will send data in response to data sent by the server and in other cases when something important happens on the client that the server needs to know about (which the server doesn't need to acknowledge).</p>
  
  <p>Is it even possible to do this with Atmosphere?</p>
  
  <p>It might look something like this:</p>
  
  <pre><code>@Stateless
  @Path("/id/{clientId}/key/{clientKey}")
  public class MyService {
      @POST
      @Produces("application/xml")
      @Consumes("application/xml")
      @Suspend
      public StreamingOutput subscribe(@PathParam("clientId") String clientId,
                                       @PathParam("clientKey") String clientKey,
                                       @Context Broadcaster broadcaster,
                                       InputStream body) {
          if (!authenticate(clientId, clientKey) {
              throw new WebApplicationException(401);
          }
          broadcaster.setID(clientId);
  
          // Do something here... Not sure what
      }
  }
  </code></pre>
  
  <p>But there are a couple of problems here:</p>
  
  <ol>
  <li>The incoming connection will suspend, so it won't be able to send anything to the server except when resumed via broadcast;</li>
  <li>Any usage of the <code>InputStream</code> will result in blocking I/O, which kind of defeats the purpose of using Atmosphere.</li>
  </ol>
  
  <p>Both of these problems could be solved simply by removing <code>@Suspend</code>, but then I'm in the thread-per-connection situation.</p>
  
  <p>I get the feeling that Atmosphere isn't going to be the appropriate technology here and perhaps I might have to do something a bit lower level. But I'm not sure how to go about it. Ideas?</p>
  
  <p><strong>Edit:</strong></p>
  
  <p>I can't find a straightforward way of parsing XML asynchronously anyway, so this whole thing is looking less like something that can be done asynchronously.</p>