hivemind-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jcar...@apache.org
Subject svn commit: r400325 - in /jakarta/hivemind/branches/branch-1-1: ./ framework/src/java/org/apache/hivemind/impl/ framework/src/java/org/apache/hivemind/service/ framework/src/java/org/apache/hivemind/service/impl/ framework/src/test/org/apache/hivemind/...
Date Sat, 06 May 2006 15:43:34 GMT
Author: jcarman
Date: Sat May  6 08:43:32 2006
New Revision: 400325

URL: http://svn.apache.org/viewcvs?rev=400325&view=rev
Log:
HiveMind LoggingInterceptor incompatible with proxies generated by outside means (CGLIB or
Javassist)
PR: HIVEMIND-176

Modified:
    jakarta/hivemind/branches/branch-1-1/framework/src/java/org/apache/hivemind/impl/ProxyUtils.java
    jakarta/hivemind/branches/branch-1-1/framework/src/java/org/apache/hivemind/service/ClassFab.java
    jakarta/hivemind/branches/branch-1-1/framework/src/java/org/apache/hivemind/service/ClassFabUtils.java
    jakarta/hivemind/branches/branch-1-1/framework/src/java/org/apache/hivemind/service/impl/AbstractFab.java
    jakarta/hivemind/branches/branch-1-1/framework/src/java/org/apache/hivemind/service/impl/ClassFabImpl.java
    jakarta/hivemind/branches/branch-1-1/framework/src/java/org/apache/hivemind/service/impl/CtClassSource.java
    jakarta/hivemind/branches/branch-1-1/framework/src/java/org/apache/hivemind/service/impl/LoggingInterceptorFactory.java
    jakarta/hivemind/branches/branch-1-1/framework/src/test/org/apache/hivemind/service/impl/TestClassFab.java
    jakarta/hivemind/branches/branch-1-1/framework/src/test/org/apache/hivemind/service/impl/TestClassFabUtils.java
    jakarta/hivemind/branches/branch-1-1/framework/src/test/org/apache/hivemind/service/impl/TestLoggingInterceptorFactory.java
    jakarta/hivemind/branches/branch-1-1/library/src/java/org/apache/hivemind/lib/impl/ServicePropertyFactory.java
    jakarta/hivemind/branches/branch-1-1/status.xml

