From commits-return-24778-apmail-directory-commits-archive=directory.apache.org@directory.apache.org Thu Feb 04 23:52:20 2010 Return-Path: Delivered-To: apmail-directory-commits-archive@www.apache.org Received: (qmail 58744 invoked from network); 4 Feb 2010 23:52:20 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 4 Feb 2010 23:52:20 -0000 Received: (qmail 7942 invoked by uid 500); 4 Feb 2010 23:52:20 -0000 Delivered-To: apmail-directory-commits-archive@directory.apache.org Received: (qmail 7883 invoked by uid 500); 4 Feb 2010 23:52:20 -0000 Mailing-List: contact commits-help@directory.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@directory.apache.org Delivered-To: mailing list commits@directory.apache.org Received: (qmail 7874 invoked by uid 99); 4 Feb 2010 23:52:20 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 04 Feb 2010 23:52:20 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 04 Feb 2010 23:52:19 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 04E4223889F7; Thu, 4 Feb 2010 23:51:59 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r906739 - /directory/clients/ldap/trunk/ldap-client-api/src/main/java/org/apache/directory/ldap/client/api/LdapConnection.java Date: Thu, 04 Feb 2010 23:51:58 -0000 To: commits@directory.apache.org From: elecharny@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20100204235159.04E4223889F7@eris.apache.org> Author: elecharny Date: Thu Feb 4 23:51:58 2010 New Revision: 906739 URL: http://svn.apache.org/viewvc?rev=906739&view=rev Log: Consolidated some generics constructions Modified: directory/clients/ldap/trunk/ldap-client-api/src/main/java/org/apache/directory/ldap/client/api/LdapConnection.java Modified: directory/clients/ldap/trunk/ldap-client-api/src/main/java/org/apache/directory/ldap/client/api/LdapConnection.java URL: http://svn.apache.org/viewvc/directory/clients/ldap/trunk/ldap-client-api/src/main/java/org/apache/directory/ldap/client/api/LdapConnection.java?rev=906739&r1=906738&r2=906739&view=diff ============================================================================== --- directory/clients/ldap/trunk/ldap-client-api/src/main/java/org/apache/directory/ldap/client/api/LdapConnection.java (original) +++ directory/clients/ldap/trunk/ldap-client-api/src/main/java/org/apache/directory/ldap/client/api/LdapConnection.java Thu Feb 4 23:51:58 2010 @@ -73,6 +73,7 @@ import org.apache.directory.ldap.client.api.message.ModifyRequest; import org.apache.directory.ldap.client.api.message.ModifyResponse; import org.apache.directory.ldap.client.api.message.Referral; +import org.apache.directory.ldap.client.api.message.Response; import org.apache.directory.ldap.client.api.message.SearchRequest; import org.apache.directory.ldap.client.api.message.SearchResponse; import org.apache.directory.ldap.client.api.message.SearchResultDone; @@ -196,7 +197,8 @@ private Map futureMap = new ConcurrentHashMap(); /** a map to hold the response queues related to the operations */ - private Map respQueueMap = new ConcurrentHashMap(); + private Map> respQueueMap = + new ConcurrentHashMap>(); /** list of controls supported by the server */ private List supportedControls; @@ -713,10 +715,10 @@ message.setProtocolOP( addReqCodec ); - BlockingQueue addResponseQueue = new LinkedBlockingQueue(); + BlockingQueue addResponseQueue = new LinkedBlockingQueue(); respQueueMap.put( newId, addResponseQueue ); - ResponseFuture addFuture = new ResponseFuture( addResponseQueue ); + ResponseFuture addFuture = new ResponseFuture( addResponseQueue ); futureMap.put( newId, addFuture ); // Send the request to the server @@ -1179,7 +1181,7 @@ LOG.debug( "-----------------------------------------------------------------" ); LOG.debug( "Sending request \n{}", bindMessage ); - BlockingQueue bindResponseQueue = new LinkedBlockingQueue(); + BlockingQueue bindResponseQueue = new LinkedBlockingQueue(); respQueueMap.put( newId, bindResponseQueue ); // Create a future for this Bind opeation @@ -1362,7 +1364,7 @@ LOG.debug( "-----------------------------------------------------------------" ); LOG.debug( "Sending request \n{}", searchMessage ); - BlockingQueue searchResponseQueue = new LinkedBlockingQueue(); + BlockingQueue searchResponseQueue = new LinkedBlockingQueue(); respQueueMap.put( newId, searchResponseQueue ); ResponseFuture searchFuture = new ResponseFuture( searchResponseQueue ); @@ -1547,14 +1549,17 @@ futureMap.remove( addRespCodec.getMessageId() ); AddListener addListener = ( AddListener ) listenerMap.remove( addRespCodec.getMessageId() ); AddResponse addResp = convert( addRespCodec ); + if ( addListener != null ) { addListener.entryAdded( this, addResp ); } else { - addToRespQueueAndRemoveQueueRef( messageId, addResp ); + BlockingQueue respQueue = (BlockingQueue)respQueueMap.remove( messageId ); + respQueue.add( addResp ); } + break; case LdapConstants.BIND_RESPONSE: @@ -1588,7 +1593,8 @@ } // Store the response into the responseQueue - addToRespQueueAndRemoveQueueRef( messageId, bindResponse ); + BlockingQueue bindResponseQueue = (BlockingQueue)respQueueMap.remove( messageId ); + bindResponseQueue.add( bindResponse ); break; @@ -1597,18 +1603,20 @@ CompareResponseCodec compResCodec = response.getCompareResponse(); compResCodec.setMessageId( messageId ); compResCodec.addControl( response.getCurrentControl() ); - CompareResponse compRes = convert( compResCodec ); + CompareResponse compareResponse = convert( compResCodec ); - futureMap.remove( compRes.getMessageId() ); + futureMap.remove( compareResponse.getMessageId() ); - CompareListener listener = ( CompareListener ) listenerMap.remove( compRes.getMessageId() ); + CompareListener listener = ( CompareListener ) listenerMap.remove( compareResponse.getMessageId() ); + if ( listener != null ) { - listener.attributeCompared( this, compRes ); + listener.attributeCompared( this, compareResponse ); } else { - addToRespQueueAndRemoveQueueRef( messageId, compRes ); + BlockingQueue compareResponseQueue = (BlockingQueue)respQueueMap.remove( messageId ); + compareResponseQueue.add( compareResponse ); } break; @@ -1618,18 +1626,19 @@ DelResponseCodec delRespCodec = response.getDelResponse(); delRespCodec.setMessageId( messageId ); delRespCodec.addControl( response.getCurrentControl() ); - DeleteResponse delResp = convert( delRespCodec ); + DeleteResponse delResponse = convert( delRespCodec ); - futureMap.remove( delResp.getMessageId() ); - DeleteListener delListener = ( DeleteListener ) listenerMap.remove( delResp.getMessageId() ); + futureMap.remove( delResponse.getMessageId() ); + DeleteListener delListener = ( DeleteListener ) listenerMap.remove( delResponse.getMessageId() ); if ( delListener != null ) { - delListener.entryDeleted( this, delResp ); + delListener.entryDeleted( this, delResponse ); } else { - addToRespQueueAndRemoveQueueRef( messageId, delResp ); + BlockingQueue delResponseQueue = (BlockingQueue)respQueueMap.remove( messageId ); + delResponseQueue.add( delResponse ); } break; @@ -1649,7 +1658,8 @@ else { // Store the response into the responseQueue - addToRespQueueAndRemoveQueueRef( messageId, extResponse ); + BlockingQueue extendedResponseQueue = (BlockingQueue)respQueueMap.remove( messageId ); + extendedResponseQueue.add( extResponse ); } break; @@ -1664,6 +1674,7 @@ IntermediateResponse intrmResp = convert( intermediateResponseCodec ); IntermediateResponseListener intrmListener = ( IntermediateResponseListener ) listenerMap .get( intermediateResponseCodec.getMessageId() ); + if ( intrmListener != null ) { intrmListener.responseReceived( this, intrmResp ); @@ -1671,7 +1682,8 @@ else { // Store the response into the responseQueue - addToRespQueueAndRemoveQueueRef( messageId, intrmResp ); + BlockingQueue intermediateResponseQueue = (BlockingQueue)respQueueMap.remove( messageId ); + intermediateResponseQueue.add( intrmResp ); } break; @@ -1691,8 +1703,10 @@ } else { - addToRespQueueAndRemoveQueueRef( messageId, modResp ); + BlockingQueue modifyResponseQueue = (BlockingQueue)respQueueMap.remove( messageId ); + modifyResponseQueue.add( modResp ); } + break; case LdapConstants.MODIFYDN_RESPONSE: @@ -1704,6 +1718,7 @@ futureMap.remove( modDnCodec.getMessageId() ); ModifyDnListener modDnListener = ( ModifyDnListener ) listenerMap.remove( modDnCodec.getMessageId() ); + if ( modDnListener != null ) { modDnListener.modifyDnCompleted( this, modDnResp ); @@ -1711,8 +1726,10 @@ else { // Store the response into the responseQueue - addToRespQueueAndRemoveQueueRef( messageId, modDnResp ); + BlockingQueue modDnResponseQueue = (BlockingQueue)respQueueMap.remove( messageId ); + modDnResponseQueue.add( modDnResp ); } + break; case LdapConstants.SEARCH_RESULT_DONE: @@ -1725,13 +1742,15 @@ futureMap.remove( searchResultDoneCodec.getMessageId() ); // search listener has to be removed from listener map only here searchListener = ( SearchListener ) listenerMap.remove( searchResultDoneCodec.getMessageId() ); + if ( searchListener != null ) { searchListener.searchDone( this, srchDone ); } else { - addToRespQueueAndRemoveQueueRef( messageId, srchDone ); + BlockingQueue searchDoneResponseQueue = (BlockingQueue)respQueueMap.remove( messageId ); + searchDoneResponseQueue.add( srchDone ); } break; @@ -1752,7 +1771,8 @@ else { // shouldn't call addToRespQueueAndRemoveQueueRef - respQueueMap.get( messageId ).add( srchEntry ); + BlockingQueue searchResponsequeue = (BlockingQueue)respQueueMap.get( messageId ); + searchResponsequeue.add( srchEntry ); } break; @@ -1765,6 +1785,7 @@ SearchResultReference srchRef = convert( searchResultReferenceCodec ); searchListener = ( SearchListener ) listenerMap.get( searchResultReferenceCodec.getMessageId() ); + if ( searchListener != null ) { searchListener.referralFound( this, srchRef ); @@ -1772,7 +1793,8 @@ else { // shouldn't call addToRespQueueAndRemoveQueueRef - respQueueMap.get( messageId ).add( srchRef ); + BlockingQueue searchResponsequeue = (BlockingQueue)respQueueMap.get( messageId ); + searchResponsequeue.add( srchRef ); } break; @@ -1839,7 +1861,7 @@ modifyMessage.setProtocolOP( modReqCodec ); setControls( modRequest.getControls(), modifyMessage ); - BlockingQueue modifyResponseQueue = new LinkedBlockingQueue(); + BlockingQueue modifyResponseQueue = new LinkedBlockingQueue(); respQueueMap.put( newId, modifyResponseQueue ); ResponseFuture modifyFuture = new ResponseFuture( modifyResponseQueue ); @@ -2023,7 +2045,7 @@ modifyDnMessage.setProtocolOP( modDnCodec ); setControls( modDnRequest.getControls(), modifyDnMessage ); - BlockingQueue modifyDNResponseQueue = new LinkedBlockingQueue(); + BlockingQueue modifyDNResponseQueue = new LinkedBlockingQueue(); respQueueMap.put( newId, modifyDNResponseQueue ); ResponseFuture modifyDNFuture = new ResponseFuture( modifyDNResponseQueue ); @@ -2314,7 +2336,7 @@ deleteMessage.setProtocolOP( delCodec ); setControls( delRequest.getControls(), deleteMessage ); - BlockingQueue deleteResponseQueue = new LinkedBlockingQueue(); + BlockingQueue deleteResponseQueue = new LinkedBlockingQueue(); respQueueMap.put( newId, deleteResponseQueue ); ResponseFuture deleteFuture = new ResponseFuture( deleteResponseQueue ); @@ -2551,7 +2573,7 @@ message.setProtocolOP( compareReqCodec ); - BlockingQueue compareResponseQueue = new LinkedBlockingQueue(); + BlockingQueue compareResponseQueue = new LinkedBlockingQueue(); respQueueMap.put( newId, compareResponseQueue ); ResponseFuture compareFuture = new ResponseFuture( compareResponseQueue ); @@ -2712,7 +2734,7 @@ message.setProtocolOP( extReqCodec ); - BlockingQueue extendedResponseQueue = new LinkedBlockingQueue(); + BlockingQueue extendedResponseQueue = new LinkedBlockingQueue(); respQueueMap.put( newId, extendedResponseQueue ); ResponseFuture extendedFuture = new ResponseFuture( extendedResponseQueue ); @@ -2992,18 +3014,4 @@ futureMap.remove( msgId ); respQueueMap.remove( msgId ); } - - - /** - * removes the blocking queue present in the - * respQueueMap and adds the given message to the blocking queue - * - * @param msgId id of the message - * @param message the received response message to be added - */ - private void addToRespQueueAndRemoveQueueRef( int msgId, AbstractMessage message ) - { - BlockingQueue respQueue = respQueueMap.remove( msgId ); - respQueue.add( message ); - } }