directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r159562 - in directory/sandbox/trunk/asn1-new-codec/src: java/org/apache/asn1/ber/ java/org/apache/asn1/util/pools/ perfs/org/apache/ans1/ber/ test/org/apache/asn1/ldap/codec/
Date Thu, 31 Mar 2005 06:38:38 GMT
Author: elecharny
Date: Wed Mar 30 22:38:36 2005
New Revision: 159562

URL: http://svn.apache.org/viewcvs?view=rev&rev=159562
Log:
Added a switch to allocate memory either directly (using new) or using pools. The pooled mechanism
is 15% faster ...

Modified:
    directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ber/Asn1Decoder.java
    directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/util/pools/LocalPoolManager.java
    directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/util/pools/PoolEnum.java
    directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/util/pools/PoolObject.java
    directory/sandbox/trunk/asn1-new-codec/src/perfs/org/apache/ans1/ber/LdapDecoderPerf.java
    directory/sandbox/trunk/asn1-new-codec/src/test/org/apache/asn1/ldap/codec/LdapDecoderTest.java

Modified: directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ber/Asn1Decoder.java
URL: http://svn.apache.org/viewcvs/directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ber/Asn1Decoder.java?view=diff&r1=159561&r2=159562
==============================================================================
--- directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ber/Asn1Decoder.java (original)
+++ directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ber/Asn1Decoder.java Wed
Mar 30 22:38:36 2005
@@ -72,19 +72,36 @@
 
     /** The local pool Manager */
     private LocalPoolManager poolMgr;
-
+    
+    /** A flag to set the memory mechanism to use */
+    private boolean isPooled;
+    
     //~ Constructors -------------------------------------------------------------------------------
 
     /**
-     * A private constructor to avoid a new instanciation of this class. A
-     * public constructor
+     * A public constructor of an Asn1 Decoder.
+     * 
+     * @param isPooled Set the memory allocation mechanism. If <code>true</code>,
+     * a pooled mechanism will be used
+     */
+    public Asn1Decoder(boolean isPooled)
+    {
+        this.indefiniteLengthAllowed = false;
+        this.maxLengthLength         = 1;
+        this.maxTagLength            = 1;
+        poolMgr                      = new LocalPoolManager(isPooled);
+    }
+
+    /**
+     * A public constructor of an Asn1 Decoder.
      */
     public Asn1Decoder()
     {
         this.indefiniteLengthAllowed = false;
         this.maxLengthLength         = 1;
         this.maxTagLength            = 1;
-        poolMgr                      = new LocalPoolManager();
+        isPooled                     = true;
+        poolMgr                      = new LocalPoolManager(isPooled);
     }
 
     //~ Methods ------------------------------------------------------------------------------------
@@ -260,21 +277,29 @@
         throws DecoderException
     {
 
-        if ( DEBUG )
-        {
-
-            Tag tag = container.getCurrentTLV().getTag();
-            log.debug( tag.toString() + " has been decoded" );
-        }
-
-        // After having decoded a tag, we have to execute the action
-        // which controls if this tag is allowed and well formed.
-        container.getGrammar().executeAction( container );
-
-        // Switch to the next state, which is the Length decoding
-        container.setState( TLVStateEnum.LENGTH_STATE_START );
-
-        return MORE;
+    	try
+		{
+	        if ( DEBUG )
+	        {
+	
+	            Tag tag = container.getCurrentTLV().getTag();
+	            log.debug( tag.toString() + " has been decoded" );
+	        }
+	
+	        // After having decoded a tag, we have to execute the action
+	        // which controls if this tag is allowed and well formed.
+	        container.getGrammar().executeAction( container );
+	
+	        // Switch to the next state, which is the Length decoding
+	        container.setState( TLVStateEnum.LENGTH_STATE_START );
+	
+	        return MORE;
+		} 
+    	catch (NullPointerException npe)
+		{
+    		npe.printStackTrace();
+    		throw new DecoderException("Null pinter exception");
+		}
     }
 
     /**
@@ -817,8 +842,14 @@
      */
     public PoolObject allocate( int pool ) throws PoolException
     {
-
-        return poolMgr.allocate( pool );
+    	if (isPooled)
+    	{
+       		return poolMgr.allocate( pool );
+    	}
+    	else
+    	{
+    		return PoolEnum.allocate( pool );
+    	}
     }
 
     /**
@@ -829,5 +860,4 @@
 
         return poolMgr;
     }
-
 } // end class TLVTagDecoder

Modified: directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/util/pools/LocalPoolManager.java
URL: http://svn.apache.org/viewcvs/directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/util/pools/LocalPoolManager.java?view=diff&r1=159561&r2=159562
==============================================================================
--- directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/util/pools/LocalPoolManager.java
(original)
+++ directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/util/pools/LocalPoolManager.java
Wed Mar 30 22:38:36 2005
@@ -53,6 +53,9 @@
 
     /** Array of pools */
     private LocalPool[] pools = new LocalPool[PoolEnum.POOL_NUMBER];
