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
>