Any way to re-use the Channel..

Trustin Lee (이희승) trustin at gmail.com
Sun Dec 28 21:03:05 EST 2008


Hi Wesly,

Unfortunately, there's no way to reuse a closed socket channel at this
moment.  You need to create a new socket channel once an existing
socket channel is closed.

There's a to-do item related with this though:

  * https://jira.jboss.org/jira/browse/NETTY-70

An idea to improve the feature request I've written would be appreciated.

Thanks,
Trustin

On Thu, Dec 18, 2008 at 3:09 PM, Wesly smith <weslysmith0 at gmail.com> wrote:
>
> It could be dummy question ...
>
> I tried to cache and re-use the channels in http case.
> Is there any way to achieve that?
>
> Currently, the way I am doing roughly is:
> ===================
> // first time, I getChannel from future.
>
> Channel c = future.getChannel();
> ...
> c.write(httpMsg);
> // cache the channels
> cachedChannels.appendChannel();
> ...
> // then in the messageReceived()
> // It seems I have to disconnect(), otherwise, the transaction wont finish.
> event.getChannel().disconnect();
>
> // later I want to re-use the channel and get this channel from cache.
> Channel ch = cachedChannels.getFreeChannel();
> if (ch.isConnected() == false)
> {
>   future = ch.connect(address);
> }
>
> But I got ClosedChannelException:
> NioClientSocketChannel(id: 48a7cec7-011e-1000-b33c-018557bf3f5e) - (cause:
> ClosedChannelException) java.nio.channels.ClosedChannelException
>   at
> sun.nio.ch.SocketChannelImpl.ensureOpenAndUnconnected(SocketChannelImpl.java:472)
>   at sun.nio.ch.SocketChannelImpl.connect(SocketChannelImpl.java:486)
>   at
> org.jboss.netty.channel.socket.nio.NioClientSocketPipelineSink.connect(NioClientSocketPipelineSink.java:143)
>   at
> org.jboss.netty.channel.socket.nio.NioClientSocketPipelineSink.eventSunk(NioClientSocketPipelineSink.java:108)
>   at org.jboss.netty.channel.Channels.connect(Channels.java:554)
>   at
> org.jboss.netty.channel.AbstractChannel.connect(AbstractChannel.java:166)
>
>
> ====
> Any idea or suggestion about re-use the Channel? I hope it will give me some
> performance advantage.
>
> --
> View this message in context: http://n2.nabble.com/Any-way-to-re-use-the-Channel..-tp1671789p1671789.html
> Sent from the Netty User Group mailing list archive at Nabble.com.
>
> _______________________________________________
> netty-users mailing list
> netty-users at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/netty-users
>
>



-- 
Trustin Lee, Principal Software Engineer, JBoss, a division of Red Hat
--
what we call human nature in actuality is human habit
--
http://gleamynode.net/



More information about the netty-users mailing list