You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@directory.apache.org by "Steven E. Harris" <se...@panix.com> on 2006/12/18 05:29:06 UTC

Trouble with WriteFuture.join() after IoSession.write()

I'm having trouble getting MINA to send outgoing data with the
IoSession.write() method. When I save the WriteFuture returned by
write() and attempt to call join() on the future, my program hangs. If
I don't call join(), my IoHandler.messageSent() method does get
called, and the data does go out as intended.

I started with the netcat example¹ and changed it only in the
IoHandler.sessionOpened() method, forcing some bytes to be written out
to provoke a response from the server:

,----
|    public void sessionOpened(IoSession session) throws Exception {
|       session.setIdleTime( IdleStatus.READER_IDLE, 10 );
| 
|       final byte[] CRLF = new byte[] { 0x0D, 0x0A };
|       final ByteBuffer buffer = ByteBuffer.allocate( 256 );
|       buffer.setAutoExpand( true );
|       final java.nio.charset.CharsetEncoder ce = java.nio.charset.Charset.defaultCharset().newEncoder();
|       buffer.putString( "GET http://www.w3.org/ HTTP/1.1", ce );
|       buffer.put( CRLF );
|       buffer.putString( "Host: www.w3.org", ce );
|       buffer.put( CRLF );
|       buffer.put( CRLF );
|       final org.apache.mina.common.WriteFuture future = session.write( buffer.flip() );
|       future.join();
|     }
`----

If I comment out the future.join() call, the program works fine.

This behavior occurs with the MINA trunk source (revision 488118)
running on Java SE 6 (1.6.0) on Windows XP.

Am I using WriteFuture.join() incorrectly()?


Footnotes: 
¹ http://svn.apache.org/viewvc/mina/trunk/example/src/main/java/org/apache/mina/example/netcat/

-- 
Steven E. Harris


Re: Trouble with WriteFuture.join() after IoSession.write()

Posted by Trustin Lee <tr...@gmail.com>.
Hi Steven,

First off, we have a mailing list dedicated to Apache MINA.  Please refer to
this page:

http://mina.apache.org/mailing-lists.html

On 12/18/06, Steven E. Harris <se...@panix.com> wrote:
>
> I'm having trouble getting MINA to send outgoing data with the
> IoSession.write() method. When I save the WriteFuture returned by
> write() and attempt to call join() on the future, my program hangs. If
> I don't call join(), my IoHandler.messageSent() method does get
> called, and the data does go out as intended.
>
> I started with the netcat example¹ and changed it only in the
> IoHandler.sessionOpened() method, forcing some bytes to be written out
> to provoke a response from the server:
>
> ,----
> |    public void sessionOpened(IoSession session) throws Exception {
> |       session.setIdleTime( IdleStatus.READER_IDLE, 10 );
> |
> |       final byte[] CRLF = new byte[] { 0x0D, 0x0A };
> |       final ByteBuffer buffer = ByteBuffer.allocate( 256 );
> |       buffer.setAutoExpand( true );
> |       final java.nio.charset.CharsetEncoder ce =
> java.nio.charset.Charset.defaultCharset().newEncoder();
> |       buffer.putString( "GET http://www.w3.org/ HTTP/1.1", ce );
> |       buffer.put( CRLF );
> |       buffer.putString( "Host: www.w3.org", ce );
> |       buffer.put( CRLF );
> |       buffer.put( CRLF );
> |       final org.apache.mina.common.WriteFuture future = session.write(
> buffer.flip() );
> |       future.join();
> |     }
> `----
>
> If I comment out the future.join() call, the program works fine.
>
> This behavior occurs with the MINA trunk source (revision 488118)
> running on Java SE 6 (1.6.0) on Windows XP.
>
> Am I using WriteFuture.join() incorrectly()?


No, you are using it correctly.  It is because I recently removed
ThreadModel interface from the trunk.  Currently all examples are running in
a single thread mode.  Calling WriteFuture.join() will cause a deadlock
situation because what you are waiting for is what you called from.  Please
try to add an ExecutorFilter to the filter chain.  We will fix this problem
soon...

HTH,
Trustin
-- 
what we call human nature is actually human habit
--
http://gleamynode.net/
--
PGP key fingerprints:
* E167 E6AF E73A CBCE EE41  4A29 544D DE48 FE95 4E7E
* B693 628E 6047 4F8F CFA4  455E 1C62 A7DC 0255 ECA6