directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r1388933 - in /directory/shared/branches/shared-mvbt: dsml/parser/src/main/java/org/apache/directory/shared/dsmlv2/reponse/ ldap/codec/core/src/main/java/org/apache/directory/shared/ldap/codec/decorators/ ldap/model/src/main/java/org/apache...
Date Sun, 23 Sep 2012 00:48:12 GMT
Author: elecharny
Date: Sun Sep 23 00:48:11 2012
New Revision: 1388933

URL: http://svn.apache.org/viewvc?rev=1388933&view=rev
Log:
o Small speed improvement : when the LdapResult is SUCCESS, with no additional information,
we can avoid the computation of its length and we can provide the byte[] directly

Modified:
    directory/shared/branches/shared-mvbt/dsml/parser/src/main/java/org/apache/directory/shared/dsmlv2/reponse/LdapResultDsml.java
    directory/shared/branches/shared-mvbt/ldap/codec/core/src/main/java/org/apache/directory/shared/ldap/codec/decorators/LdapResultDecorator.java
    directory/shared/branches/shared-mvbt/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/message/LdapResult.java
    directory/shared/branches/shared-mvbt/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/message/LdapResultImpl.java
    directory/shared/branches/shared-mvbt/ldap/model/src/test/java/org/apache/directory/shared/ldap/model/message/LdapResultImplTest.java

Modified: directory/shared/branches/shared-mvbt/dsml/parser/src/main/java/org/apache/directory/shared/dsmlv2/reponse/LdapResultDsml.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-mvbt/dsml/parser/src/main/java/org/apache/directory/shared/dsmlv2/reponse/LdapResultDsml.java?rev=1388933&r1=1388932&r2=1388933&view=diff
==============================================================================
--- directory/shared/branches/shared-mvbt/dsml/parser/src/main/java/org/apache/directory/shared/dsmlv2/reponse/LdapResultDsml.java
(original)
+++ directory/shared/branches/shared-mvbt/dsml/parser/src/main/java/org/apache/directory/shared/dsmlv2/reponse/LdapResultDsml.java
Sun Sep 23 00:48:11 2012
@@ -243,4 +243,13 @@ public class LdapResultDsml implements D
     {
         getDecorated().setReferral( referral );
     }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public boolean isDefaultSuccess()
+    {
+        return false;
+    }
 }

Modified: directory/shared/branches/shared-mvbt/ldap/codec/core/src/main/java/org/apache/directory/shared/ldap/codec/decorators/LdapResultDecorator.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-mvbt/ldap/codec/core/src/main/java/org/apache/directory/shared/ldap/codec/decorators/LdapResultDecorator.java?rev=1388933&r1=1388932&r2=1388933&view=diff
==============================================================================
--- directory/shared/branches/shared-mvbt/ldap/codec/core/src/main/java/org/apache/directory/shared/ldap/codec/decorators/LdapResultDecorator.java
(original)
+++ directory/shared/branches/shared-mvbt/ldap/codec/core/src/main/java/org/apache/directory/shared/ldap/codec/decorators/LdapResultDecorator.java
Sun Sep 23 00:48:11 2012
@@ -24,8 +24,8 @@ import java.nio.BufferOverflowException;
 import java.nio.ByteBuffer;
 
 import org.apache.directory.shared.asn1.EncoderException;
-import org.apache.directory.shared.asn1.ber.tlv.TLV;
 import org.apache.directory.shared.asn1.ber.tlv.BerValue;
+import org.apache.directory.shared.asn1.ber.tlv.TLV;
 import org.apache.directory.shared.i18n.I18n;
 import org.apache.directory.shared.ldap.codec.api.Decorator;
 import org.apache.directory.shared.ldap.codec.api.LdapApiService;
@@ -56,6 +56,9 @@ public class LdapResultDecorator impleme
     /** The codec responsible for encoding and decoding this object. */
     private LdapApiService codec;
 
+    private static final byte[] DEFAULT_SUCCESS = new byte[]
+        { 0x0A, 0x01, 0x00, 0x04, 0x00, 0x04, 0x00 };
+
 
     /**
      * Makes a LdapResult encodable.
@@ -208,7 +211,7 @@ public class LdapResultDecorator impleme
      * Compute the LdapResult length 
      * 
      * LdapResult : 
-     * 0x0A 01 resultCode (0..80)
+     *   0x0A 01 resultCode (0..80)
      *   0x04 L1 matchedDN (L1 = Length(matchedDN)) 
      *   0x04 L2 errorMessage (L2 = Length(errorMessage)) 
      *   [0x83 L3] referrals 
@@ -230,6 +233,12 @@ public class LdapResultDecorator impleme
      */
     public int computeLength()
     {
+        if ( decoratedLdapResult.isDefaultSuccess() )
+        {
+            // The length of a default success PDU : 0xA0 0x01 0x00 0x04 0x00 0x04 0x00
+            return DEFAULT_SUCCESS.length;
+        }
+
         int ldapResultLength = 0;
 
         // The result code
@@ -277,6 +286,14 @@ public class LdapResultDecorator impleme
             throw new EncoderException( I18n.err( I18n.ERR_04023 ) );
         }
 
