Puzzle in org.jboss.netty.example.local.LocalServerPipelineFactory.java

"Trustin Lee (이희승)" trustin at gmail.com
Tue Apr 6 05:43:15 EDT 2010


Hi,

Strictly speaking, the Executor instance that is used by
ExecutionHandler must be shared.  ExecutionHandler itself doesn't need
to be shared.  However, it's a better idea to share ExecutionHandler
together because you don't need to create a new handler instance
unnecessarily.

Thanks for asking a good question.  I've just updated the example.

Cheers,
Trustin

Peng Fei Di wrote:
> Hi all,
> 
> As Trustin said in the api of ExecutionHandler, the executionHandler
> instance must be shared in the method getPipeline(), just like below code:
> 
> public class DatabaseGatewayPipelineFactory implements
> ChannelPipelineFactory {
> 
>      private final ExecutionHandler executionHandler;
> 
>      public DatabaseGatewayPipelineFactory(ExecutionHandler
> executionHandler) {
>          this.executionHandler = executionHandler;
>      }
> 
>      public ChannelPipeline getPipeline() {
>          return Channels.pipeline(
>                  new DatabaseGatewayProtocolEncoder(),
>                  new DatabaseGatewayProtocolDecoder(),
>                  executionHandler, // Must be shared
>                  new DatabaseQueryingHandler());
>      }
>  }
>  ...
> 
>  public static void main(String[] args) {
>      ServerBootstrap bootstrap = ...;
>      ...
>      ExecutionHandler executionHandler = new ExecutionHandler(
>              new OrderedMemoryAwareThreadPoolExecutor(16, 1048576, 1048576))
>      bootstrap.setPipelineFactory(
>              new DatabaseGatewayPipelineFactory(executionHandler));
>      ...
>      bootstrap.bind(...);
>      ...
> 
>      while (!isServerReadyToShutDown()) {
>          // ... wait ...
>      }
> 
>      bootstrap.releaseExternalResources();
>      executionHandler.releaseExternalResources();
>  }
> 
> 
> But in org.jboss.netty.example.local.LocalServerPipelineFactory.java(line
> 50), I found that the executionHandler instance will be created and added
> into the pipeline everytime in the method getPipeline() althought all these
> executionHandler instances will share the same eventExecutor.
> So I am thinking about whether the LocalServerPipelineFactory.java is ok. I
> want to know whether the executionHandler instance should be shared, or we
> just only need to share the eventExecutor instance? And is there any
> difference between them?
> 
> Thanks!
> 
> Best regards

-- 
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: 260 bytes
Desc: OpenPGP digital signature
Url : http://lists.jboss.org/pipermail/netty-users/attachments/20100406/8e102ea6/attachment-0001.bin 


More information about the netty-users mailing list