Skip to content

Commit

Permalink
upgrade vertx to 3.9.2 + remove reflectasm from Protocol.
Browse files Browse the repository at this point in the history
  • Loading branch information
robdu committed Sep 2, 2020
1 parent f27f723 commit 3ef15fb
Show file tree
Hide file tree
Showing 8 changed files with 82 additions and 34 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
15 changes: 7 additions & 8 deletions core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}
30 changes: 19 additions & 11 deletions core/main/java/com/codingchili/core/protocol/Protocol.java
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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.
* <p>
* 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<RequestType> {
private AuthorizationHandler<RequestType> authorizer = new SimpleAuthorizationHandler<>();
Expand Down Expand Up @@ -133,9 +136,13 @@ private void readMapper(Method method, Receiver<RequestType> 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);
}
};
}
}

Expand All @@ -144,9 +151,13 @@ private void readAuthenticator(Method method, Receiver<RequestType> 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<RoleType>) access.invoke(handler, index, request);
this.authenticator = (request) -> {
try {
return (Future<RoleType>) method.invoke(handler, request);
} catch (IllegalAccessException | InvocationTargetException e) {
throw new RuntimeException(e);
}
};
}
}

Expand Down Expand Up @@ -200,12 +211,9 @@ public Protocol<RequestType> setRole(RoleType... role) {
}

private void wrap(String route, Receiver<RequestType> 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;
Expand Down
57 changes: 48 additions & 9 deletions core/test/java/com/codingchili/core/listener/RestRequestTest.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;

Expand Down Expand Up @@ -332,6 +335,21 @@ public HttpConnection connection() {
public HttpServerRequest streamPriorityHandler(Handler<StreamPriority> handler) {
return this;
}

@Override
public Cookie getCookie(String name) {
return null;
}

@Override
public int cookieCount() {
return 0;
}

@Override
public Map<String, Cookie> cookieMap() {
return null;
}
};
}

Expand Down Expand Up @@ -401,7 +419,7 @@ public String normalisedPath() {
}

@Override
public Cookie getCookie(String s) {
public io.vertx.ext.web.Cookie getCookie(String name) {
return null;
}

Expand All @@ -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;
}

Expand All @@ -426,10 +444,16 @@ public int cookieCount() {
}

@Override
public Set<Cookie> cookies() {
public Set<io.vertx.ext.web.Cookie> cookies() {
return null;
}

@Override
public Map<String, Cookie> cookieMap() {
return null;
}


@Override
public String getBodyAsString() {
return null;
Expand Down Expand Up @@ -465,6 +489,11 @@ public Session session() {
return null;
}

@Override
public boolean isSessionAccessed() {
return false;
}

@Override
public User user() {
return null;
Expand Down Expand Up @@ -510,6 +539,16 @@ public boolean removeBodyEndHandler(int i) {
return false;
}

@Override
public int addEndHandler(Handler<AsyncResult<Void>> handler) {
return 0;
}

@Override
public boolean removeEndHandler(int handlerID) {
return false;
}

@Override
public boolean failed() {
return false;
Expand Down
2 changes: 1 addition & 1 deletion core/test/resources/AuthenticationGenerator/service1.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{}
{ }
2 changes: 1 addition & 1 deletion core/test/resources/AuthenticationGenerator/service2.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{}
{ }
7 changes: 5 additions & 2 deletions docs/protocol.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 3ef15fb

Please sign in to comment.