How to fail a channel.write() future in a channel handler?

"이희승 (Trustin Lee)" trustin at gmail.com
Mon Jul 12 03:49:20 EDT 2010


Hi Alex,

If I understood correctly, you seem to want to make some ChannelFutures
as done sooner, right?  If so, you can do this:

    ChannelFuture f = ch.write(msg);
    f.setCause(new Exception("failed"));
    // or
    f.setSuccess();

Please note the creating an exception costs a lot in Java.  If you
intend to use it only for some signaling, you'd better pre-create the
exception:

    private static final Exception SIGNAL = new Exception("signal");

    ChannelFuture f = ch.write(msg);
    f.setCause(SIGNAL);

HTH,
Trustin

On 07/09/2010 05:19 AM, Alex Wang wrote:
> 
> Hi all,
> 
> I have a client written in Netty.  When I write to the channel, I want to be
> able to cause the future.isSuccessful() to return false when certain
> conditions are met.  How do I do that?  Throwing an exception in the
> writeRequested() method does not seem to do that.
> 
> Thanks for your help.
> 
> Alex
> 

-- 
what we call human nature in actuality is human habit
http://gleamynode.net/

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 293 bytes
Desc: OpenPGP digital signature
Url : http://lists.jboss.org/pipermail/netty-users/attachments/20100712/acbea5a6/attachment.bin 


More information about the netty-users mailing list