Hmm is it my editor or the source. My jEdit displays
some strange line feeds...

  ~Gerhard
 
+----------------------------------------------+
My parents have been visiting me for a few days. 
I just dropped them off at the airport. 
They leave tomorrow. 
+----------------------------------------------+

>-----Original Message-----
>From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]]
>Sent: Friday, February 15, 2002 9:12 PM
>To: [EMAIL PROTECTED]
>Subject: cvs commit:
>jakarta-avalon-excalibur/src/java/org/apache/avalon/excalibur/component
>ExcaliburComponentManager.java ExcaliburComponentSelector.java
>
>
>bloritsch    02/02/15 12:12:10
>
>  Modified:    src/java/org/apache/avalon/excalibur/component
>                        ExcaliburComponentManager.java
>                        ExcaliburComponentSelector.java
>  Added:       src/java/org/apache/avalon/excalibur/collections
>                        BucketMap.java
>  Log:
>  reduce load on ECM by 50%
>  
>  Revision  Changes    Path
>  1.1                  
>jakarta-avalon-excalibur/src/java/org/apache/avalon/excalibur/collections/BucketMap.java
>  
>  Index: BucketMap.java
>  ===================================================================
>  /*
>   * Copyright (C) The Apache Software Foundation. All rights reserved.
>   *
>   * This software is published under the terms of the Apache Software License
>   * version 1.1, a copy of which has been included with this distribution in
>   * the LICENSE.txt file.
>   */
>  package org.apache.avalon.excalibur.collections;
>  
>  import java.util.List;
>  import java.util.ArrayList;
>  import java.util.Set;
>  import java.util.HashSet;
>  
>  /**
>   * A BucketMap is an efficient ThreadSafe implementation of a Map.  The
>   * map only supports get(), put(), and contains().
>   *
>   * @author  <a href="[EMAIL PROTECTED]">Berin Loritsch</a>
>   * @version CVS $Revision: 1.1 $ $Date: 2002/02/15 20:12:10 $
>   * @since 4.0
>   */
>  public final class BucketMap
>  {
>      private static final int DEFAULT_BUCKETS = 256;
>      private final Node[]   m_buckets;
>      private final Object[] m_locks;
>  
>      /**
>       */
>      public BucketMap()
>      {
>          this( DEFAULT_BUCKETS );
>      }
>  
>      public BucketMap( int numBuckets )
>      {
>          int size = ( numBuckets >= 16 ) ? numBuckets : 16;
>          m_buckets = new Node[size];
>          m_locks = new Object[size];
>  
>          for ( int i = 0; i < size; i++ )
>          {
>              m_locks[i] = new Object();
>          }
>      }
>  
>      private final int getHash( Object key )
>      {
>          final int hash = key.hashCode() % m_buckets.length;
>          return (hash < 0) ? hash * -1 : hash;
>      }
>  
>      /**
>       * Add an object into the buffer.
>       *
>       * @throws BufferOverflowException if adding this element exceeds the
>       *         buffer's capacity.
>       */
>      public Set keySet()
>      {
>          Set keySet = new HashSet();
>  
>          for (int i = 0; i < m_buckets.length; i++ )
>          {
>              synchronized( m_locks[i] )
>              {
>                  Node n = m_buckets[i];
>  
>                  while( n != null )
>                  {
>                      keySet.add(n.key);
>                      n = n.next;
>                  }
>              }
>          }
>  
>          return keySet;
>      }
>  
>      /**
>       * Add an object into the buffer.
>       *
>       * @throws BufferOverflowException if adding this element exceeds the
>       *         buffer's capacity.
>       */
>      public void put( final Object key, final Object value )
>      {
>          if ( null == key || null == value )
>          {
>              return;
>          }
>  
>          int hash = getHash( key );
>  
>          synchronized( m_locks[hash] )
>          {
>              Node n = m_buckets[hash];
>  
>              if ( n == null )
>              {
>                  n = new Node();
>                  n.key = key;
>                  n.value = value;
>                  m_buckets[hash] = n;
>                  return;
>              }
>  
>              while ( n.next != null )
>              {
>                  if ( n.key.equals(key) )
>                  {
>                      n.value = value;
>                      return;
>                  }
>  
>                  n = n.next;
>              }
>  
>              Node newNode = new Node();
>              newNode.key = key;
>              newNode.value = value;
>              n.next = newNode;
>          }
>      }
>  
>      /**
>       * Add an object into the buffer.
>       *
>       * @throws BufferOverflowException if adding this element exceeds the
>       *         buffer's capacity.
>       */
>      public Object get( final Object key )
>      {
>          if ( null == key )
>          {
>              return null;
>          }
>  
>          int hash = getHash( key );
>  
>          synchronized( m_locks[hash] )
>          {
>              Node n = m_buckets[hash];
>  
>              while ( n != null )
>              {
>                  if ( n.key.equals(key) )
>                  {
>                      return n.value;
>                  }
>  
>                  n = n.next;
>              }
>          }
>  
>          return null;
>      }
>  
>      /**
>       * Add an object into the buffer.
>       *
>       * @throws BufferOverflowException if adding this element exceeds the
>       *         buffer's capacity.
>       */
>      public boolean containsKey( final Object key )
>      {
>          if ( null == key )
>          {
>              return false;
>          }
>  
>          int hash = getHash( key );
>  
>          synchronized( m_locks[hash] )
>          {
>              Node n = m_buckets[hash];
>  
>              while ( n != null )
>              {
>                  if ( n.key.equals(key) )
>                  {
>                      return true;
>                  }
>  
>                  n = n.next;
>              }
>          }
>  
>          return false;
>      }
>  
>      /**
>       * Removes the next object from the buffer.
>       *
>       * @throws BufferUnderflowException if the buffer is already empty
>       */
>      public Object remove( Object key )
>      {
>          if ( null == key )
>          {
>              return null;
>          }
>  
>          int hash = getHash( key );
>  
>          synchronized( m_locks[hash] )
>          {
>              Node n = m_buckets[hash];
>              Node prev = null;
>  
>              while ( n != null )
>              {
>                  if ( n.key.equals( key ) )
>                  {
>                      if ( null == prev )
>                      {
>                          m_buckets[hash] = n.next;
>                      }
>                      else
>                      {
>                          prev.next = n.next;
>                      }
>  
>                      return n.value;
>                  }
>  
>                  prev = n;
>                  n = n.next;
>              }
>          }
>  
>          return null;
>      }
>  
>      private final static class Node
>      {
>          protected Object key;
>          protected Object value;
>          protected Node next;
>      }
>  }
>  
>  
>  
>  1.17      +5 -7      
>jakarta-avalon-excalibur/src/java/org/apache/avalon/excalibur/component/ExcaliburComponentM
>anager.java
>  
>  Index: ExcaliburComponentManager.java
>  ===================================================================
>  RCS file: 
>/home/cvs/jakarta-avalon-excalibur/src/java/org/apache/avalon/excalibur/component/Excalibur
>ComponentManager.java,v
>  retrieving revision 1.16
>  retrieving revision 1.17
>  diff -u -r1.16 -r1.17
>  --- ExcaliburComponentManager.java   30 Jan 2002 16:49:04 -0000      1.16
>  +++ ExcaliburComponentManager.java   15 Feb 2002 20:12:10 -0000      1.17
>  @@ -28,12 +28,14 @@
>   import org.apache.avalon.excalibur.logger.LogKitManager;
>   import org.apache.avalon.excalibur.logger.LogKitManageable;
>   
>  +import org.apache.avalon.excalibur.collections.BucketMap;
>  +
>   /**
>    * Default component manager for Avalon's components.
>    *
>    * @author <a href="mailto:[EMAIL PROTECTED]";>Berin Loritsch</a>
>    * @author <a href="mailto:[EMAIL PROTECTED]";>Paul Russell</a>
>  - * @version CVS $Revision: 1.16 $ $Date: 2002/01/30 16:49:04 $
>  + * @version CVS $Revision: 1.17 $ $Date: 2002/02/15 20:12:10 $
>    * @since 4.0
>    */
>   public class ExcaliburComponentManager
>  @@ -58,11 +60,11 @@
>   
>       /** Static component mapping handlers.
>        */
>  -    private Map          m_componentMapping;
>  +    private final BucketMap    m_componentMapping = new BucketMap();
>   
>       /** Static component handlers.
>        */
>  -    private Map          m_componentHandlers;
>  +    private final BucketMap    m_componentHandlers = new BucketMap();
>   
>       /** RoleInfos.
>        */
>  @@ -103,10 +105,6 @@
>           }
>   
>           m_parentManager = manager;
>  -
>  -        // Setup the maps.
>  -        m_componentHandlers = Collections.synchronizedMap( new HashMap() );
>  -        m_componentMapping = Collections.synchronizedMap( new HashMap() );
>       }
>   
>       /** Create the ComponentManager with a parent ComponentManager */
>  
>  
>  
>  1.11      +8 -10     
>jakarta-avalon-excalibur/src/java/org/apache/avalon/excalibur/component/ExcaliburComponentS
>elector.java
>  
>  Index: ExcaliburComponentSelector.java
>  ===================================================================
>  RCS file: 
>/home/cvs/jakarta-avalon-excalibur/src/java/org/apache/avalon/excalibur/component/Excalibur
>ComponentSelector.java,v
>  retrieving revision 1.10
>  retrieving revision 1.11
>  diff -u -r1.10 -r1.11
>  --- ExcaliburComponentSelector.java  30 Jan 2002 16:49:05 -0000      1.10
>  +++ ExcaliburComponentSelector.java  15 Feb 2002 20:12:10 -0000      1.11
>  @@ -30,12 +30,14 @@
>   import org.apache.avalon.excalibur.logger.LogKitManager;
>   import org.apache.avalon.excalibur.logger.LogKitManageable;
>   
>  +import org.apache.avalon.excalibur.collections.BucketMap;
>  +
>   /**
>    * Default component selector for Avalon's components.
>    *
>    * @author <a href="mailto:[EMAIL PROTECTED]";>Berin Loritsch</a>
>    * @author <a href="mailto:[EMAIL PROTECTED]";>Paul Russell</a>
>  - * @version CVS $Revision: 1.10 $ $Date: 2002/01/30 16:49:05 $
>  + * @version CVS $Revision: 1.11 $ $Date: 2002/02/15 20:12:10 $
>    * @since 4.0
>    */
>   public class ExcaliburComponentSelector
>  @@ -69,17 +71,17 @@
>        */
>       private ComponentManager m_componentManager;
>   
>  -    /** Dynamic component handlers mapping.
>  -     */
>  -    private Map              m_componentMapping;
>  -
>       /** Static configuraiton object.
>        */
>       private Configuration    m_configuration;
>   
>       /** Static component handlers.
>        */
>  -    private Map              m_componentHandlers;
>  +    private BucketMap        m_componentHandlers = new BucketMap();
>  +
>  +    /** Dynamic component handlers mapping.
>  +     */
>  +    private BucketMap        m_componentMapping = new BucketMap();
>   
>       /** Flag for if this is disposed or not.
>        */
>  @@ -114,10 +116,6 @@
>           {
>               m_loader = loader;
>           }
>  -
>  -        // Setup the maps.
>  -        m_componentHandlers = Collections.synchronizedMap( new HashMap() );
>  -        m_componentMapping = Collections.synchronizedMap( new HashMap() );
>       }
>   
>       /** Provide the application Context.
>  
>  
>  
>
>--
>To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
>For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>
>
>

--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to