title: Design of a server push using netty
body: <p>in my second question on netty. We are just starting with it. And we have a design where we need to use <strike>HTTP with long polling</strike> HTTP Streaming. We are estimating from 5k - 50k connected users with an opened connection. We know tomcat won't handle, so we look over netty to accomplish the task.</p>
  
  <p>The design should be simple enough, but we can't use websockets (we would love to use hornetQ on top of netty with websocket/stomp support) but we can't.</p>
  
  <p>So basically we will have server pushing events (we may even use JS SSE to do that) in the connected clients.</p>
  
  <p>Clients will subscribe to an endpoint based on a url (like a queue on JMS, much much simpler though)</p>
  
  <p>So we will have a process on the server side that generate events and notifies the interested channels (we are using a simple observer pattern for this).</p>
  
  <p>So a channel subscribes to those process and then receive events from them.</p>
  
  <p>My question here today is to see if the design approach we used is the right one considering netty's architecture.</p>
  
  <pre><code>public void channelConnected(ChannelHandlerContext ctx, ChannelStateEvent e) throws Exception {
      service.subscribe(this);
      this.context = ctx;
      ctx.sendUpstream(e);
  }
  
  //this method gets called by the service when a server event happens
  public void onUpdate(String message) {
    ChannelBuffer buffer = Channels.buffer(message.getBytes().length());
    buffer.writeBytes(message.getBytes());
    ChannelFuture future = Channels.future(this.context.getChannel());
    future.addListener(ChannelFutureListener.CLOSE);
    Channels.write(this.context,future,buffer);
  }
  </code></pre>
  
  <p>Regards</p>