ExecutionHandler problem
Marian Stranecky
marian.stranecky at mobilbonus.cz
Tue Dec 30 04:26:45 EST 2008
Thanks for your answer, Trustin.
I was just wondering if there is a more generic way to handle this. IMHO when there is an institute of ExecutionHandler we should be able to shutdown it transparently (e.g. by signaling somewhere in the pipeline).
Anyway, as far as I see, it should be handled now by this piece of code in "client" (to avoid pushing a referable instance of an Executor to the PipelineFactory):
ExecutionHandler execHandler = (ExecutionHandler) channel.getPipeline().get("executor");
ExecutorService es = (ExecutorService) execHandler.getExecutor();
es.shutdown();
Am I right?
TIA,
Marian
On Tuesday 30 of December 2008 07:48:48 Trustin Lee wrote:
> Hi Marian,
>
> You need to shut down the OrderedMemoryAwareThreadPoolExecutor that
> you've created by yourself. ChannelFactory.releaseExternalResources()
> will not shut down the Executor that is used by ExecutionHandler.
> Please call OrderedMemoryAwareThreadPoolExecutor.shutdown() after
> calling ChannelFactory.releaseExternalResources(), then everything
> should be cleaned up.
>
> HTH,
> Trustin
>
> On Tue, Dec 30, 2008 at 2:09 AM, Marian Stranecky
>
> <marian.stranecky at mobilbonus.cz> wrote:
> > Hi all,
> >
> > I would like to ask you for information of how to connect and shutdown
> > the client properly, because I have experienced a problem with netty
> > while trying to use an ExecutionHandler:
> > The threads created in OrderedMemoryAwareThreadPoolExecutor and used in
> > handling are running even after the channel is closed (e.g. closed by a
> > server after the channel is marked idle)
> >
> > Thanks in advance,
> >
> > Marian
> >
> > public ChannelPipeline getPipeline() throws Exception {
> >
> > ChannelPipeline pipeline = pipeline();
> >
> > // Add the number codec first,
> > pipeline.addLast("decoder", new MyMessageDecoder());
> > pipeline.addLast("encoder", new MyMessageEncoder());
> >
> > // utilize the processing
> > // pipeline.addLast("executor", new ExecutionHandler(new
> > OrderedMemoryAwareThreadPoolExecutor(16, 1048576, 1048576)));
> >
> >
> > // and then business logic.
> > pipeline.addLast("handler", new OISDClientHandler(this.client));
> >
> > return pipeline;
> > }
> >
> >
> > The client is as follows:
> >
> > public void connect(){
> > ExecutorService bossExecutor = Executors.newCachedThreadPool(new
> > CustomThreadFactory("bossExecutorPool"));
> > ExecutorService workerExecutor = Executors.newCachedThreadPool(new
> > CustomThreadFactory("workerExecutorPool"));
> >
> > ChannelFactory factory = new NioClientSocketChannelFactory(bossExecutor,
> > workerExecutor);
> >
> > ClientBootstrap bootstrap = new ClientBootstrap(factory);
> >
> > bootstrap.setPipelineFactory(new OISDClientPipelineFactory(this));
> >
> > HashMap<String, Object> opts = new HashMap<String, Object>();
> >
> > opts.put("tcpNoDelay", false);
> > opts.put("keepAlive", true);
> >
> > bootstrap.setOptions(opts);
> >
> > ChannelFuture connectFuture = bootstrap.connect(this.SMSCAddress);
> >
> > // Wait until the connection attempt succeeds or fails.
> > this.channel = connectFuture.awaitUninterruptibly().getChannel();
> >
> > if (!connectFuture.isSuccess()) {
> > log.error("Problem while connecting to " + this.SMSCAddress.toString(),
> > connectFuture.getCause());
> > return;
> > }
> >
> > // Wait for the server to close the connection.
> > channel.getCloseFuture().awaitUninterruptibly();
> >
> > // Shut down executor threads to exit.
> > factory.releaseExternalResources();
> > log.debug("resources released...");
> > }
> >
> >
> > _______________________________________________
> > netty-users mailing list
> > netty-users at lists.jboss.org
> > https://lists.jboss.org/mailman/listinfo/netty-users
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/netty-users/attachments/20081230/299a0a56/attachment.html
More information about the netty-users
mailing list