bloritsch 02/02/18 06:21:01
Modified: src/java/org/apache/avalon/excalibur/collections
BucketMap.java
src/scratchpad/org/apache/avalon/excalibur/system
AbstractContainer.java
Log:
migrate Container to use BucketMap
Revision Changes Path
1.8 +19 -2
jakarta-avalon-excalibur/src/java/org/apache/avalon/excalibur/collections/BucketMap.java
Index: BucketMap.java
===================================================================
RCS file:
/home/cvs/jakarta-avalon-excalibur/src/java/org/apache/avalon/excalibur/collections/BucketMap.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- BucketMap.java 18 Feb 2002 13:44:39 -0000 1.7
+++ BucketMap.java 18 Feb 2002 14:21:01 -0000 1.8
@@ -18,7 +18,7 @@
*
* @author <a href="[EMAIL PROTECTED]">Berin Loritsch</a>
* @author <a href="[EMAIL PROTECTED]">Gerhard Froehlich</a>
- * @version CVS $Revision: 1.7 $ $Date: 2002/02/18 13:44:39 $
+ * @version CVS $Revision: 1.8 $ $Date: 2002/02/18 14:21:01 $
* @since 4.0
*/
public final class BucketMap
@@ -36,7 +36,24 @@
public BucketMap( int numBuckets )
{
- int size = ( numBuckets >= 16 ) ? numBuckets : 16;
+ int size = Math.max( 17, numBuckets );
+
+ // Ensure that bucketSize is never a power of 2 (to ensure maximal
distribution)
+ for ( int i = 0; i < 32; i++ )
+ {
+ if ( ( 2 ^ i ) < size )
+ {
+ continue;
+ }
+
+ if ( ( 2 ^ i ) == size )
+ {
+ size = ( 2 ^ i ) - 1;
+ }
+
+ break;
+ }
+
m_buckets = new Node[size];
m_locks = new Object[size];
1.20 +16 -29
jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/system/AbstractContainer.java
Index: AbstractContainer.java
===================================================================
RCS file:
/home/cvs/jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/system/AbstractContainer.java,v
retrieving revision 1.19
retrieving revision 1.20
diff -u -r1.19 -r1.20
--- AbstractContainer.java 12 Feb 2002 21:30:43 -0000 1.19
+++ AbstractContainer.java 18 Feb 2002 14:21:01 -0000 1.20
@@ -14,6 +14,7 @@
import org.apache.avalon.framework.logger.*;
import org.apache.avalon.excalibur.collections.FixedSizeBuffer;
+import org.apache.avalon.excalibur.collections.BucketMap;
import org.apache.avalon.excalibur.command.*;
import org.apache.avalon.excalibur.system.handler.*;
import org.apache.avalon.excalibur.logger.LoggerManager;
@@ -22,10 +23,8 @@
import java.util.ArrayList;
import java.util.Collections;
-import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
-import java.util.Map;
import java.lang.reflect.Constructor;
@@ -35,7 +34,7 @@
* Manager can expose that to the instantiating class.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Berin Loritsch</a>
- * @version CVS $Revision: 1.19 $ $Date: 2002/02/12 21:30:43 $
+ * @version CVS $Revision: 1.20 $ $Date: 2002/02/18 14:21:01 $
*/
public abstract class AbstractContainer
extends AbstractLogEnabled
@@ -50,8 +49,8 @@
protected ClassLoader m_classLoader;
protected RoleManager m_roleManager;
protected Configuration m_configuration;
- protected Map m_configs = new HashMap(10);
- protected Map m_mapper = new HashMap(10);
+ protected BucketMap m_configs = new BucketMap();
+ protected BucketMap m_mapper = new BucketMap();
protected List m_components = new ArrayList(10);
/**
@@ -207,11 +206,11 @@
if ( null != role && null != klass && null != handler )
{
- Map hintMap = (Map) m_mapper.get( role );
+ BucketMap hintMap = (BucketMap) m_mapper.get( role );
if ( null == hintMap )
{
- hintMap = new HashMap(5);
+ hintMap = new BucketMap();
}
hintMap.put( hint, handler );
@@ -289,7 +288,7 @@
protected Object get( final String role, final Object hint )
throws ComponentException
{
- Map hintMap = (Map) m_mapper.get( role );
+ BucketMap hintMap = (BucketMap) m_mapper.get( role );
Object value;
if ( null == hintMap )
@@ -337,7 +336,7 @@
return m_mapper.keySet().contains( role );
}
- Map hintMap = (Map) m_mapper.get( role );
+ BucketMap hintMap = (BucketMap) m_mapper.get( role );
return hintMap.keySet().contains( hint );
}
@@ -452,7 +451,7 @@
implements ComponentManager
{
private final AbstractContainer m_components;
- private final Map m_used;
+ private final BucketMap m_used;
private final ComponentManager m_parent;
/**
@@ -472,7 +471,7 @@
{
m_parent = parent;
m_components = container;
- m_used = new HashMap( 10 );
+ m_used = new BucketMap();
}
public Component lookup( String role )
@@ -525,10 +524,7 @@
throw new ComponentException( "Could not return a reference
to the Component", e );
}
- synchronized ( m_used )
- {
- m_used.put( component, handler );
- }
+ m_used.put( component, handler );
return component;
}
@@ -549,10 +545,7 @@
{
final ComponentHandler handler;
- synchronized ( m_used )
- {
- handler = (ComponentHandler) m_used.remove( component );
- }
+ handler = (ComponentHandler) m_used.remove( component );
if ( null == handler && null != m_parent )
{
@@ -574,13 +567,13 @@
{
private final String m_role;
private final AbstractContainer m_components;
- private final Map m_used;
+ private final BucketMap m_used;
public ContainerComponentSelector( final AbstractContainer
container, final String role )
{
m_role = role;
m_components = container;
- m_used = new HashMap( 5 );
+ m_used = new BucketMap();
}
public Component select( final Object hint )
@@ -614,10 +607,7 @@
throw new ComponentException( "Could not return a reference
to the Component", e );
}
- synchronized ( m_used )
- {
- m_used.put( component, handler );
- }
+ m_used.put( component, handler );
return component;
}
@@ -631,10 +621,7 @@
{
final ComponentHandler handler;
- synchronized ( m_used )
- {
- handler = (ComponentHandler) m_used.remove( component );
- }
+ handler = (ComponentHandler) m_used.remove( component );
handler.put( component );
}
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>