Got it, thanks. 

-----Original Message-----
From: Emmanuel Lécharny [mailto:[email protected]] 
Sent: Saturday, January 30, 2016 7:48 PM
To: Apache Directory Developers List <[email protected]>
Subject: Re: Cursor to implement Closeable

Le 30/01/16 12:33, Zheng, Kai a écrit :
> Just did a search getting below. I thought it's the method we're talking 
> about.
> ====
> void close(Exception reason)
>
> Closes this Cursor and frees any resources it my have allocated. Repeated 
> calls to this method after this Cursor has already been called should not 
> fail with exceptions. The reason argument is the Exception instance thrown 
> instead of the standard CursorClosedException.
>
> Parameters:
>     reason - exception thrown when this Cursor is accessed after close 
> ====
>
> Not sure if it's a good practice to pass an exception as reason to a close 
> method, as least in Java.

The Javadoc is far from being clear. let me expose a bit of code where the 
usage is clearer :

    public boolean next() throws LdapException, CursorException
    {
        if ( done )
        {
            return false;
        }

        try
        {
            if ( future.isCancelled() )
            {
                response = null;
                done = true;
                return false;
            }

            response = future.get( timeout, timeUnit );
        }
        catch ( Exception e )
        {
            LdapException ldapException = new LdapException( 
LdapNetworkConnection.NO_RESPONSE_ERROR, e );

            // Send an abandon request
            if ( !future.isCancelled() )
            {
                future.cancel( true );
            }

            // close the cursor
            try
            {
                close( ldapException );
            }

Typiclaly, here, we have had no response to a future.get() call, and we should 
then close the cursor. Calling close() would not provide any information to the 
monitor that is used internally to store this information. It allows the 
application using the Future to know what has hapepned.

Reply via email to