hivemind-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ahue...@apache.org
Subject svn commit: r468964 - /hivemind/branches/branch-2-0-annot/framework/src/java/org/apache/hivemind/impl/ConfigurationPointImpl.java
Date Sun, 29 Oct 2006 19:51:39 GMT
Author: ahuegen
Date: Sun Oct 29 11:51:38 2006
New Revision: 468964

URL: http://svn.apache.org/viewvc?view=rev&rev=468964
Log:
Implemented caching of configuration proxies. Not final yet

Modified:
    hivemind/branches/branch-2-0-annot/framework/src/java/org/apache/hivemind/impl/ConfigurationPointImpl.java

Modified: hivemind/branches/branch-2-0-annot/framework/src/java/org/apache/hivemind/impl/ConfigurationPointImpl.java
URL: http://svn.apache.org/viewvc/hivemind/branches/branch-2-0-annot/framework/src/java/org/apache/hivemind/impl/ConfigurationPointImpl.java?view=diff&rev=468964&r1=468963&r2=468964
==============================================================================
--- hivemind/branches/branch-2-0-annot/framework/src/java/org/apache/hivemind/impl/ConfigurationPointImpl.java
(original)
+++ hivemind/branches/branch-2-0-annot/framework/src/java/org/apache/hivemind/impl/ConfigurationPointImpl.java
Sun Oct 29 11:51:38 2006
@@ -16,7 +16,9 @@
 
 import java.lang.reflect.Constructor;
 import java.lang.reflect.Modifier;
+import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
@@ -291,12 +293,12 @@
             // Create the outer proxy, the one visible to client code (including
             // other services). It is dependent on an inner proxy.
 
-            Class proxyClass = createSingletonProxyClass();
+            Class proxyClass = getSingletonProxyClass();
 
             // Create the inner proxy, whose job is to replace itself
             // when the first service method is invoked.
 
-            Class innerProxyClass = createInnerProxyClass(proxyClass);
+            Class innerProxyClass = getInnerProxyClass(proxyClass);
 
             // Create the outer proxy.
 
@@ -318,6 +320,31 @@
         }
 
     }
+    
+    private final static Map SINGLETON_PROXY_CACHE = new HashMap();
+    private final static Map INNER_PROXY_CACHE = new HashMap();
+    
+    private Class getSingletonProxyClass()
+    {
+        Class configurationInterface = lookupContainerInterface();
+        Class result = (Class) SINGLETON_PROXY_CACHE.get(configurationInterface);
+        if (result == null) {
+          result = createSingletonProxyClass(configurationInterface);
+          SINGLETON_PROXY_CACHE.put(configurationInterface, result);
+        }
+        return result;
+    }
+    
+    private Class getInnerProxyClass(Class deferredProxyClass)
+    {
+        Class result = (Class) INNER_PROXY_CACHE.get(deferredProxyClass);
+        if (result == null) {
+          Class configurationInterface = lookupContainerInterface();
+          result = createInnerProxyClass(configurationInterface, deferredProxyClass);
+          INNER_PROXY_CACHE.put(deferredProxyClass, result);
+        }
+        return result;
+    }
 
     /**
      * Creates a class that implements the service interface. Implements a private synchronized
@@ -325,10 +352,8 @@
      * method re-invoke on _configuration(). Adds a toString() method if the service interface
does not
      * define toString().
      */
-    private Class createSingletonProxyClass()
+    private Class createSingletonProxyClass(Class configurationInterface)
     {
-        Class configurationInterface = lookupContainerInterface();
-
         ProxyBuilder proxyBuilder = new ProxyBuilder("LazyConstructionProxy", this, configurationInterface,
true);
 
         ClassFab classFab = proxyBuilder.getClassFab();
@@ -371,17 +396,15 @@
         return classFab.createClass();
     }
 
-    private Class createInnerProxyClass(Class deferredProxyClass)
+    private Class createInnerProxyClass(Class configurationInterface, Class deferredProxyClass)
     {
-        Class configurationInterface = lookupContainerInterface();
-        
         ProxyBuilder builder = new ProxyBuilder("InnerProxy", this, configurationInterface,
false);
 
         ClassFab classFab = builder.getClassFab();
 
         classFab.addField("_deferredProxy", deferredProxyClass);
         classFab.addField("_configuration", configurationInterface);
-        classFab.addField("_configurationPoint", this.getClass());
+        classFab.addField("_configurationPoint", ConfigurationPointImpl.class);
 
         BodyBuilder body = new BodyBuilder();
 
@@ -398,7 +421,7 @@
         body.end();
 
         classFab.addConstructor(new Class[]
-        { deferredProxyClass, getClass() }, null, body.toString());
+        { deferredProxyClass, ConfigurationPointImpl.class }, null, body.toString());
 
         // Method _configuration() will look up the service implementation,
         // then update the deferred proxy to go directly to the



Mime
View raw message