Package org.apache.directory.ldap.client.api.future

Examples of org.apache.directory.ldap.client.api.future.SearchFuture


            case SEARCH_RESULT_DONE:
                // Store the response into the responseQueue
                SearchResultDone searchResultDone = ( SearchResultDone ) response;

                SearchFuture searchFuture = ( SearchFuture ) responseFuture;

                if ( LOG.isDebugEnabled() )
                {
                    if ( searchResultDone.getLdapResult().getResultCode() == ResultCodeEnum.SUCCESS )
                    {
                        // Everything is fine, return the response
                        LOG.debug( "Search successful : {}", searchResultDone );
                    }
                    else
                    {
                        // We have had an error
                        LOG.debug( "Search failed : {}", searchResultDone );
                    }
                }

                // Store the response into the future
                searchFuture.set( searchResultDone );

                // Remove the future from the map
                removeFromFutureMaps( messageId );

                break;

            case SEARCH_RESULT_ENTRY:
                // Store the response into the responseQueue
                SearchResultEntry searchResultEntry = ( SearchResultEntry ) response;

                if ( schemaManager != null )
                {
                    searchResultEntry.setEntry( new DefaultEntry( schemaManager, searchResultEntry.getEntry() ) );
                }

                searchFuture = ( SearchFuture ) responseFuture;

                if ( LOG.isDebugEnabled() )
                {
                    LOG.debug( "Search entry found : {}", searchResultEntry );
                }

                // Store the response into the future
                searchFuture.set( searchResultEntry );

                break;

            case SEARCH_RESULT_REFERENCE:
                // Store the response into the responseQueue
                SearchResultReference searchResultReference = ( SearchResultReference ) response;

                searchFuture = ( SearchFuture ) responseFuture;

                if ( LOG.isDebugEnabled() )
                {
                    LOG.debug( "Search reference found : {}", searchResultReference );
                }

                // Store the response into the future
                searchFuture.set( searchResultReference );

                break;

            default:
                throw new IllegalStateException( "Unexpected response type " + response.getType() );
View Full Code Here


        int newId = messageId.incrementAndGet();
        searchRequest.setMessageId( newId );

        LOG.debug( "Sending request \n{}", searchRequest );

        SearchFuture searchFuture = new SearchFuture( this, searchRequest.getMessageId() );
        addToFutureMap( searchRequest.getMessageId(), searchFuture );

        // Send the request to the server
        writeRequest( searchRequest );

        // Check that the future hasn't be canceled
        if ( searchFuture.isCancelled() )
        {
            // Throw an exception here
            throw new LdapException( searchFuture.getCause() );
        }

        // Ok, done return the future
        return searchFuture;
    }
View Full Code Here

            String msg = "Cannot process a null searchRequest";
            LOG.debug( msg );
            throw new IllegalArgumentException( msg );
        }

        SearchFuture searchFuture = searchAsync( searchRequest );

        long timeout = getTimeout( searchRequest.getTimeLimit() );

        return new SearchCursorImpl( searchFuture, timeout, TimeUnit.MILLISECONDS );
    }
View Full Code Here

            case SEARCH_RESULT_DONE:
                // Store the response into the responseQueue
                SearchResultDone searchResultDone = ( SearchResultDone ) response;

                SearchFuture searchFuture = ( SearchFuture ) responseFuture;

                if ( LOG.isDebugEnabled() )
                {
                    if ( searchResultDone.getLdapResult().getResultCode() == ResultCodeEnum.SUCCESS )
                    {
                        // Everything is fine, return the response
                        LOG.debug( "Search successful : {}", searchResultDone );
                    }
                    else
                    {
                        // We have had an error
                        LOG.debug( "Search failed : {}", searchResultDone );
                    }
                }

                // Store the response into the future
                searchFuture.set( searchResultDone );

                // Remove the future from the map
                removeFromFutureMaps( messageId );

                break;

            case SEARCH_RESULT_ENTRY:
                // Store the response into the responseQueue
                SearchResultEntry searchResultEntry = ( SearchResultEntry ) response;

                if ( schemaManager != null )
                {
                    searchResultEntry.setEntry( new DefaultEntry( schemaManager, searchResultEntry.getEntry() ) );
                }

                searchFuture = ( SearchFuture ) responseFuture;

                if ( LOG.isDebugEnabled() )
                {
                    LOG.debug( "Search entry found : {}", searchResultEntry );
                }

                // Store the response into the future
                searchFuture.set( searchResultEntry );

                break;

            case SEARCH_RESULT_REFERENCE:
                // Store the response into the responseQueue
                SearchResultReference searchResultReference = ( SearchResultReference ) response;

                searchFuture = ( SearchFuture ) responseFuture;

                if ( LOG.isDebugEnabled() )
                {
                    LOG.debug( "Search reference found : {}", searchResultReference );
                }

                // Store the response into the future
                searchFuture.set( searchResultReference );

                break;

            default:
                throw new IllegalStateException( "Unexpected response type " + response.getType() );
View Full Code Here

        SearchRequestCodec request = createSearchMessage( searchRequest );

        LOG.debug( "-----------------------------------------------------------------" );
        LOG.debug( "Sending request \n{}", request );

        SearchFuture searchFuture = new SearchFuture( this, request.getMessageId() );
        addToFutureMap( request.getMessageId(), searchFuture );

        // Send the request to the server
        WriteFuture writeFuture = ldapSession.write( request );