+        if ( decoratedLdapResult.isDefaultSuccess() )
+        {
+            // The length of a default success PDU : 0xA0 0x01 0x00 0x04 0x00 0x04 0x00
+            buffer.put( DEFAULT_SUCCESS );
+
+            return buffer;
+        }
+
         try
         {
             // The result code
@@ -321,4 +338,13 @@ public class LdapResultDecorator impleme
     {
         return codec;
     }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public boolean isDefaultSuccess()
+    {
+        return decoratedLdapResult.isDefaultSuccess();
+    }
 }

Modified: directory/shared/branches/shared-mvbt/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/message/LdapResult.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-mvbt/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/message/LdapResult.java?rev=1388933&r1=1388932&r2=1388933&view=diff
==============================================================================
--- directory/shared/branches/shared-mvbt/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/message/LdapResult.java
(original)
+++ directory/shared/branches/shared-mvbt/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/message/LdapResult.java
Sun Sep 23 00:48:11 2012
@@ -184,4 +184,14 @@ public interface LdapResult
      * @param referral optional referral on REFERRAL errors.
      */
     void setReferral( Referral referral );
+
+
+    /**
+     * Tells if the LdapResult is a success, with no added information. The
+     * MatchedDn will be empty, as the diagnostic message and the referral.
+     * The ResultCode will always be 0.
+     * 
+     * @return True if the LdapResult is SUCCESS.
+     */
+    boolean isDefaultSuccess();
 }

Modified: directory/shared/branches/shared-mvbt/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/message/LdapResultImpl.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-mvbt/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/message/LdapResultImpl.java?rev=1388933&r1=1388932&r2=1388933&view=diff
==============================================================================
--- directory/shared/branches/shared-mvbt/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/message/LdapResultImpl.java
(original)
+++ directory/shared/branches/shared-mvbt/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/message/LdapResultImpl.java
Sun Sep 23 00:48:11 2012
@@ -43,6 +43,9 @@ public class LdapResultImpl implements L
     /** Resultant operation error code - defaults to SUCCESS */
     private ResultCodeEnum resultCode = ResultCodeEnum.SUCCESS;
 
+    /** A flag set when the LdapResult is a SUCESS with no additional information */
+    private boolean isDefaultSuccess = true;
+
 
     // ------------------------------------------------------------------------
     // LdapResult Interface Method Implementations
@@ -62,6 +65,7 @@ public class LdapResultImpl implements L
     public void setDiagnosticMessage( String diagnosticMessage )
     {
         this.diagnosticMessage = diagnosticMessage;
+        isDefaultSuccess = false;
     }
 
 
@@ -80,6 +84,7 @@ public class LdapResultImpl implements L
     public void setMatchedDn( Dn matchedDn )
     {
         this.matchedDn = matchedDn;
+        isDefaultSuccess = false;
     }
 
 
@@ -98,6 +103,8 @@ public class LdapResultImpl implements L
     public void setResultCode( ResultCodeEnum resultCode )
     {
         this.resultCode = resultCode;
+
+        isDefaultSuccess = isDefaultSuccess & ( resultCode == ResultCodeEnum.SUCCESS
);
     }
 
 
@@ -125,6 +132,16 @@ public class LdapResultImpl implements L
     public void setReferral( Referral referral )
     {
         this.referral = referral;
+        isDefaultSuccess = false;
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public boolean isDefaultSuccess()
+    {
+        return isDefaultSuccess;
     }
 
 

Modified: directory/shared/branches/shared-mvbt/ldap/model/src/test/java/org/apache/directory/shared/ldap/model/message/LdapResultImplTest.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-mvbt/ldap/model/src/test/java/org/apache/directory/shared/ldap/model/message/LdapResultImplTest.java?rev=1388933&r1=1388932&r2=1388933&view=diff
==============================================================================
--- directory/shared/branches/shared-mvbt/ldap/model/src/test/java/org/apache/directory/shared/ldap/model/message/LdapResultImplTest.java
(original)
+++ directory/shared/branches/shared-mvbt/ldap/model/src/test/java/org/apache/directory/shared/ldap/model/message/LdapResultImplTest.java
Sun Sep 23 00:48:11 2012
@@ -140,6 +140,12 @@ public class LdapResultImplTest
             public void setReferral( Referral referral )
             {
             }
+
+
+            public boolean isDefaultSuccess()
+            {
+                return false;
+            }
         };
 
         assertTrue( "r0 equals should see other impl r1 as equal", r0.equals( r1 ) );



Mime
View raw message