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: Tue, 01 Dec 2009 11:17:06 +0100

Hi Ming Qin,

sorry for the late response (I was on vacation)..

> After adding an override method configureBlocking in
> TCPNIOConnection.java with below code snippet , blocking mode of
> Connection is propagated to StreamReader in the ctx(Context) related
> to main thread. Unfortunately, work-thread's StreamReader obtained
> form Context is not affected by Connection Blocking Setting.
>
> @Override
> public void configureBlocking(boolean isBlocking) {
> super.configureBlocking(isBlocking);
> this.streamReader.setBlocking(isBlocking);
> }

Ok, thank you. I'll double check this, when will commit changes to 2.0
branch.
>
>
>
> TransportFilter.java's initialzeContext method which assigns
> StreamReader to context accessed by worker thread.
That's fine.

> In Girzzly 1.5.0 the main thread was taking care
> SelectionKey.OP_CONNECT, worker-threads are processing
> SelectionKey.OP_READ.
>
> In Gizzly 2.0.0-M3 , both main and work-thread are processing
> SelectionKey.OP_READ. If my observation is true on thread's handling
> SelectionKey.OP_READ, IMO, Gizzly 1.5.0's implementation is straight.
>

Can you pls. elaborate this "both main and work-thread are processing
SelectionKey.OP_READ"?

Thanks.

WBR,
Alexey.

>
>
>
> Ming Qin
> Cell Phone 858-353-2839
>
> --- On Wed, 11/18/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: Wednesday, November 18, 2009, 6:41 AM
>
> 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
>>>
>>
>