I think I may have figured this out, the javadocs are a little
confusing.  In WriteFuture the javadocs say:

IoSession session = ...;
WriteFuture future = session.write(...);
// Wait until the message is completely written out to the O/S buffer.
future.join();

I thought the "Wait until the message is completely written out to the
O/S buffer." meant I have to put in some sort of locking/callback/etc
in order to get everything to happen at the right time.  I appears
that the join method actually will wait until everything is written.

Am I right here?

On 10/12/06, Mark <[EMAIL PROTECTED]> wrote:
I am finally getting the chance to get back into this.  The only way I
see this working is to use the java.util.concurrent.locks.Lock class.
Here is what I have so far...

public class MyHandler extends IoHandlerAdapter implements IoFutureListener {
.....
private Lock writeLock = new ReentrantLock();
private Condition locked = writeLock.newCondition();

public void operationComplete(IoFuture arg0) {
        locked.signal();
}

private void writeData( IoSession session, String msg )
{
       writeLock.tryLock();
        WriteFuture future = session.write( msg );
        future.addListener( this );

        try {
                System.out.println("Awaiting lock condition release...");
                locked.await();
                System.out.println("Lock condition released..");
        } catch (InterruptedException e) {
                e.printStackTrace();
        }

        writeLock.unlock();
}
}

Is there some other way of doing this, because I am running into
problems here?  I am stumped...

Thank you.


On 9/19/06, Niklas Therning <[EMAIL PROTECTED]> wrote:
> True! :)
>
> One thing though: if I use a listener like you suggest I think it will
> be called from within the SocketIoProcessor's worker thread, right? If
> that's the case it's very important not to do any heavy processing in
> such a callback otherwise that SocketIoProcessor would be completely
> blocked.
>
> Please correct me if I'm wrong.
>
> /Niklas
>
> Trustin Lee wrote:
> > On 9/19/06, Niklas Therning <[EMAIL PROTECTED]> wrote:
> >>
> >> Instead of blocking on the WriteFuture you may want to implement
> >> IoHandler.messageSent(). For every call to session.write() there will be
> >> a matching call to messageSent() once the message you wrote has been
> >> sent. This avoids blocking the current thread and should make things
> >> more scalable.
> >
> >
> > Or you can use IoFutureListener by adding a listener to the
> > WriteFuture.  :)
> >
> > Trustin
>
>

Reply via email to