You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by ch...@apache.org on 2009/12/16 00:23:42 UTC

svn commit: r891069 - in /activemq/sandbox/activemq-apollo-actor/activemq-dispatcher/src: main/java/org/apache/activemq/actor/ test/java/org/apache/activemq/actor/

Author: chirino
Date: Tue Dec 15 23:23:41 2009
New Revision: 891069

URL: http://svn.apache.org/viewvc?rev=891069&view=rev
Log:
better type handing for the asm based actor generator

Added:
    activemq/sandbox/activemq-apollo-actor/activemq-dispatcher/src/test/java/org/apache/activemq/actor/AsmActorTest.java
Removed:
    activemq/sandbox/activemq-apollo-actor/activemq-dispatcher/src/test/java/org/apache/activemq/actor/OrderRunnable.java
Modified:
    activemq/sandbox/activemq-apollo-actor/activemq-dispatcher/src/main/java/org/apache/activemq/actor/AsmActor.java
    activemq/sandbox/activemq-apollo-actor/activemq-dispatcher/src/test/java/org/apache/activemq/actor/PizzaServiceCustomProxy.java

Modified: activemq/sandbox/activemq-apollo-actor/activemq-dispatcher/src/main/java/org/apache/activemq/actor/AsmActor.java
URL: http://svn.apache.org/viewvc/activemq/sandbox/activemq-apollo-actor/activemq-dispatcher/src/main/java/org/apache/activemq/actor/AsmActor.java?rev=891069&r1=891068&r2=891069&view=diff
==============================================================================
--- activemq/sandbox/activemq-apollo-actor/activemq-dispatcher/src/main/java/org/apache/activemq/actor/AsmActor.java (original)
+++ activemq/sandbox/activemq-apollo-actor/activemq-dispatcher/src/main/java/org/apache/activemq/actor/AsmActor.java Tue Dec 15 23:23:41 2009
@@ -137,11 +137,13 @@
                 for (int index = 0; index < methods.length; index++) {
                     Method method = methods[index];
                     
-                    
                     Class<?>[] params = method.getParameterTypes();
+                    Type[] types = Type.getArgumentTypes(method);
+                    
+                    String methodSig = Type.getMethodDescriptor(method);
                     
                     // example: public void order(final long count)
-                    mv = cw.visitMethod(ACC_PUBLIC, method.getName(), "("+sig(params)+")V", null, null); 
+                    mv = cw.visitMethod(ACC_PUBLIC, method.getName(), methodSig, null, null); 
                     {
                         mv.visitCode();
                         
@@ -156,8 +158,7 @@
                         mv.visitFieldInsn(GETFIELD, proxyName, "target", sig(interfaceName));
                         
                         for (int i = 0; i < params.length; i++) {
-                            // TODO: pick the right load
-                            mv.visitVarInsn(LLOAD, 1+i);
+                            mv.visitVarInsn(types[i].getOpcode(ILOAD), 1+i);
                         }
                         
                         mv.visitMethodInsn(INVOKESPECIAL, runnable(index), "<init>", "(" + sig(interfaceName) + sig(params) +")V");
@@ -201,6 +202,8 @@
                 // example: private final long count;
                 
                 Class<?>[] params = method.getParameterTypes();
+                Type[] types = Type.getArgumentTypes(method);
+                
                 for (int i = 0; i < params.length; i++) {
                     fv = cw.visitField(ACC_PRIVATE + ACC_FINAL, "param"+i, sig(params[i]), null, null);
                     fv.visitEnd();
@@ -227,7 +230,7 @@
                         
                         // TODO: figure out how to do the right loads. it varies with the type.
                         mv.visitVarInsn(ALOAD, 0);
-                        mv.visitVarInsn(LLOAD, 2+i);
+                        mv.visitVarInsn(types[i].getOpcode(ILOAD), 2+i);
                         mv.visitFieldInsn(PUTFIELD, runnable(index), "param"+i, sig(params[i]));
                         
                     }

Added: activemq/sandbox/activemq-apollo-actor/activemq-dispatcher/src/test/java/org/apache/activemq/actor/AsmActorTest.java
URL: http://svn.apache.org/viewvc/activemq/sandbox/activemq-apollo-actor/activemq-dispatcher/src/test/java/org/apache/activemq/actor/AsmActorTest.java?rev=891069&view=auto
==============================================================================
--- activemq/sandbox/activemq-apollo-actor/activemq-dispatcher/src/test/java/org/apache/activemq/actor/AsmActorTest.java (added)
+++ activemq/sandbox/activemq-apollo-actor/activemq-dispatcher/src/test/java/org/apache/activemq/actor/AsmActorTest.java Tue Dec 15 23:23:41 2009
@@ -0,0 +1,72 @@
+package org.apache.activemq.actor;
+
+import junit.framework.Assert;
+
+import org.apache.activemq.dispatch.internal.AbstractSerialDispatchQueue;
+import org.junit.Test;
+
+import static junit.framework.Assert.*;
+
+public class AsmActorTest {
+
+    public static interface TestInterface {
+        void strings(String value, String[] value2);
+        void shorts(short value, short[] value2);
+    }
+    
+    static class TestMock implements TestInterface {
+        public void shorts(short value, short[] value2) {
+            fail();
+        }
+        public void strings(String value, String[] value2) {
+            fail();
+        }
+    }
+
+    private TestMock service;
+    private TestInterface proxy;
+            
+    private AbstractSerialDispatchQueue createQueue() {
+        return new AbstractSerialDispatchQueue("mock queue") {
+            public void dispatchAsync(Runnable runnable) {
+                runnable.run();
+            }
+        };
+    }
+    
+    @Test
+    public void strings() throws Exception {
+
+        final String expected1 = "hello";
+        final String expected2[] = {"world"};
+        
+        service = new TestMock() {
+            public void strings(String actual1, String[] actual2) {
+                Assert.assertEquals(expected1, actual1);
+                Assert.assertEquals(expected2, actual2);
+            }
+        };
+        
+        proxy = AsmActor.create(TestInterface.class, service, createQueue());
+        proxy.strings(expected1, expected2);
+
+    }
+
+    @Test
+    public void shorts() throws Exception {
+
+        final short expected1 = 37;
+        final short expected2[] = {45,37};
+        
+        service = new TestMock() {
+            public void shorts(short actual1, short[] actual2) {
+                Assert.assertEquals(expected1, actual1);
+                Assert.assertEquals(expected2, actual2);
+            }
+        };
+        
+        proxy = AsmActor.create(TestInterface.class, service, createQueue());
+        proxy.shorts(expected1, expected2);
+
+    }
+}

Modified: activemq/sandbox/activemq-apollo-actor/activemq-dispatcher/src/test/java/org/apache/activemq/actor/PizzaServiceCustomProxy.java
URL: http://svn.apache.org/viewvc/activemq/sandbox/activemq-apollo-actor/activemq-dispatcher/src/test/java/org/apache/activemq/actor/PizzaServiceCustomProxy.java?rev=891069&r1=891068&r2=891069&view=diff
==============================================================================
--- activemq/sandbox/activemq-apollo-actor/activemq-dispatcher/src/test/java/org/apache/activemq/actor/PizzaServiceCustomProxy.java (original)
+++ activemq/sandbox/activemq-apollo-actor/activemq-dispatcher/src/test/java/org/apache/activemq/actor/PizzaServiceCustomProxy.java Tue Dec 15 23:23:41 2009
@@ -29,7 +29,11 @@
     }
 
     public void order(final long count) {
-        queue.dispatchAsync(new OrderRunnable(target, count));
+        queue.dispatchAsync(new Runnable(){
+            public void run() {
+                target.order(count);
+            }
+        });
     }
     
 }
\ No newline at end of file