aries-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cschnei...@apache.org
Subject [1/2] aries-rsa git commit: [ARIES-1582] fastbin should handle object methods locally
Date Fri, 24 Jun 2016 12:39:35 GMT
Repository: aries-rsa
Updated Branches:
  refs/heads/master 659bba76d -> 99f1571ef


[ARIES-1582] fastbin should handle object methods locally


Project: http://git-wip-us.apache.org/repos/asf/aries-rsa/repo
Commit: http://git-wip-us.apache.org/repos/asf/aries-rsa/commit/3d33d291
Tree: http://git-wip-us.apache.org/repos/asf/aries-rsa/tree/3d33d291
Diff: http://git-wip-us.apache.org/repos/asf/aries-rsa/diff/3d33d291

Branch: refs/heads/master
Commit: 3d33d291f82384648a2ec81e1a81936bde37d48c
Parents: 659bba7
Author: Johannes Utzig <j.utzig@seeburger.de>
Authored: Thu Jun 23 11:18:01 2016 +0200
Committer: Christian Schneider <chris@die-schneider.net>
Committed: Fri Jun 24 14:30:34 2016 +0200

----------------------------------------------------------------------
 .../provider/fastbin/tcp/ClientInvokerImpl.java | 24 ++++++++++-
 .../rsa/provider/fastbin/InvocationTest.java    | 45 ++++++++++++++++++--
 2 files changed, 65 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/aries-rsa/blob/3d33d291/provider/fastbin/src/main/java/org/apache/aries/rsa/provider/fastbin/tcp/ClientInvokerImpl.java
----------------------------------------------------------------------
diff --git a/provider/fastbin/src/main/java/org/apache/aries/rsa/provider/fastbin/tcp/ClientInvokerImpl.java
b/provider/fastbin/src/main/java/org/apache/aries/rsa/provider/fastbin/tcp/ClientInvokerImpl.java
index dd8c8e8..a0b0f2c 100644
--- a/provider/fastbin/src/main/java/org/apache/aries/rsa/provider/fastbin/tcp/ClientInvokerImpl.java
+++ b/provider/fastbin/src/main/java/org/apache/aries/rsa/provider/fastbin/tcp/ClientInvokerImpl.java
@@ -295,7 +295,29 @@ public class ClientInvokerImpl implements ClientInvoker, Dispatched {
         }
 
         public Object invoke(Object proxy, Method method, Object[] args) throws Throwable
{
-            return request(this, address, service, classLoader, method, args);
+            try {
+                if(method.getDeclaringClass()==Object.class) {
+                    //shortcut for equals, hashcode,...
+                    return method.invoke(this, args);
+                }
+                return request(this, address, service, classLoader, method, args);
+            }
+            catch (Throwable e) {
+                if (e instanceof ExecutionException) {
+                    ExecutionException executionException = (ExecutionException)e;
+                    e = executionException.getCause();
+                }
+                if (e instanceof RuntimeException) {
+                    RuntimeException runtimeException = (RuntimeException)e;
+                    throw runtimeException;
+                }
+                Class< ? >[] exceptionTypes = method.getExceptionTypes();
+                for (Class< ? > exceptionType : exceptionTypes) {
+                    if(exceptionType.isAssignableFrom(e.getClass()))
+                        throw e;
+                }
+                throw new ServiceException(e.getMessage(), e);
+            }
         }
 
     }

http://git-wip-us.apache.org/repos/asf/aries-rsa/blob/3d33d291/provider/fastbin/src/test/java/org/apache/aries/rsa/provider/fastbin/InvocationTest.java
----------------------------------------------------------------------
diff --git a/provider/fastbin/src/test/java/org/apache/aries/rsa/provider/fastbin/InvocationTest.java
b/provider/fastbin/src/test/java/org/apache/aries/rsa/provider/fastbin/InvocationTest.java
index 2c7a9e6..1cde9b2 100644
--- a/provider/fastbin/src/test/java/org/apache/aries/rsa/provider/fastbin/InvocationTest.java
+++ b/provider/fastbin/src/test/java/org/apache/aries/rsa/provider/fastbin/InvocationTest.java
@@ -18,6 +18,9 @@
  */
 package org.apache.aries.rsa.provider.fastbin;
 
+import static org.fusesource.hawtdispatch.Dispatch.createQueue;
+import static org.junit.Assert.*;
+
 import java.lang.reflect.InvocationHandler;
 import java.lang.reflect.Proxy;
 import java.lang.reflect.UndeclaredThrowableException;
@@ -43,9 +46,6 @@ import org.fusesource.hawtdispatch.Dispatch;
 import org.fusesource.hawtdispatch.DispatchQueue;
 import org.junit.Test;
 
-import static org.fusesource.hawtdispatch.Dispatch.createQueue;
-import static org.junit.Assert.assertEquals;
-
 public class InvocationTest {
     final static long MILLIS_IN_A_NANO = TimeUnit.MILLISECONDS.toNanos(1);
     final static long SECONDS_IN_A_NANO = TimeUnit.SECONDS.toNanos(1);
@@ -109,6 +109,40 @@ public class InvocationTest {
         }
     }
 
+
+    @Test
+    public void testObjectMethods() throws Exception {
+
+        DispatchQueue queue = Dispatch.createQueue();
+        HashMap<String, SerializationStrategy> map = new HashMap<String, SerializationStrategy>();
+        map.put("protobuf", new ProtobufSerializationStrategy());
+
+        ServerInvokerImpl server = new ServerInvokerImpl("tcp://localhost:0", queue, map);
+        server.start();
+
+        ClientInvokerImpl client = new ClientInvokerImpl(queue, map);
+        client.start();
+        final HelloImpl serviceImpl = new HelloImpl();
+        try {
+            server.registerService("service-id", new ServerInvoker.ServiceFactory() {
+                public Object get() {
+                    return serviceImpl;
+                }
+                public void unget() {
+                }
+            }, HelloImpl.class.getClassLoader());
+
+            InvocationHandler handler = client.getProxy(server.getConnectAddress(), "service-id",
HelloImpl.class.getClassLoader(),FastBinProvider.PROTOCOL_VERSION);
+            Hello hello  = (Hello) Proxy.newProxyInstance(HelloImpl.class.getClassLoader(),
new Class[] { Hello.class }, handler);
+            assertNotEquals("Hashcode should be handled by the proxy and not be a remote
call",-7, hello.hashCode());
+            assertFalse("equals should be handled by the proxy and not be a remote call",hello.equals(serviceImpl));
+        }
+        finally {
+            server.stop();
+            client.stop();
+        }
+    }
+
     @Test(timeout=30*1000)
     public void testOverflowAsync() throws Exception {
 
@@ -578,6 +612,11 @@ public class InvocationTest {
             return 'f';
         }
 
+        @Override
+        public int hashCode()
+        {
+            return -7;
+        }
     }
 
 


Mime
View raw message