+    
+    /** A flag that sets the memory allocation mechanism */
+    private boolean isPooled;
 
     //~ Constructors -------------------------------------------------------------------------------
 
@@ -60,34 +63,38 @@
      * Creates a new LocalPoolManager object. All the objects that could be allocated are
stored in 
      * local pools.
      */
-    public LocalPoolManager()
+    public LocalPoolManager(boolean isPooled)
     {
-
-        // We have to initialize the pools.
-        // Tag and TLV pool will be bigger than others, because PDU may contain many of them
-        // for only one POJO generated.
-        //
-        // TODO It has to be improved. Picocontainer?
-        pools[PoolEnum.TLV_POOL]                     = new LocalPool( PoolEnum.TLV_POOL,
10240,
-                1024 );
-        
-        pools[PoolEnum.SIMPLE_AUTH_POJO_POOL]        = new LocalPool(
-                PoolEnum.SIMPLE_AUTH_POJO_POOL, 1024, 1024 );
-        
-        pools[PoolEnum.SASL_AUTH_POJO_POOL]          = new LocalPool( PoolEnum.SASL_AUTH_POJO_POOL,
-                1024, 1024 );
-        
-        pools[PoolEnum.BIND_RESPONSE_POJO_POOL]      = new LocalPool(
-                PoolEnum.BIND_RESPONSE_POJO_POOL, 1024, 1024 );
-        
-        pools[PoolEnum.BIND_REQUEST_POJO_POOL]       = new LocalPool(
-                PoolEnum.BIND_REQUEST_POJO_POOL, 1024, 1024 );
-
-        pools[PoolEnum.LDAP_MESSAGE_CONTAINER_POOL] = new LocalPool(
-                PoolEnum.LDAP_MESSAGE_CONTAINER_POOL, 1024, 1024 );
-
-        pools[PoolEnum.LDAP_MESSAGE_POJO_POOL] = new LocalPool(
-                PoolEnum.LDAP_MESSAGE_POJO_POOL, 1024, 1024 );
+    	this.isPooled = isPooled;
+    	
+    	if (isPooled)
+    	{
+	        // We have to initialize the pools.
+	        // Tag and TLV pool will be bigger than others, because PDU may contain many of
them
+	        // for only one POJO generated.
+	        //
+	        // TODO It has to be improved. Picocontainer?
+	        pools[PoolEnum.TLV_POOL]                     = new LocalPool( PoolEnum.TLV_POOL,
10240,
+	                1024 );
+	        
+	        pools[PoolEnum.SIMPLE_AUTH_POJO_POOL]        = new LocalPool(
+	                PoolEnum.SIMPLE_AUTH_POJO_POOL, 1024, 1024 );
+	        
+	        pools[PoolEnum.SASL_AUTH_POJO_POOL]          = new LocalPool( PoolEnum.SASL_AUTH_POJO_POOL,
+	                1024, 1024 );
+	        
+	        pools[PoolEnum.BIND_RESPONSE_POJO_POOL]      = new LocalPool(
+	                PoolEnum.BIND_RESPONSE_POJO_POOL, 1024, 1024 );
+	        
+	        pools[PoolEnum.BIND_REQUEST_POJO_POOL]       = new LocalPool(
+	                PoolEnum.BIND_REQUEST_POJO_POOL, 1024, 1024 );
+	
+	        pools[PoolEnum.LDAP_MESSAGE_CONTAINER_POOL] = new LocalPool(
+	                PoolEnum.LDAP_MESSAGE_CONTAINER_POOL, 1024, 1024 );
+	
+	        pools[PoolEnum.LDAP_MESSAGE_POJO_POOL] = new LocalPool(
+	                PoolEnum.LDAP_MESSAGE_POJO_POOL, 1024, 1024 );
+    	}
     }
 
     //~ Methods ------------------------------------------------------------------------------------
