From 3ef15fbfd25f26acdc98c78d3ece669a5013b1c2 Mon Sep 17 00:00:00 2001 From: robdu Date: Wed, 2 Sep 2020 18:45:24 +0200 Subject: [PATCH] upgrade vertx to 3.9.2 + remove reflectasm from Protocol. --- README.md | 1 - build.gradle | 2 +- core/build.gradle | 15 +++-- .../codingchili/core/protocol/Protocol.java | 30 ++++++---- .../core/listener/RestRequestTest.java | 57 ++++++++++++++++--- .../AuthenticationGenerator/service1.json | 2 +- .../AuthenticationGenerator/service2.json | 2 +- docs/protocol.md | 7 ++- 8 files changed, 82 insertions(+), 34 deletions(-) diff --git a/README.md b/README.md index 9a82efe2..516c2a2f 100644 --- a/README.md +++ b/README.md @@ -119,7 +119,6 @@ The core uses some great software, such as * [eclipse/vert.x](https://github.com/eclipse/vert.x) - reactive: eventbus, clustering and networking * [EsotericSoftware/kryo](https://github.com/EsotericSoftware/kryo) - serialization library -* [EsotericSoftware/reflectasm](https://github.com/EsotericSoftware/reflectasm) - fast reflections library Optional dependencies diff --git a/build.gradle b/build.gradle index c9bb275b..153371b3 100644 --- a/build.gradle +++ b/build.gradle @@ -2,7 +2,7 @@ apply plugin: 'java' apply plugin: 'idea' apply plugin: 'maven' -project.version = "1.3.3" +project.version = "1.3.4" project.group = 'com.github.codingchili.chili-core' subprojects { diff --git a/core/build.gradle b/core/build.gradle index 67ab54ce..170a26b2 100644 --- a/core/build.gradle +++ b/core/build.gradle @@ -28,24 +28,23 @@ artifacts { } dependencies { - compile 'io.vertx:vertx-core:3.8.0' - compile 'io.vertx:vertx-web:3.8.0' - compile 'io.vertx:vertx-hazelcast:3.8.0' - compile 'io.vertx:vertx-mongo-client:3.8.0' - compile 'io.vertx:vertx-dropwizard-metrics:3.8.0' + compile 'io.vertx:vertx-core:3.9.2' + compile 'io.vertx:vertx-web:3.9.2' + compile 'io.vertx:vertx-hazelcast:3.9.2' + compile 'io.vertx:vertx-mongo-client:3.9.2' + compile 'io.vertx:vertx-dropwizard-metrics:3.9.2' compile 'de.neuland-bfi:jade4j:1.2.7' compile 'de.mkammerer:argon2-jvm:2.5' compile 'org.fusesource.jansi:jansi:1.18' - compile 'com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:2.9.9' + compile 'com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:2.11.2' compile 'org.elasticsearch.client:elasticsearch-rest-high-level-client:7.3.0' compile 'com.googlecode.cqengine:cqengine:3.5.0' /* keep these in sync with cqengine, used internally. */ - compile 'com.esotericsoftware:reflectasm:1.11.9' compile 'com.esotericsoftware:kryo:5.0.0-RC6' - testCompile 'io.vertx:vertx-unit:3.8.0' + testCompile 'io.vertx:vertx-unit:3.9.2' testCompile 'junit:junit:4.12' } diff --git a/core/main/java/com/codingchili/core/protocol/Protocol.java b/core/main/java/com/codingchili/core/protocol/Protocol.java index 6d3f7344..aee11fe0 100644 --- a/core/main/java/com/codingchili/core/protocol/Protocol.java +++ b/core/main/java/com/codingchili/core/protocol/Protocol.java @@ -1,9 +1,9 @@ package com.codingchili.core.protocol; -import com.esotericsoftware.reflectasm.MethodAccess; import io.vertx.core.Future; import io.vertx.core.buffer.Buffer; +import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.util.Objects; import java.util.Set; @@ -31,6 +31,9 @@ * route. The documentation route is enabled whenever a handler class or route * is documented using either #{@link #document(String)}, #{@link #setDescription(String)} * or by adding the #{@link Description} annotation to the class or handler method. + *

+ * Aug, 2020 - removed use of reflectasm as method reflection in J11 is 10% faster. + * If setAccessible(true) is called then J11 reflection is 50% faster. */ public class Protocol { private AuthorizationHandler authorizer = new SimpleAuthorizationHandler<>(); @@ -133,9 +136,13 @@ private void readMapper(Method method, Receiver handler) { RouteMapper mapper = method.getAnnotation(RouteMapper.class); if (mapper != null) { - MethodAccess access = MethodAccess.get(handler.getClass()); - int index = access.getIndex(method.getName()); - this.routeMapper = (request) -> (String) access.invoke(handler, index, request); + this.routeMapper = (request) -> { + try { + return (String) method.invoke(handler, request); + } catch (IllegalAccessException | InvocationTargetException e) { + throw new RuntimeException(e); + } + }; } } @@ -144,9 +151,13 @@ private void readAuthenticator(Method method, Receiver handler) { Authenticator authenticator = method.getAnnotation(Authenticator.class); if (authenticator != null) { - MethodAccess access = MethodAccess.get(handler.getClass()); - int index = access.getIndex(method.getName()); - this.authenticator = (request) -> (Future) access.invoke(handler, index, request); + this.authenticator = (request) -> { + try { + return (Future) method.invoke(handler, request); + } catch (IllegalAccessException | InvocationTargetException e) { + throw new RuntimeException(e); + } + }; } } @@ -200,12 +211,9 @@ public Protocol setRole(RoleType... role) { } private void wrap(String route, Receiver handler, Method method, RoleType[] role) { - MethodAccess access = MethodAccess.get(handler.getClass()); - - int index = access.getIndex(method.getName()); use(route, request -> { try { - access.invoke(handler, index, request); + method.invoke(handler, request); } catch (Throwable e) { if (e instanceof RuntimeException) { throw (RuntimeException) e; diff --git a/core/test/java/com/codingchili/core/listener/RestRequestTest.java b/core/test/java/com/codingchili/core/listener/RestRequestTest.java index 679db27f..419c79dd 100644 --- a/core/test/java/com/codingchili/core/listener/RestRequestTest.java +++ b/core/test/java/com/codingchili/core/listener/RestRequestTest.java @@ -1,18 +1,23 @@ package com.codingchili.core.listener; -import io.vertx.core.*; +import com.codingchili.core.listener.transport.RestRequest; +import io.vertx.core.AsyncResult; +import io.vertx.core.Handler; +import io.vertx.core.MultiMap; +import io.vertx.core.Vertx; import io.vertx.core.buffer.Buffer; +import io.vertx.core.http.Cookie; import io.vertx.core.http.*; import io.vertx.core.json.JsonArray; import io.vertx.core.json.JsonObject; import io.vertx.core.net.NetSocket; import io.vertx.core.net.SocketAddress; import io.vertx.ext.auth.User; -import io.vertx.ext.unit.junit.VertxUnitRunner; -import io.vertx.ext.web.*; import io.vertx.ext.unit.TestContext; +import io.vertx.ext.unit.junit.VertxUnitRunner; import io.vertx.ext.web.Locale; import io.vertx.ext.web.Session; +import io.vertx.ext.web.*; import org.junit.After; import org.junit.Test; import org.junit.runner.RunWith; @@ -22,8 +27,6 @@ import javax.security.cert.X509Certificate; import java.util.*; -import com.codingchili.core.listener.transport.RestRequest; - import static com.codingchili.core.configuration.CoreStrings.PROTOCOL_ROUTE; import static com.codingchili.core.configuration.CoreStrings.PROTOCOL_TARGET; @@ -332,6 +335,21 @@ public HttpConnection connection() { public HttpServerRequest streamPriorityHandler(Handler handler) { return this; } + + @Override + public Cookie getCookie(String name) { + return null; + } + + @Override + public int cookieCount() { + return 0; + } + + @Override + public Map cookieMap() { + return null; + } }; } @@ -401,7 +419,7 @@ public String normalisedPath() { } @Override - public Cookie getCookie(String s) { + public io.vertx.ext.web.Cookie getCookie(String name) { return null; } @@ -411,12 +429,12 @@ public RoutingContext addCookie(Cookie cookie) { } @Override - public Cookie removeCookie(String s) { + public RoutingContext addCookie(io.vertx.ext.web.Cookie cookie) { return null; } @Override - public Cookie removeCookie(String name, boolean invalidate) { + public io.vertx.ext.web.Cookie removeCookie(String name, boolean invalidate) { return null; } @@ -426,10 +444,16 @@ public int cookieCount() { } @Override - public Set cookies() { + public Set cookies() { return null; } + @Override + public Map cookieMap() { + return null; + } + + @Override public String getBodyAsString() { return null; @@ -465,6 +489,11 @@ public Session session() { return null; } + @Override + public boolean isSessionAccessed() { + return false; + } + @Override public User user() { return null; @@ -510,6 +539,16 @@ public boolean removeBodyEndHandler(int i) { return false; } + @Override + public int addEndHandler(Handler> handler) { + return 0; + } + + @Override + public boolean removeEndHandler(int handlerID) { + return false; + } + @Override public boolean failed() { return false; diff --git a/core/test/resources/AuthenticationGenerator/service1.json b/core/test/resources/AuthenticationGenerator/service1.json index 9e26dfee..6f31cf5a 100644 --- a/core/test/resources/AuthenticationGenerator/service1.json +++ b/core/test/resources/AuthenticationGenerator/service1.json @@ -1 +1 @@ -{} \ No newline at end of file +{ } \ No newline at end of file diff --git a/core/test/resources/AuthenticationGenerator/service2.json b/core/test/resources/AuthenticationGenerator/service2.json index 9e26dfee..6f31cf5a 100644 --- a/core/test/resources/AuthenticationGenerator/service2.json +++ b/core/test/resources/AuthenticationGenerator/service2.json @@ -1 +1 @@ -{} \ No newline at end of file +{ } \ No newline at end of file diff --git a/docs/protocol.md b/docs/protocol.md index 2c04cf6f..63bce617 100644 --- a/docs/protocol.md +++ b/docs/protocol.md @@ -5,8 +5,11 @@ features role-based access control through an AuthorizationHandler. Javadoc can be found [here](javadoc/com/codingchili/core/protocol/package-summary.html). -The dynamic invocation when using annotations uses ReflectASM and is pretty fast. If the programmatic -API is used instead, reflection will not be used at all. +The dynamic invocation when using annotations uses Java reflection and is pretty fast. Previous +versions of chili-core used reflectasm but as of J11 Java reflection is 10% faster, or 50% faster +if `setAccessible(true)` is called. + +If the programmatic API is used instead, reflection will not be used at all. ### Registering a protocol There are two ways of creating a protocol mapping, lets create the protocol instance first.