ChannelSink.eventSunk() doesn't catch OPEN state with TRUE as value

"이희승 (Trustin Lee)" trustin at gmail.com
Wed Aug 12 00:01:27 EDT 2009


On 08/12/2009 12:26 PM, Rafael Marins wrote:
> 
> Hi Trustin,
> 
> On Aug 11, 2009, at 11:59 PM, Trustin Lee (via Nabble) wrote:
> 
>> Hi Rafael,
>>
>> A Channel is supposed to be open when it is constructed.  If you  
>> take a
>> look into the source code of a Channel implementation, you will find
>> that it triggers a channelOpen event in its constructor.  Therefore,
>> there is no need to send OPEN(TRUE) downstream - it's open already and
>> hence no need to request it.
> 
> I was also triggering the channelOpen event in my channel constructor,  
> but doing so I could't get notified on the ChannelSink about the  
> OPEN(TRUE). I would like to use the OPEN(TRUE) event on ChannelSink to  
> initialize the hardware device.
> 
> To overcome that issue I'm invoking the sink.eventSunk() method from  
> my channel constructor, just as below. Then, I handle the OPEN(TRUE)  
> on ChannelSink to trigger the channelOpen event.
> 
>          ChannelFuture future = future(this);
>          try {
>              sink.eventSunk(pipeline, new  
> DownstreamChannelStateEvent(this, future, OPEN, TRUE));
>          } catch (Throwable t) {
>              future.setFailure(t);
>              fireExceptionCaught(this, t);
>          }
> 
> It makes more sense, for me, since I had to initialize the hardware  
> device (as said before) and caught the channelOpen event on an upper  
> SimpleChannelHandler subclass to configure the ChannelConfig properly.  
> The ChannelConfig is later used during channelConnect phase.

You could simply initialize the device in the constructor.  Perhaps you
don't want the hardware control code spread over many classes?

The solution looks fine anyway, but I would simply define an init()
method in the ChannelSink implementation and call the init method
directly rather than handling the initialization in the eventSunk
method.  Either way will be fine anyway.

BTW, you might be the first user who implements a custom transport.  I'd
like to know what difficulties you are having so that I can make Netty
more extensible.  Please keep posting your story on this if you don't
mind. :)

Trustin


More information about the netty-users mailing list