Re: [xSocket-develop] ClosedChannelException
Status: Inactive
Brought to you by:
grro
|
From: Gregor R. <gre...@go...> - 2008-11-05 07:08:15
|
Hi David,
the <connection>.readByteBufferByDelimiter(…) returns an array of byte
buffers. This doesn't mean, that several records (separated by a delimiter)
is fetched. If you get an array longer than 1, it just means that more than
one byte buffer is used to hold the record data. This is caused by a
fragmented network I/O read. For performance reasons xSocket doesn't merge
such fragmented byte buffers into a single buffer. xSocket's DataConverter
class supports a toByteBuffer(ByteBuffer[] buffers) method to do this (which
has performance impacts).
In your code you have also to ensure that your delimiter will never appear
as part of the serialized data. May be using a leading length filed would be
a better approach
Gregor
2008/11/5 David Alves <da...@st...>
> Hi
> I'm trying xsocket for the first time and I quite like the api and the
> features.
> I'm using a nonblockingpipeline over a multiplexed connection and all seems
> fine, until the channel closes and a ClosedChannelException is thrown.
> I'm reasearching some event processing mechanisms and as such I serialize
> objects across the client to the server, and it all boils down to the fact
> that I always can send 67 and just 67 events.
> Strange no?
> Any help would be greatly appreciated.
> My send/receive code along with the trace is in the end of the email.
>
> Kind regards
> David Alves
>
> ______________________
>
> Client: (All the connection creation code is done only once then a
> generating thread tries to send event through the pipeline)
>
> Creation:
> this.nativeConnection = new NonBlockingConnection(this.host, port,
> Integer.MAX_VALUE);
> this.multiplexedConnection = new MultiplexedConnection(nativeConnection);
> controlPipelineId = multiplexedConnection.createPipeline();
> controlPipeline = multiplexedConnection.getNonBlockingPipeline(
> controlPipelineId);
>
> Repeat:
> FastByteArrayOutputStream fbaos = new FastByteArrayOutputStream();
> ObjectOutputStream oos = new ObjectOutputStream(fbaos);
> oos.writeObject(event);
> ByteBuffer objectBuffer = fbaos.getByteBuffer();
> controlPipeline.write(objectBuffer);
> controlPipeline.write(EVENT_SEPARATOR);
>
> ________________
>
> Server: (Implements IPipelineDataHandler)
> ByteBuffer[] eventsBbs = pipeline
> .readByteBufferByDelimiter(DummyMultiplexedNonBockingAdapter.
> EVENT_SEPARATOR);
> for (ByteBuffer eventBb : eventsBbs) {
> FastByteArrayInputStream fbais = new FastByteArrayInputStream(eventBb);
> ObjectInputStream ois = new ObjectInputStream(fbais);
> Event event;
> try {
> event = (Event) ois.readObject();
> } catch (ClassNotFoundException e) {
> throw new IOException(e);
> }
> receiveEvent(event);
> }
>
> Trace:
>
> Caused by: java.nio.channels.ClosedChannelException
> at
> org.xsocket.connection.AbstractNonBlockingStream.ensureStreamIsOpenAndWritable(
> AbstractNonBlockingStream.java:1472)
> at org.xsocket.connection.AbstractNonBlockingStream.write(
> AbstractNonBlockingStream.java:1140)
> at
> pt.uc.dei.fincos.adapter.dummy.remote.DummyMultiplexedNonBockingAdapter.send(
> DummyMultiplexedNonBockingAdapter.java:72)
> ... 19 more
> java.lang.NullPointerException
> at
> pt.uc.dei.fincos.adapter.dummy.remote.DummyMultiplexedNonBockingAdapter.send(
> DummyMultiplexedNonBockingAdapter.java:72)
>
> -------------------------------------------------------------------------
> This SF.Net email is sponsored by the Moblin Your Move Developer's
> challenge
> Build the coolest Linux based applications with Moblin SDK & win great
> prizes
> Grand prize is a trip for two to an Open Source event anywhere in the world
> http://moblin-contest.org/redirect.php?banner_id=100&url=/
> _______________________________________________
> xSocket-develop mailing list
> xSo...@li...
> https://lists.sourceforge.net/lists/listinfo/xsocket-develop
>
>
|