@@ -101,10 +108,14 @@
      */
     public PoolObject allocate( int poolId ) throws PoolException
     {
-
-        PoolObject object = ( PoolObject ) pools[poolId].allocate();
-
-        return object;
+    	if (isPooled)
+    	{
+    		return ( PoolObject ) pools[poolId].allocate();
+    	}
+    	else 
+    	{
+    		return PoolEnum.allocate(poolId);
+    	}
     }
 
     /**
@@ -120,7 +131,14 @@
      */
     public void free( PoolObject object ) throws PoolStackFullException
     {
-        pools[object.getPoolId()].free( object );
+    	if (isPooled)
+    	{
+    		pools[object.getPoolId()].free( object );
+    	}
+    	else
+    	{
+    		object = null;
+    	}
     }
 
     //~ Inner Classes ------------------------------------------------------------------------------

Modified: directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/util/pools/PoolEnum.java
URL: http://svn.apache.org/viewcvs/directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/util/pools/PoolEnum.java?view=diff&r1=159561&r2=159562
==============================================================================
--- directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/util/pools/PoolEnum.java
(original)
+++ directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/util/pools/PoolEnum.java
Wed Mar 30 22:38:36 2005
@@ -16,6 +16,14 @@
  */
 package org.apache.asn1.util.pools;
 
+import org.apache.asn1.ber.tlv.TLV;
+import org.apache.asn1.ldap.codec.LdapMessageContainer;
+import org.apache.asn1.ldap.pojo.BindRequestPOJO;
+import org.apache.asn1.ldap.pojo.BindResponsePOJO;
+import org.apache.asn1.ldap.pojo.LdapMessagePOJO;
+import org.apache.asn1.ldap.pojo.SaslAuthenticationPOJO;
+import org.apache.asn1.ldap.pojo.SimpleAuthenticationPOJO;
+
 /**
  * This is where all the different pools are named. To add a new pool, we have to
  * add an entry to the list, and to modify the getType method.
@@ -87,5 +95,26 @@
     	{
     		return "UNKNOWN POOL";
     	}
+    }
+    
+    /**
+     * Allocate a new object the classic way.
+     * @param poolId The object pool Id
+     * @return An object
+     */
+    public static PoolObject allocate(int poolId)
+    {
+    	switch (poolId)
+		{
+    		case 0 : return new TLV();
+    		case 1 : return new SimpleAuthenticationPOJO();
+    		case 2 : return new SaslAuthenticationPOJO();
+    		case 3 : return new BindResponsePOJO();
+    		case 4 : return new BindRequestPOJO();
+    		case 5 : return new LdapMessageContainer();
+    		case 6 : return new LdapMessagePOJO();
+    		
+    		default : return null;
+		}
     }
 }

Modified: directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/util/pools/PoolObject.java
URL: http://svn.apache.org/viewcvs/directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/util/pools/PoolObject.java?view=diff&r1=159561&r2=159562
==============================================================================
--- directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/util/pools/PoolObject.java
(original)
+++ directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/util/pools/PoolObject.java
Wed Mar 30 22:38:36 2005
@@ -80,6 +80,9 @@
      */
     public void free()
     {
-        pool.free( this );
+    	if (pool != null)
+    	{
+    		pool.free( this );
+    	}
     }
 }

