You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@aries.apache.org by cs...@apache.org on 2016/06/24 12:39:35 UTC
[1/2] aries-rsa git commit: [ARIES-1582] fastbin should handle object
methods locally
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....@seeburger.de>
Authored: Thu Jun 23 11:18:01 2016 +0200
Committer: Christian Schneider <ch...@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;
+ }
}
[2/2] aries-rsa git commit: [ARIES-1582] Fixes on fastbin tests
Posted by cs...@apache.org.
[ARIES-1582] Fixes on fastbin tests
Project: http://git-wip-us.apache.org/repos/asf/aries-rsa/repo
Commit: http://git-wip-us.apache.org/repos/asf/aries-rsa/commit/99f1571e
Tree: http://git-wip-us.apache.org/repos/asf/aries-rsa/tree/99f1571e
Diff: http://git-wip-us.apache.org/repos/asf/aries-rsa/diff/99f1571e
Branch: refs/heads/master
Commit: 99f1571efaf481cf30d797ab582500c65135bf46
Parents: 3d33d29
Author: Christian Schneider <ch...@die-schneider.net>
Authored: Fri Jun 24 14:39:27 2016 +0200
Committer: Christian Schneider <ch...@die-schneider.net>
Committed: Fri Jun 24 14:39:27 2016 +0200
----------------------------------------------------------------------
.../aries/rsa/provider/fastbin/tcp/ClientInvokerImpl.java | 7 +++++--
.../org/apache/aries/rsa/provider/fastbin/InvocationTest.java | 2 +-
2 files changed, 6 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/aries-rsa/blob/99f1571e/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 a0b0f2c..877b297 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
@@ -24,6 +24,7 @@ import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.Map;
import java.util.WeakHashMap;
+import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;
@@ -42,6 +43,7 @@ import org.fusesource.hawtbuf.DataByteArrayInputStream;
import org.fusesource.hawtbuf.DataByteArrayOutputStream;
import org.fusesource.hawtbuf.UTF8Buffer;
import org.fusesource.hawtdispatch.DispatchQueue;
+import org.osgi.framework.ServiceException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -51,7 +53,8 @@ public class ClientInvokerImpl implements ClientInvoker, Dispatched {
protected static final Logger LOGGER = LoggerFactory.getLogger(ClientInvokerImpl.class);
- private final static HashMap<Class,String> CLASS_TO_PRIMITIVE = new HashMap<Class, String>(8, 1.0F);
+ @SuppressWarnings("rawtypes")
+ private final static Map<Class,String> CLASS_TO_PRIMITIVE = new HashMap<Class, String>(8, 1.0F);
static {
CLASS_TO_PRIMITIVE.put(boolean.class,"Z");
@@ -134,7 +137,7 @@ public class ClientInvokerImpl implements ClientInvoker, Dispatched {
protected void onCommand(TransportPool pool, Object data) {
try {
DataByteArrayInputStream bais = new DataByteArrayInputStream( (Buffer) data);
- int size = bais.readInt();
+ bais.readInt();
long correlation = bais.readVarLong();
pool.onDone(correlation);
ResponseFuture response = requests.remove(correlation);
http://git-wip-us.apache.org/repos/asf/aries-rsa/blob/99f1571e/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 1cde9b2..7725375 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
@@ -132,7 +132,7 @@ public class InvocationTest {
}
}, HelloImpl.class.getClassLoader());
- InvocationHandler handler = client.getProxy(server.getConnectAddress(), "service-id", HelloImpl.class.getClassLoader(),FastBinProvider.PROTOCOL_VERSION);
+ InvocationHandler handler = client.getProxy(server.getConnectAddress(), "service-id", HelloImpl.class.getClassLoader());
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));