You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@mina.apache.org by Trustin Lee <tr...@gmail.com> on 2007/05/16 08:22:08 UTC

A possible duplicate event emission because of the new DefaultIoFuture implementation in 1.1?

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

Re: A possible duplicate event emission because of the new DefaultIoFuture implementation in 1.1?

Posted by Trustin Lee <tr...@gmail.com>.
On 5/16/07, Trustin Lee <tr...@gmail.com> wrote:
> Please let me know if I make a mistake.  Otherwise I will revert it back.

I make a mistake of course.  I meant 'if I made a mistake'. ;)

Trustin
-- 
what we call human nature is actually human habit
--
http://gleamynode.net/
--
PGP Key ID: 0x0255ECA6

Re: A possible duplicate event emission because of the new DefaultIoFuture implementation in 1.1?

Posted by peter royal <pr...@apache.org>.
On May 15, 2007, at 11:22 PM, Trustin Lee wrote:
> I was reviewing DefaultIoFuture implementation in 1.1 which used
> CountDownLatch and AtomicBoolean, and found a possible bug.  Please
> verify my idea.

I think you're right. Might just be safest to use synchronization on  
the two methods to keep them from being executed in parallel?

-pete





-- 
proyal@apache.org - http://fotap.org/~osi