Question on LocalChannel

Frederic Bregier fredbregier at free.fr
Tue Jul 7 17:45:36 EDT 2009


Hi Trustin,

I struggle for one week now on a problem I didn't realized before when using
LocalChannel.
There are two questions.

First let me say the reason I wanted to use LocalChannel.
I want to multiplex connections using several LocalChannels with one
NioChannel, and of course having several clients connecting to the server,
so several NioChannels (each one having possibly several LocalChannels).
Everything was ok (codec of multiplexing was quite easy using a hashmap and
the channel Id of the client LocalChannel).

Now I found out what I was believing as a bug of my code could be the
reason. I made a simple example (safely inspired from the LocalExample of
Netty so without any NioChannel, but just LocalChannels) that illustrates
the problem.
When I open any number of connections, everything is ok if the channel is
closed from client side.
But when I closed the connection from the server (LocalChannel), it then
refused any new connections.
To test this, you have to comment in/out the Channels.close(e.getChannel());
at lines 67 and 81 of LocalServerPipelineFactory class file. Only line 67
breaks the program (handleUpstream).

My misunderstanding (at least if it is intend and no a bug) was that I
believed that if I add a pipelineFactory (LocalServerPipelineFactory), I
will have the same behaviour than with usual Channel when using bootstrap,
that is to say that the child "server side" channel is a channel like others
and can be closed without "unbinding" or so the father channel that was
binded with the bootstrap. It seems that the "father" channel is closed or
so when I close the "child" channel from server side when handling Upstream.

So my first question is: is that normal?
On the example, it makes an exception
java.nio.channels.NotYetConnectedException.
On my code, it makes another exception but I didn't find the way to
reproduce it right now. I suppose they are related however. Here is a part
of the exception dump:
Not that the LocalPacketCodec.handleDownstream does simply
ctx.sendDownstream(e); as it is not a MessageEvent. It occurs when a new
client localChannel wants to connect to the LocalAddress and after a
previously server side localChannel was closed.

Caused by: java.net.ConnectException: connection refused
	at
org.jboss.netty.channel.local.LocalClientChannelSink.connect(LocalClientChannelSink.java:122)
[Netty-Jboss.jar:na]
	at
org.jboss.netty.channel.local.LocalClientChannelSink.eventSunk(LocalClientChannelSink.java:79)
[Netty-Jboss.jar:na]
	at
org.jboss.netty.channel.DefaultChannelPipeline$DefaultChannelHandlerContext.sendDownstream(DefaultChannelPipeline.java:791)
[Netty-Jboss.jar:na]
	at
openr66.protocol.localhandler.packet.LocalPacketCodec.handleDownstream(LocalPacketCodec.java:95)
[classes/:na]
	at
org.jboss.netty.channel.DefaultChannelPipeline.sendDownstream(DefaultChannelPipeline.java:590)
[Netty-Jboss.jar:na]
	at
org.jboss.netty.channel.DefaultChannelPipeline$DefaultChannelHandlerContext.sendDownstream(DefaultChannelPipeline.java:796)
[Netty-Jboss.jar:na]
	at
org.jboss.netty.channel.SimpleChannelHandler.connectRequested(SimpleChannelHandler.java:324)
[Netty-Jboss.jar:na]
	at
org.jboss.netty.channel.SimpleChannelHandler.handleDownstream(SimpleChannelHandler.java:289)
[Netty-Jboss.jar:na]
	at
org.jboss.netty.channel.DefaultChannelPipeline.sendDownstream(DefaultChannelPipeline.java:590)
[Netty-Jboss.jar:na]
	at
org.jboss.netty.channel.DefaultChannelPipeline.sendDownstream(DefaultChannelPipeline.java:585)
[Netty-Jboss.jar:na]
	at org.jboss.netty.channel.Channels.connect(Channels.java:767)
[Netty-Jboss.jar:na]
	at
org.jboss.netty.channel.AbstractChannel.connect(AbstractChannel.java:195)
[Netty-Jboss.jar:na]
	at
org.jboss.netty.bootstrap.ClientBootstrap$Connector.channelOpen(ClientBootstrap.java:287)
[Netty-Jboss.jar:na]
	at
org.jboss.netty.channel.SimpleChannelUpstreamHandler.handleUpstream(SimpleChannelUpstreamHandler.java:103)
[Netty-Jboss.jar:na]
	at
org.jboss.netty.channel.DefaultChannelPipeline.sendUpstream(DefaultChannelPipeline.java:567)
[Netty-Jboss.jar:na]
	at
org.jboss.netty.channel.DefaultChannelPipeline.sendUpstream(DefaultChannelPipeline.java:562)
[Netty-Jboss.jar:na]
	at org.jboss.netty.channel.Channels.fireChannelOpen(Channels.java:197)
[Netty-Jboss.jar:na]
	at
org.jboss.netty.channel.local.DefaultLocalChannel.<init>(DefaultLocalChannel.java:64)
[Netty-Jboss.jar:na]
	at
org.jboss.netty.channel.local.DefaultLocalClientChannelFactory.newChannel(DefaultLocalClientChannelFactory.java:48)
[Netty-Jboss.jar:na]
	at
org.jboss.netty.channel.local.DefaultLocalClientChannelFactory.newChannel(DefaultLocalClientChannelFactory.java:1)
[Netty-Jboss.jar:na]
	at
org.jboss.netty.bootstrap.ClientBootstrap.connect(ClientBootstrap.java:235)
[Netty-Jboss.jar:na]
	at
org.jboss.netty.bootstrap.ClientBootstrap.connect(ClientBootstrap.java:199)
[Netty-Jboss.jar:na]

Second, I did add in the example an ExecutionHandler but it changes nothing.
But is it ok (useful) to add such an ExecutionHandler in the pipeline of the
server side LocalChannel? My wish was to be sure to have separate threads
than the one used in the network Channel. I could live without (just have to
be careful then). I ask this question since I only see the same thread again
and again in my logs.

I join my example (placed in the same package of the example LocalExample).

http://n2.nabble.com/file/n3222132/LocalExampleMultiple.java
LocalExampleMultiple.java 
http://n2.nabble.com/file/n3222132/LocalServerPipelineFactory.java
LocalServerPipelineFactory.java 

Cheers,
Frederic

-----
Hardware/Software Architect
-- 
View this message in context: http://n2.nabble.com/Question-on-LocalChannel-tp3222132p3222132.html
Sent from the Netty Developer Group mailing list archive at Nabble.com.



More information about the netty-dev mailing list