Modified: directory/sandbox/trunk/asn1-new-codec/src/perfs/org/apache/ans1/ber/LdapDecoderPerf.java
URL: http://svn.apache.org/viewcvs/directory/sandbox/trunk/asn1-new-codec/src/perfs/org/apache/ans1/ber/LdapDecoderPerf.java?view=diff&r1=159561&r2=159562
==============================================================================
--- directory/sandbox/trunk/asn1-new-codec/src/perfs/org/apache/ans1/ber/LdapDecoderPerf.java
(original)
+++ directory/sandbox/trunk/asn1-new-codec/src/perfs/org/apache/ans1/ber/LdapDecoderPerf.java
Wed Mar 30 22:38:36 2005
@@ -57,8 +57,8 @@
      */
     public void run()
     {
-        Asn1Decoder ldapDecoder = new Asn1Decoder();
-
+        Asn1Decoder ldapDecoder = new Asn1Decoder(false);
+        
         ByteBuffer  stream      = ByteBuffer.allocate( 0x35 );
         stream.put(
             new byte[]
@@ -128,6 +128,8 @@
 
             IAsn1Container ldapMessageContainer = ( IAsn1Container ) ldapDecoder.allocate(
                     PoolEnum.LDAP_MESSAGE_CONTAINER_POOL );
+            ldapMessageContainer.setGrammar( LdapMessageGrammar.getInstance() );
+            ldapMessageContainer.setPoolManager( ldapDecoder.getPoolManager() );
 
             ldapDecoder.decode( stream, ldapMessageContainer );
 
@@ -176,8 +178,8 @@
         LdapDecoderPerf ldpt4 = new LdapDecoderPerf();
 
         ldpt1.start();
-        ldpt2.start();
-        ldpt3.start();
-        ldpt4.start();
+        //ldpt2.start();
+        //ldpt3.start();
+        //ldpt4.start();
     }
 }

Modified: directory/sandbox/trunk/asn1-new-codec/src/test/org/apache/asn1/ldap/codec/LdapDecoderTest.java
URL: http://svn.apache.org/viewcvs/directory/sandbox/trunk/asn1-new-codec/src/test/org/apache/asn1/ldap/codec/LdapDecoderTest.java?view=diff&r1=159561&r2=159562
==============================================================================
--- directory/sandbox/trunk/asn1-new-codec/src/test/org/apache/asn1/ldap/codec/LdapDecoderTest.java
(original)
+++ directory/sandbox/trunk/asn1-new-codec/src/test/org/apache/asn1/ldap/codec/LdapDecoderTest.java
Wed Mar 30 22:38:36 2005
@@ -313,7 +313,7 @@
             return;
         }
     	
-        Assert.fail("Should never arrive here...");
+        Assert.fail("Should never reach this point..");
     }
 
     /**
@@ -370,7 +370,7 @@
             return;
         }
     	
-        Assert.fail("Should never arrive here...");
+        Assert.fail("Should never reach this point.");
     }
 
     /**
@@ -396,7 +396,7 @@
                 'e', 'x', 'a', 'm', 'p', 'l', 'e', ',', 'd', 'c', '=', 'c', 'o', 'm',
 				( byte ) 0x80, 0x08, //        authentication AuthenticationChoice
                                      // AuthenticationChoice ::= CHOICE { simple [0] OCTET
STRING, ...
-				'p', 'a', 's', 's', 'w', 'o', 'r'
+				'p', 'a', 's', 's', 'w', 'o', 'r', 'd'
             } );
 
         stream.flip();
@@ -427,6 +427,6 @@
             return;
         }
     	
-        Assert.fail("Should never arrive here...");
+        Assert.fail("Should never reach this point.");
     }
 }



Mime
View raw message