View Full Code Here

     * @return A {@link Cursor} containing Entries and Referencs
     * @throws LdapException @TODO
     */
    public Cursor<SearchResponse> search( SearchRequest searchRequest ) throws LdapException
    {
        SearchFuture searchFuture = searchAsync( searchRequest );

        long timeout = getTimeout( searchRequest.getTimeout() );
       
        return new SearchCursor( searchFuture, timeout, TimeUnit.MILLISECONDS );
    }
View Full Code Here

                SearchResultDoneCodec searchResultDoneCodec = (SearchResultDoneCodec)response;
                searchResultDoneCodec.setMessageId( messageId );
                searchResultDoneCodec.addControl( response.getCurrentControl() );
                SearchResultDone searchResultDone = convert( searchResultDoneCodec );

                SearchFuture searchFuture = (SearchFuture)responseFuture;
               
                if ( searchFuture == null )
                {
                    LOG.error( "SearchFuture is null" );
                    throw new LdapException( "SearchFuture is null"  );
                }
               
                if ( LOG.isDebugEnabled() )
                {
                    if ( searchResultDone.getLdapResult().getResultCode() == ResultCodeEnum.SUCCESS )
                    {
                        // Everything is fine, return the response
                        LOG.debug( "Search successful : {}", searchResultDone );
                    }
                    else
                    {
                        // We have had an error
                        LOG.debug( "Search failed : {}", searchResultDone );
                    }
                }

                // Store the response into the future
                searchFuture.set( searchResultDone );
               
                // Remove the future from the map
                removeFromFutureMaps( messageId );

                break;

            case SEARCH_RESULT_ENTRY:
                // Store the response into the responseQueue
                SearchResultEntryCodec searchResultEntryCodec = (SearchResultEntryCodec)response;
                searchResultEntryCodec.setMessageId( messageId );
                searchResultEntryCodec.addControl( response.getCurrentControl() );

                SearchResultEntry srchEntry = convert( searchResultEntryCodec );

                searchFuture = (SearchFuture)responseFuture;
               
                if ( searchFuture == null )
                {
                    LOG.error( "SearchFuture is null" );
                    throw new LdapException( "SearchFuture is null"  );
                }
               
                if ( LOG.isDebugEnabled() )
                {
                    LOG.debug( "Search entry found : {}", srchEntry );
                }

                // Store the response into the future
                searchFuture.set( srchEntry );
               
                break;

            case SEARCH_RESULT_REFERENCE:
                // Store the response into the responseQueue
                SearchResultReferenceCodec searchResultReferenceCodec = (SearchResultReferenceCodec)response;
                searchResultReferenceCodec.setMessageId( messageId );
                searchResultReferenceCodec.addControl( response.getCurrentControl() );

                SearchResultReference searchResultReference = convert( searchResultReferenceCodec );

                searchFuture = (SearchFuture)responseFuture;
               
                if ( searchFuture == null )
                {
                    LOG.error( "SearchFuture is null" );
                    throw new LdapException( "SearchFuture is null"  );
                }
               
                if ( LOG.isDebugEnabled() )
                {
                    LOG.debug( "Search reference found : {}", searchResultReference );
                }

                // Store the response into the future
                searchFuture.set( searchResultReference );
               
                break;

            default:
                LOG.error( "~~~~~~~~~~~~~~~~~~~~~ Unknown message type {} ~~~~~~~~~~~~~~~~~~~~~", response
View Full Code Here

   
   
    @Test
    public void testAsyncSearch() throws Exception
    {
        SearchFuture searchFuture = connection.searchAsync( "ou=system", "(objectclass=*)", SearchScope.ONELEVEL, "*",
            "+" );
        int count = 0;
        SearchResponse searchResponse = null;
        do
        {
            searchResponse = ( SearchResponse ) searchFuture.get( 1000, TimeUnit.MILLISECONDS );
            assertNotNull( searchResponse );
            if( !( searchResponse instanceof SearchResultDone ) )
            {
                count++;
            }
View Full Code Here

        sr.setBaseDn( "ou=system" );
        sr.setScope( SearchScope.ONELEVEL );
        sr.setDerefAliases( AliasDerefMode.NEVER_DEREF_ALIASES );

        // Launch the search now
        SearchFuture searchFuture = connection.searchAsync( sr );
       
        SearchResponse searchResponse = null;
        int count = 0;
       
        do
        {
            searchResponse = searchFuture.get();
            count++;
           
            if ( count > 10 )
            {
                searchFuture.cancel( true );
                break;
            }
        }
        while ( !(searchResponse instanceof SearchResultDone ) );
       
        assertTrue( numEntries > count );
        assertTrue( searchFuture.isCancelled() );

        // Now do a simple synchronous search
        Cursor<SearchResponse> results = connection.search( sr );
       
        int n = -1;
View Full Code Here

        sr.setBase( new Dn( "ou=system" ) );
        sr.setScope( SearchScope.ONELEVEL );
        sr.setDerefAliases( AliasDerefMode.NEVER_DEREF_ALIASES );

        // Launch the search now
        SearchFuture searchFuture = connection.searchAsync( sr );

        Response searchResponse = null;
        int count = 0;

        do
        {
            searchResponse = searchFuture.get();
            count++;

            if ( count > 10 )
            {
                searchFuture.cancel( true );
                break;
            }
        }
        while ( !( searchResponse instanceof SearchResultDone ) );

        assertTrue( numEntries > count );
        assertTrue( searchFuture.isCancelled() );

        // Now do a simple synchronous search
        Cursor<Response> results = connection.search( sr );

        int n = -1;
View Full Code Here

TOP

Related Classes of org.apache.directory.ldap.client.api.future.SearchFuture

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.