dev@grizzly.java.net

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

From: ming qin <mingqin1_at_yahoo.com>
Date: Mon, 16 Nov 2009 15:25:23 -0800 (PST)

Hi Oleksiy Stashok:

  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 TCPNIOStreamReaderValue of Boolean TrueTrue isBlocking() is false, read operation is preformed byint readBytes = transport.read(connection, buffer); True  FalseisBlocking() is false, read operation is preformed byint readBytes = transport.read(connection, buffer);  FalseFalseisBlocking() is false, read operation is preformed byint readBytes = transport.read(connection, buffer);  TrueFalseisBlocking() is false, read operation is preformed byint 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 Qin858-353-2839