title: Is there a way to return a custom promise from channel.write() in Netty?
body: <p>I'm currently working on implementing a privacy preserving data mining algorithm. For the communication part between the different parties I'm using <a href="http://netty.io/" rel="nofollow">Netty 4.0</a>. The communication flow between the parties looks like this:</p>
  
  <pre><code>         -- multiplicationMsg --&gt; ... -- multiplicationMsg --&gt;
     P_{1}                                                       P_{N}
           &lt;-- multiplicationMsg -- ... &lt;-- multiplicationMsg --
  </code></pre>
  
  <p>where <code>P_{1}</code> is the master party that initiates and controls the whole computation. The logic for the secure multi-party multiplication is located in Netty <code>ChannelHandler</code>s. There is also another protocol for secure addition.</p>
  
  <p>At the moment I use a similar solution like <a href="http://normanmaurer.me/presentations/2014-eclipsecon-na-netty/slides.html#20.0" rel="nofollow">this</a>, shown by Norman Maurer from Netty core team, to get informed if a sub-protocol computation has finished. But that feels a bit like fighting against the framework.</p>
  
  <p>Is there a way to get a custom promise from <code>channel.write(msg)</code>, that will be created and fulfilled in the <code>ChannelPipeline</code>? In my example above, it should be fulfilled when <code>multiplicationMsg</code> arrives back at <code>P_{1}</code>.</p>
  
  <p><strong>Edit 1</strong></p>
  
  <p>This is what I normally do to write a message from outside of the <code>ChannelPipeline</code>:</p>
  
  <pre><code>ChannelFuture f = channel.write(msg);
  future.addListener(new ChannelFutureListener() {
      public void operationComplete(ChannelFuture future) {
           //do something with the future
      }
  });
  </code></pre>
  
  <p>The <code>ChannelFuture</code> <code>f</code> from the example above will be fulfilled, if the data could be written to the socket or if a failure occurs. But I need a way do get back a custom <code>Future</code> in addition to the <code>ChannelFuture</code>, somehow like:</p>
  
  <pre><code>ChannelFuture f = channel.write(msg);
  future.addListener(new ChannelFutureListener() {
      public void operationComplete(ChannelFuture future) {
           // I need something like the following
           if(future.isSuccess()) {
               Future myFuture = future.getMyFuture();
           }
      }
  });
  </code></pre>