title: Java client peer-to-multipeer using Netty
body: <p>I'm writing a process which must connect (and keep alive) to several (hundreds) remote peers and manage messaging / control over them.</p>
  
  <p>I made two versions of this software: first with classic "thread-per-connection" model, the second using standard java NIO and selectors (to reduce thread allocation, but has problems). Then, looking around I found Netty can boost a lot in most cases and I started a third one using it. My goal is to keep resource usage quite low keeping it fast.</p>
  
  <p>Once written the pipeline factory with custom events and dynamic handler switching, I stopped on the most superficial part: its allocation.
  All the examples I read use a single client with single connection, so I got the doubt: <em>I set up a <code>ChannelFactory</code> and a <code>PipelineFactory</code>, so every <code>(new ClientBootstrap(factory)).connect(address)</code> makes a new channel with a new pipeline. Is it possible to make a shared pipeline and defer business logic to a thread-pool?</em>
  If so, how?</p>
  
  <p>Using standard java NIO I managed to use two small small thread pools (threads &lt; remote peers) taking advantage of selectors; I had, however, troubles on recycling listened channels for writing.</p>
  
  <p>Communication should happen through a single channel which can receive timed messages from the remote peer or make a 3-way control (command-ack-ok).</p>
  
  <p>On second hand: once the event as reached the last handler, what happens? Is it there I extract it or can I extract a message from any point?</p>