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