Modified: jakarta/hivemind/branches/branch-1-1/framework/src/java/org/apache/hivemind/impl/ProxyUtils.java
URL: http://svn.apache.org/viewcvs/jakarta/hivemind/branches/branch-1-1/framework/src/java/org/apache/hivemind/impl/ProxyUtils.java?rev=400325&r1=400324&r2=400325&view=diff
==============================================================================
--- jakarta/hivemind/branches/branch-1-1/framework/src/java/org/apache/hivemind/impl/ProxyUtils.java
(original)
+++ jakarta/hivemind/branches/branch-1-1/framework/src/java/org/apache/hivemind/impl/ProxyUtils.java
Sat May  6 08:43:32 2006
@@ -127,7 +127,7 @@
     {
         classFab.addField("_shutdown", boolean.class);
 
-        Class delegateClass = ClassFabUtils.getInstanceClass(delegate, servicePoint
+        Class delegateClass = ClassFabUtils.getInstanceClass(classFab, delegate, servicePoint
                 .getServiceInterface());
 
         classFab.addField("_delegate", delegateClass);

Modified: jakarta/hivemind/branches/branch-1-1/framework/src/java/org/apache/hivemind/service/ClassFab.java
URL: http://svn.apache.org/viewcvs/jakarta/hivemind/branches/branch-1-1/framework/src/java/org/apache/hivemind/service/ClassFab.java?rev=400325&r1=400324&r2=400325&view=diff
==============================================================================
--- jakarta/hivemind/branches/branch-1-1/framework/src/java/org/apache/hivemind/service/ClassFab.java
(original)
+++ jakarta/hivemind/branches/branch-1-1/framework/src/java/org/apache/hivemind/service/ClassFab.java
Sat May  6 08:43:32 2006
@@ -57,6 +57,8 @@
 
     public void addField(String name, Class type);
 
+    public boolean canConvert(Class inputClass);
+    
     /**
      * Convenience method for checking whether the fabricated class already contains
      * a method.

Modified: jakarta/hivemind/branches/branch-1-1/framework/src/java/org/apache/hivemind/service/ClassFabUtils.java
URL: http://svn.apache.org/viewcvs/jakarta/hivemind/branches/branch-1-1/framework/src/java/org/apache/hivemind/service/ClassFabUtils.java?rev=400325&r1=400324&r2=400325&view=diff
==============================================================================
--- jakarta/hivemind/branches/branch-1-1/framework/src/java/org/apache/hivemind/service/ClassFabUtils.java
(original)
+++ jakarta/hivemind/branches/branch-1-1/framework/src/java/org/apache/hivemind/service/ClassFabUtils.java
Sat May  6 08:43:32 2006
@@ -16,7 +16,6 @@
 
 import java.lang.reflect.Method;
 import java.lang.reflect.Modifier;
-import java.lang.reflect.Proxy;
 
 /**
  * Static class containing utility methods.
@@ -115,11 +114,11 @@
      * @param interfaceClass
      *            the interface class to return if the instance is a JDK proxy.
      */
-    public static Class getInstanceClass(Object instance, Class interfaceClass)
+    public static Class getInstanceClass(ClassFab classFab, Object instance, Class interfaceClass)
     {
         Class instanceClass = instance.getClass();
 
-        if (Proxy.isProxyClass(instanceClass))
+        if (!classFab.canConvert(instanceClass))
             return interfaceClass;
 
         return instanceClass;

Modified: jakarta/hivemind/branches/branch-1-1/framework/src/java/org/apache/hivemind/service/impl/AbstractFab.java
URL: http://svn.apache.org/viewcvs/jakarta/hivemind/branches/branch-1-1/framework/src/java/org/apache/hivemind/service/impl/AbstractFab.java?rev=400325&r1=400324&r2=400325&view=diff
==============================================================================
--- jakarta/hivemind/branches/branch-1-1/framework/src/java/org/apache/hivemind/service/impl/AbstractFab.java
(original)
+++ jakarta/hivemind/branches/branch-1-1/framework/src/java/org/apache/hivemind/service/impl/AbstractFab.java
Sat May  6 08:43:32 2006
@@ -71,6 +71,11 @@
         return result;
     }
 
+    public boolean canConvert(Class inputClass)
+    {
+    	return _source.canConvert(inputClass);
+    }
+    
     /**
      * @since 1.1
      */

Modified: jakarta/hivemind/branches/branch-1-1/framework/src/java/org/apache/hivemind/service/impl/ClassFabImpl.java
URL: http://svn.apache.org/viewcvs/jakarta/hivemind/branches/branch-1-1/framework/src/java/org/apache/hivemind/service/impl/ClassFabImpl.java?rev=400325&r1=400324&r2=400325&view=diff
==============================================================================
--- jakarta/hivemind/branches/branch-1-1/framework/src/java/org/apache/hivemind/service/impl/ClassFabImpl.java
(original)
+++ jakarta/hivemind/branches/branch-1-1/framework/src/java/org/apache/hivemind/service/impl/ClassFabImpl.java
Sat May  6 08:43:32 2006
@@ -244,7 +244,7 @@
     {
         return getCtClass().getName();
     }
-
+    
     public void addField(String name, Class type)
     {
         CtClass ctType = convertClass(type);

Modified: jakarta/hivemind/branches/branch-1-1/framework/src/java/org/apache/hivemind/service/impl/CtClassSource.java
URL: http://svn.apache.org/viewcvs/jakarta/hivemind/branches/branch-1-1/framework/src/java/org/apache/hivemind/service/impl/CtClassSource.java?rev=400325&r1=400324&r2=400325&view=diff
==============================================================================
--- jakarta/hivemind/branches/branch-1-1/framework/src/java/org/apache/hivemind/service/impl/CtClassSource.java
(original)
+++ jakarta/hivemind/branches/branch-1-1/framework/src/java/org/apache/hivemind/service/impl/CtClassSource.java
Sat May  6 08:43:32 2006
@@ -36,14 +36,24 @@
         _pool = pool;
     }
 
+    public boolean canConvert(Class searchClass) 
+    {
+    	ensureClassLoaderAvailable(searchClass);
+        String name = ClassFabUtils.getJavaClassName(searchClass);
+        try
+        {
+        	_pool.get(name);
+        	return true;
+        }
+        catch (NotFoundException ex)
+        {
+            return false;
+        }
+    }
+    
     public CtClass getCtClass(Class searchClass)
     {
-        ClassLoader loader = searchClass.getClassLoader();
-
-        // Add the class loader for the searchClass to the class pool and
-        // delegating class loader if needed.
-
-        _pool.appendClassLoader(loader);
+        ensureClassLoaderAvailable(searchClass);
 
         String name = ClassFabUtils.getJavaClassName(searchClass);
 
@@ -56,6 +66,18 @@
             throw new ApplicationRuntimeException(ServiceMessages.unableToLookupClass(name,
ex), ex);
         }
     }
+
+	/**
+	 * @param searchClass
+	 */
+	private void ensureClassLoaderAvailable(Class searchClass) {
+		ClassLoader loader = searchClass.getClassLoader();
+
+        // Add the class loader for the searchClass to the class pool and
+        // delegating class loader if needed.
+
+        _pool.appendClassLoader(loader);
+	}
 
     public CtClass newClass(String name, Class superClass)
     {

Modified: jakarta/hivemind/branches/branch-1-1/framework/src/java/org/apache/hivemind/service/impl/LoggingInterceptorFactory.java
URL: http://svn.apache.org/viewcvs/jakarta/hivemind/branches/branch-1-1/framework/src/java/org/apache/hivemind/service/impl/LoggingInterceptorFactory.java?rev=400325&r1=400324&r2=400325&view=diff
==============================================================================
--- jakarta/hivemind/branches/branch-1-1/framework/src/java/org/apache/hivemind/service/impl/LoggingInterceptorFactory.java
(original)
+++ jakarta/hivemind/branches/branch-1-1/framework/src/java/org/apache/hivemind/service/impl/LoggingInterceptorFactory.java
Sat May  6 08:43:32 2006
@@ -218,8 +218,8 @@
 
     private void createInfrastructure(InterceptorStack stack, ClassFab classFab)
     {
-        Class topClass = ClassFabUtils.getInstanceClass(stack.peek(), stack.getServiceInterface());
-
+        Class topClass = ClassFabUtils.getInstanceClass(classFab, stack.peek(), stack.getServiceInterface());
+        
         classFab.addField("_log", Log.class);
 
         // This is very important: since we know the instance of the top object (the next

Modified: jakarta/hivemind/branches/branch-1-1/framework/src/test/org/apache/hivemind/service/impl/TestClassFab.java
URL: http://svn.apache.org/viewcvs/jakarta/hivemind/branches/branch-1-1/framework/src/test/org/apache/hivemind/service/impl/TestClassFab.java?rev=400325&r1=400324&r2=400325&view=diff
==============================================================================
--- jakarta/hivemind/branches/branch-1-1/framework/src/test/org/apache/hivemind/service/impl/TestClassFab.java
(original)
+++ jakarta/hivemind/branches/branch-1-1/framework/src/test/org/apache/hivemind/service/impl/TestClassFab.java
Sat May  6 08:43:32 2006
@@ -441,10 +441,21 @@
 
     }
 
+    public void testCanConvert()
+    {
+    	final ClassFab cf = newClassFab("BamBam", Object.class);
+    	assertTrue( cf.canConvert( String.class ) );
+    	assertFalse(cf.canConvert(CglibBeanInterfaceFactory.createCglibBean().getClass()));
+    	assertFalse(cf.canConvert(JavassistBeanInterfaceFactory.createJavassistBean().getClass()));
+    	assertFalse(cf.canConvert(JdkBeanInterfaceFactory.createJdkBean().getClass()));
+    }
+    
     /** @since 1.1 */
     private void contains(String actual, String expected)
     {
         if (actual.indexOf(expected) < 0)
             throw new AssertionFailedError("Missing substring: " + expected);
     }
+    
+    
 }

Modified: jakarta/hivemind/branches/branch-1-1/framework/src/test/org/apache/hivemind/service/impl/TestClassFabUtils.java
URL: http://svn.apache.org/viewcvs/jakarta/hivemind/branches/branch-1-1/framework/src/test/org/apache/hivemind/service/impl/TestClassFabUtils.java?rev=400325&r1=400324&r2=400325&view=diff
==============================================================================
--- jakarta/hivemind/branches/branch-1-1/framework/src/test/org/apache/hivemind/service/impl/TestClassFabUtils.java
(original)
+++ jakarta/hivemind/branches/branch-1-1/framework/src/test/org/apache/hivemind/service/impl/TestClassFabUtils.java
Sat May  6 08:43:32 2006
@@ -27,63 +27,69 @@
  * Tests for {@link org.apache.hivemind.service.ClassFabUtils}
  * 
  * @author Howard Lewis Ship
+ * @author James Carman
  */
-public class TestClassFabUtils extends HiveMindTestCase
-{
-    public void testGetInstanceClassName()
-    {
-        Runnable subject = new Runnable()
-        {
-            public void run()
-            {
-            }
-        };
-
-        assertSame(subject.getClass(), ClassFabUtils.getInstanceClass(subject, Runnable.class));
-
-        Runnable mock = (Runnable) newMock(Runnable.class);
-
-        assertSame(Runnable.class, ClassFabUtils.getInstanceClass(mock, Runnable.class));
-    }
-
-    /** @since 1.1 */
-    public void testAddNoOpMethod()
-    {
-        tryAddNoOpMethod(void.class, "{  }");
-        tryAddNoOpMethod(String.class, "{ return null; }");
-        tryAddNoOpMethod(boolean.class, "{ return false; }");
-        tryAddNoOpMethod(char.class, "{ return 0; }");
-        tryAddNoOpMethod(short.class, "{ return 0; }");
-        tryAddNoOpMethod(int.class, "{ return 0; }");
-        tryAddNoOpMethod(long.class, "{ return 0L; }");
-        tryAddNoOpMethod(double.class, "{ return 0.0d; }");
-        tryAddNoOpMethod(float.class, "{ return 0.0f; }");
-    }
-
-    /** @since 1.1 */
-    private void tryAddNoOpMethod(Class returnClass, String expectedBody)
-    {
-        MethodSignature sig = new MethodSignature(returnClass, "run", null, null);
-
-        MockControl control = newControl(ClassFab.class);
-        ClassFab cf = (ClassFab) control.getMock();
-        MethodFab mf = (MethodFab) newMock(MethodFab.class);
-
-        cf.addMethod(Modifier.PUBLIC, sig, expectedBody);
-        control.setReturnValue(mf);
-
-        replayControls();
-
-        ClassFabUtils.addNoOpMethod(cf, sig);
-
-        verifyControls();
-    }
-
-    /** @since 1.1 */
-    public void testGenerateClassName() throws Exception
-    {
-        String name = ClassFabUtils.generateClassName(Runnable.class);
+public class TestClassFabUtils extends HiveMindTestCase {
+	
 
-        assertRegexp("\\$Runnable_([0-9|a-f])+", name);
-    }
+	public void testGetInstanceClassName() {
+		final HiveMindClassPool pool = new HiveMindClassPool();
+		final CtClassSource classSource = new CtClassSource(pool);
+		final ClassFab classFab = new ClassFabImpl(classSource, pool
+				.makeClass("Dummy"));
+		assertSame(ClassFabUtils.getInstanceClass(classFab,
+				new BeanInterfaceImpl(), BeanInterface.class),
+				BeanInterfaceImpl.class);
+		assertSame( ClassFabUtils.getInstanceClass(classFab,CglibBeanInterfaceFactory.createCglibBean(),
BeanInterface.class ), BeanInterface.class );
+		assertSame( ClassFabUtils.getInstanceClass(classFab,JavassistBeanInterfaceFactory.createJavassistBean(),
BeanInterface.class ), BeanInterface.class );
+		assertSame( ClassFabUtils.getInstanceClass(classFab,JdkBeanInterfaceFactory.createJdkBean(),
BeanInterface.class ), BeanInterface.class );
+		
+	}
+
+	public static class BeanInterfaceImpl implements BeanInterface {
+
+		public String interfaceMethod() {
+			return "Hello, World!";
+		}
+
+	}
+
+	/** @since 1.1 */
+	public void testAddNoOpMethod() {
+		tryAddNoOpMethod(void.class, "{  }");
+		tryAddNoOpMethod(String.class, "{ return null; }");
+		tryAddNoOpMethod(boolean.class, "{ return false; }");
+		tryAddNoOpMethod(char.class, "{ return 0; }");
+		tryAddNoOpMethod(short.class, "{ return 0; }");
+		tryAddNoOpMethod(int.class, "{ return 0; }");
+		tryAddNoOpMethod(long.class, "{ return 0L; }");
+		tryAddNoOpMethod(double.class, "{ return 0.0d; }");
+		tryAddNoOpMethod(float.class, "{ return 0.0f; }");
+	}
+
+	/** @since 1.1 */
+	private void tryAddNoOpMethod(Class returnClass, String expectedBody) {
+		MethodSignature sig = new MethodSignature(returnClass, "run", null,
+				null);
+
+		MockControl control = newControl(ClassFab.class);
+		ClassFab cf = (ClassFab) control.getMock();
+		MethodFab mf = (MethodFab) newMock(MethodFab.class);
+
+		cf.addMethod(Modifier.PUBLIC, sig, expectedBody);
+		control.setReturnValue(mf);
+
+		replayControls();
+
+		ClassFabUtils.addNoOpMethod(cf, sig);
+
+		verifyControls();
+	}
+
+	/** @since 1.1 */
+	public void testGenerateClassName() throws Exception {
+		String name = ClassFabUtils.generateClassName(Runnable.class);
+
+		assertRegexp("\\$Runnable_([0-9|a-f])+", name);
+	}
 }

Modified: jakarta/hivemind/branches/branch-1-1/framework/src/test/org/apache/hivemind/service/impl/TestLoggingInterceptorFactory.java
URL: http://svn.apache.org/viewcvs/jakarta/hivemind/branches/branch-1-1/framework/src/test/org/apache/hivemind/service/impl/TestLoggingInterceptorFactory.java?rev=400325&r1=400324&r2=400325&view=diff
==============================================================================
--- jakarta/hivemind/branches/branch-1-1/framework/src/test/org/apache/hivemind/service/impl/TestLoggingInterceptorFactory.java
(original)
+++ jakarta/hivemind/branches/branch-1-1/framework/src/test/org/apache/hivemind/service/impl/TestLoggingInterceptorFactory.java
Sat May  6 08:43:32 2006
@@ -17,6 +17,7 @@
 import java.util.Collections;
 
 import org.apache.commons.logging.Log;
+import org.apache.hivemind.Registry;
 import org.apache.hivemind.impl.InterceptorStackImpl;
 import org.apache.hivemind.internal.Module;
 import org.apache.hivemind.internal.ServicePoint;
@@ -28,6 +29,7 @@
  * Tests for {@link org.apache.hivemind.service.impl.LoggingInterceptorFactory}.
  * 
  * @author Howard Lewis Ship
+ * @author James Carman
  */
 public class TestLoggingInterceptorFactory extends HiveMindTestCase
 {
@@ -85,4 +87,23 @@
 
         verifyControls();
     }
+    
+    public void testJavassistProxies() throws Exception {
+		final Registry reg = buildFrameworkRegistry("generated.xml" );
+		final BeanInterface bean = ( BeanInterface )reg.getService( "generated.JavassistBeanInterface",
BeanInterface.class );
+		bean.interfaceMethod();
+	}
+	
+	public void testCglibProxies() throws Exception {
+		final Registry reg = buildFrameworkRegistry("generated.xml" );
+		final BeanInterface bean = ( BeanInterface )reg.getService( "generated.CglibBeanInterface",
BeanInterface.class );
+		bean.interfaceMethod();
+	}
+	
+	public void testJdkProxies() throws Exception {
+		final Registry reg = buildFrameworkRegistry("generated.xml" );
+		final BeanInterface bean = ( BeanInterface )reg.getService( "generated.JdkBeanInterface",
BeanInterface.class );
+		bean.interfaceMethod();
+	}
+	
 }

Modified: jakarta/hivemind/branches/branch-1-1/library/src/java/org/apache/hivemind/lib/impl/ServicePropertyFactory.java
URL: http://svn.apache.org/viewcvs/jakarta/hivemind/branches/branch-1-1/library/src/java/org/apache/hivemind/lib/impl/ServicePropertyFactory.java?rev=400325&r1=400324&r2=400325&view=diff
==============================================================================
--- jakarta/hivemind/branches/branch-1-1/library/src/java/org/apache/hivemind/lib/impl/ServicePropertyFactory.java
(original)
+++ jakarta/hivemind/branches/branch-1-1/library/src/java/org/apache/hivemind/lib/impl/ServicePropertyFactory.java
Sat May  6 08:43:32 2006
@@ -99,7 +99,7 @@
     {
         cf.addInterface(serviceInterface);
 
-        Class targetServiceClass = ClassFabUtils.getInstanceClass(targetService, serviceInterface);
+        Class targetServiceClass = ClassFabUtils.getInstanceClass(cf, targetService, serviceInterface);
 
         cf.addField("_targetService", targetServiceClass);
 

Modified: jakarta/hivemind/branches/branch-1-1/status.xml
URL: http://svn.apache.org/viewcvs/jakarta/hivemind/branches/branch-1-1/status.xml?rev=400325&r1=400324&r2=400325&view=diff
==============================================================================
--- jakarta/hivemind/branches/branch-1-1/status.xml (original)
+++ jakarta/hivemind/branches/branch-1-1/status.xml Sat May  6 08:43:32 2006
@@ -28,6 +28,9 @@
     </actions>
   </todo>
   <changes>
+    <release version="1.1.2" date="unreleased">
+      <action type="fix" dev="JC" fixes-bug="HIVEMIND-176">HiveMind LoggingInterceptor
incompatible with proxies generated by outside means (CGLIB or Javassist)</action>
+    </release> 
     <release version="1.1.1" date="Jan 28 2006">
       <action type="fix" dev="HLS" fixes-bug="HIVEMIND-162">Performance bottleneck
with threaded services</action>
       <action type="fix" dev="HLS" fixes-bug="HIVEMIND-161">ThreadLocal object is never
removed in ThreadEventNotifierImpl and holds the classloader</action>



---------------------------------------------------------------------
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