001/*
002 * Licensed to the Apache Software Foundation (ASF) under one
003 *  or more contributor license agreements.  See the NOTICE file
004 *  distributed with this work for additional information
005 *  regarding copyright ownership.  The ASF licenses this file
006 *  to you under the Apache License, Version 2.0 (the
007 *  "License"); you may not use this file except in compliance
008 *  with the License.  You may obtain a copy of the License at
009 *
010 *    https://www.apache.org/licenses/LICENSE-2.0
011 *
012 *  Unless required by applicable law or agreed to in writing,
013 *  software distributed under the License is distributed on an
014 *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015 *  KIND, either express or implied.  See the License for the
016 *  specific language governing permissions and limitations
017 *  under the License.
018 *
019 */
020package org.apache.directory.ldap.client.api.future;
021
022
023import org.apache.directory.api.ldap.model.message.ExtendedRequest;
024import org.apache.directory.api.ldap.model.message.ExtendedResponse;
025import org.apache.directory.api.ldap.model.message.Response;
026import org.apache.directory.ldap.client.api.LdapConnection;
027
028
029/**
030 * A Future to manage ExtendedRequests.
031 *
032 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
033 */
034public class ExtendedFuture extends MultipleResponseFuture<Response>
035{
036    /** 
037     * The extendedRequest : we need it to find which request is associated 
038     * with a response, when this response has no name */
039    ExtendedRequest extendedRequest;
040    
041    /**
042     * Creates a new instance of ExtendedFuture.
043     *
044     * @param connection the LDAP connection
045     * @param messageId The associated messageId
046     */
047    public ExtendedFuture( LdapConnection connection, int messageId )
048    {
049        super( connection, messageId );
050    }
051
052
053    /**
054     * @return the extendedRequest
055     */
056    public ExtendedRequest getExtendedRequest()
057    {
058        return extendedRequest;
059    }
060
061
062    /**
063     * @param extendedRequest the extendedRequest to set
064     */
065    public void setExtendedRequest( ExtendedRequest extendedRequest )
066    {
067        this.extendedRequest = extendedRequest;
068    }
069
070
071    /**
072     * Set the associated Response in this Future
073     * 
074     * @param response The response to add into the Future
075     * @throws InterruptedException if the operation has been cancelled by client
076     */
077    public void set( ExtendedResponse response ) throws InterruptedException
078    {
079        if ( response.getResponseName() == null )
080        {
081            // Feed the response with the request's OID 
082            response.setResponseName( extendedRequest.getRequestName() );
083        }
084        
085        queue.add( response );
086    }
087
088
089    /**
090     * {@inheritDoc}
091     */
092    @Override
093    public String toString()
094    {
095        StringBuilder sb = new StringBuilder();
096
097        sb.append( "ExtendedFuture" ).append( super.toString() );
098
099        return sb.toString();
100    }
101}