hivemind-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hls...@apache.org
Subject svn commit: r357710 - in /jakarta/hivemind/branches/branch-1-1/framework/src: java/org/apache/hivemind/impl/ModuleImpl.java test/org/apache/hivemind/impl/TestModule.java
Date Mon, 19 Dec 2005 15:36:27 GMT
Author: hlship
Date: Mon Dec 19 07:36:24 2005
New Revision: 357710

URL: http://svn.apache.org/viewcvs?rev=357710&view=rev
Log:
HIVEMIND-162: Performance bottleneck with threaded services

Modified:
    jakarta/hivemind/branches/branch-1-1/framework/src/java/org/apache/hivemind/impl/ModuleImpl.java
    jakarta/hivemind/branches/branch-1-1/framework/src/test/org/apache/hivemind/impl/TestModule.java

Modified: jakarta/hivemind/branches/branch-1-1/framework/src/java/org/apache/hivemind/impl/ModuleImpl.java
URL: http://svn.apache.org/viewcvs/jakarta/hivemind/branches/branch-1-1/framework/src/java/org/apache/hivemind/impl/ModuleImpl.java?rev=357710&r1=357709&r2=357710&view=diff
==============================================================================
--- jakarta/hivemind/branches/branch-1-1/framework/src/java/org/apache/hivemind/impl/ModuleImpl.java
(original)
+++ jakarta/hivemind/branches/branch-1-1/framework/src/java/org/apache/hivemind/impl/ModuleImpl.java
Mon Dec 19 07:36:24 2005
@@ -14,6 +14,7 @@
 
 package org.apache.hivemind.impl;
 
+import java.util.HashMap;
 import java.util.List;
 import java.util.Locale;
 import java.util.Map;
@@ -52,6 +53,13 @@
 
     private Messages _messages;
 
+    /**
+     * Map from (partial) class name to Class. Related to performance bug HIVEMIND-162.
+     * 
+     * @since 1.1.1
+     */
+    private final Map _typeCache = new HashMap();
+
     public List getConfiguration(String extensionPointId)
     {
         String qualifiedId = IdUtils.qualify(_moduleId, extensionPointId);
@@ -186,7 +194,21 @@
         return _registry.valueForSymbol(symbol);
     }
 
-    public Class resolveType(String type)
+    public synchronized Class resolveType(String type)
+    {
+        Class result = (Class) _typeCache.get(type);
+
+        if (result == null)
+        {
+            result = findTypeInClassResolver(type);
+
+            _typeCache.put(type, result);
+        }
+
+        return result;
+    }
+
+    private Class findTypeInClassResolver(String type)
     {
         Class result = _resolver.checkForClass(type);
 

Modified: jakarta/hivemind/branches/branch-1-1/framework/src/test/org/apache/hivemind/impl/TestModule.java
URL: http://svn.apache.org/viewcvs/jakarta/hivemind/branches/branch-1-1/framework/src/test/org/apache/hivemind/impl/TestModule.java?rev=357710&r1=357709&r2=357710&view=diff
==============================================================================
--- jakarta/hivemind/branches/branch-1-1/framework/src/test/org/apache/hivemind/impl/TestModule.java
(original)
+++ jakarta/hivemind/branches/branch-1-1/framework/src/test/org/apache/hivemind/impl/TestModule.java
Mon Dec 19 07:36:24 2005
@@ -18,6 +18,7 @@
 import hivemind.test.services.impl.StringHolderImpl;
 
 import org.apache.hivemind.ApplicationRuntimeException;
+import org.apache.hivemind.ClassResolver;
 import org.apache.hivemind.ErrorLog;
 import org.apache.hivemind.Locatable;
 import org.apache.hivemind.internal.RegistryInfrastructure;
@@ -63,6 +64,43 @@
         assertSame(Locatable.class, module.resolveType("org.apache.hivemind.Locatable"));
         assertSame(ErrorLog.class, module.resolveType("ErrorLog"));
         assertSame(BaseLocatable.class, module.resolveType("impl.BaseLocatable"));
+    }
+
+    /**
+     * @since 1.1.1
+     */
+    public void testResolveTypeCache()
+    {
+        Class expected = getClass();
+
+        ClassResolver resolver = newClassResolver();
+
+        trainCheckForClass(resolver, "FooBar", expected);
+
+        replayControls();
+
+        ModuleImpl module = new ModuleImpl();
+        module.setPackageName("org.apache.hivemind");
+        module.setClassResolver(resolver);
+
+        assertSame(expected, module.resolveType("FooBar"));
+
+        // And this time it comes out of the cache
+
+        assertSame(expected, module.resolveType("FooBar"));
+
+        verifyControls();
+    }
+
+    private void trainCheckForClass(ClassResolver resolver, String type, Class returnClass)
+    {
+        resolver.checkForClass(type);
+        setReturnValue(resolver, returnClass);
+    }
+
+    private ClassResolver newClassResolver()
+    {
+        return (ClassResolver) newMock(ClassResolver.class);
     }
 
     public void testResolveTypeFailure()



---------------------------------------------------------------------
To unsubscribe, e-mail: hivemind-cvs-unsubscribe@jakarta.apache.org
For additional commands, e-mail: hivemind-cvs-help@jakarta.apache.org


Mime
View raw message