Hi folks,
I was reviewing DefaultIoFuture implementation in 1.1 which used
CountDownLatch and AtomicBoolean, and found a possible bug. Please
verify my idea.
Current implementation:
protected void setValue( Object newValue )
{
if( ready.compareAndSet( false, true ) )
{
result = newValue;
completionLatch.countDown();
notifyListeners();
}
}
public void addListener( IoFutureListener listener )
{
if( listener == null )
{
throw new NullPointerException( "listener" );
}
listeners.add( listener );
if( ready.get() )
{
listener.operationComplete( this );
}
}
A counter example:
1) A user calls the future's addListener().
2) addListener() adds the specified listener to the 'listeners'.
3) MINA calls the future's setValue(); all listeners including what
has just added are notified.
4) ready.get() returns true, so listener.operationComplete() is
invoked once again causing duplicate events.
Please let me know if I make a mistake. Otherwise I will revert it back.
Trustin
--
what we call human nature is actually human habit
--
http://gleamynode.net/
--
PGP Key ID: 0x0255ECA6