dev@grizzly.java.net

Re: When is TemporaySelectorReader used to handle I/0 mode( blocking / async) read operation

From: Oleksiy Stashok <Oleksiy.Stashok_at_Sun.COM>
Date: Wed, 18 Nov 2009 15:41:11 +0100

Hi Ming Qin,
TemporaySelectorReader should be used if StreamReader.isBlocking() is
true.
What IMO doesn't work is that when you change blocking mode of
Connection - it should propogate this mode to underlying StreamReader
and StreamWriter, which seems doesn't happen.

WBR,
Alexey.


> Issue number 762 is created for this bug.
> I submitted issue 673 related to Grizzly 2.0.0-M3 in middle of
> June 2009 , it seems still not yet fixed. I would give a try to fix
> this issue 762
> If you can explain that read should be type TemporaySelectorReader
> under conditions such as connection.configureBlocking(true) .AND.
> transport.configureBlocking(true),
>
> Ming Qin
> Cell Phone 858-353-2839
>
> --- On Mon, 11/16/09, Oleksiy Stashok <Oleksiy.Stashok_at_Sun.COM> wrote:
>
> From: Oleksiy Stashok <Oleksiy.Stashok_at_Sun.COM>
> Subject: Re: When is TemporaySelectorReader used to handle I/0
> mode( blocking / async) read operation
> To: dev_at_grizzly.dev.java.net
> Date: Monday, November 16, 2009, 2:56 AM
>
> Hi Ming Qin,
>
> it looks like a bug. Can you pls. file an issue?
>
> Thank you.
>
> WBR,
> Alexey.
>
> On Nov 16, 2009, at 7:04 , ming qin wrote:
>
>>
>>
>> Hi :
>>
>> I tested both methods( testSeveralPacketsEcho and testSimpleEcho)
>> in TCPNIOTransportTest.java by altering Boolean values of
>> transport.configureBlocking(boolean) and
>> connection.configureBlocking(bolean).
>>
>> In TCPNIOStreamReader.java, isBlocking() is always false, so
>> reader has no chance to be Type of TemapoarySelectorReady.
>>
>> Below is read0() snippet in TCPNIOStreamReader.java
>>
>> if (isBlocking()) {
>>
>> …….
>> try {
>> TemporarySelectorReader reader =
>> (TemporarySelectorReader)
>>
>> transport.getTemporarySelectorIO().getReader();
>> ………
>> ……..
>> return buffer;
>>
>> } else {
>> ……
>> Buffer buffer = newBuffer(bufferSize);
>>
>> ……
>> return buffer;
>> }
>> }
>>
>> Below is Boolean values were set up in
>> transport.configureBlocking(boolean) and
>> connection.configureBlocking(bolean),
>>
>>
>> transport.configureBlocking(boolean)
>> connection.configureBlocking(bolean);
>> I/O read operation performed by read0 in TCPNIOStreamReader
>> Value of Boolean
>> True
>> True
>> isBlocking() is false, read operation is preformed by
>> int readBytes = transport.read(connection, buffer);
>>
>> True
>>
>>
>> False
>> isBlocking() is false, read operation is preformed by
>> int readBytes = transport.read(connection, buffer);
>>
>>
>> False
>> False
>> isBlocking() is false, read operation is preformed by
>> int readBytes = transport.read(connection, buffer);
>>
>>
>> True
>> False
>> isBlocking() is false, read operation is preformed by
>> int readBytes = transport.read(connection, buffer);
>>
>>
>> Here is my testSimpleEcho() with adding one line of
>> transport.configureBlocking(true);
>>
>>
>> public void testSimpleEcho() throws Exception {
>> Connection connection = null;
>> StreamReader reader = null;
>> StreamWriter writer = null;
>> TCPNIOTransport transport =
>> TransportFactory.getInstance().createTCPTransport();
>> transport.getFilterChain().add(new TransportFilter());
>> transport.getFilterChain().add(new EchoFilter());
>>
>> try {
>> transport.bind(PORT);
>> transport.start();
>> transport.configureBlocking(true);
>>
>>
>>
>> Future<Connection> future =
>> transport.connect("localhost", PORT);
>> connection = (TCPNIOConnection) future.get(10,
>> TimeUnit.SECONDS);
>> assertTrue(connection != null);
>>
>> System.out.println (" $$$Connected " + ++ii + "
>> connected connection ");
>>
>> connection.configureBlocking(true);
>> connection.setProcessor(null);
>>
>> byte[] originalMessage = "Hello".getBytes();
>> writer = connection.getStreamWriter();
>> writer.writeByteArray(originalMessage);
>> Future<Integer> writeFuture = writer.flush();
>>
>> assertTrue("Write timeout", writeFuture.isDone());
>> assertEquals(originalMessage.length, (int)
>> writeFuture.get());
>>
>>
>> reader = connection.getStreamReader();
>> Future readFuture =
>> reader.notifyAvailable(originalMessage.length);
>> assertTrue("Read timeout", readFuture.get(10,
>> TimeUnit.SECONDS) != null);
>>
>> byte[] echoMessage = new byte[originalMessage.length];
>> reader.readByteArray(echoMessage);
>> assertTrue(Arrays.equals(echoMessage, originalMessage));
>>
>> } finally {
>> if (connection != null) {
>> connection.close();
>> }
>>
>> transport.stop();
>> TransportFactory.getInstance().close();
>> }
>> }
>>
>>
>> Ming Qin
>> 858-353-2839
>>
>