Skip to content

Commit

Permalink
Merge pull request #5 from mohrezaei/transport
Browse files Browse the repository at this point in the history
5.0.0: new transport layer
  • Loading branch information
mohrezaei authored Jul 7, 2019
2 parents 62882e3 + 864e7c9 commit 0d47168
Show file tree
Hide file tree
Showing 56 changed files with 5,580 additions and 1,500 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
# Change Log
## 5.0.0 - 2019-07-05
- Added `@Timeout` annotation to specify timeout on a per class or method level
- Tighter timeout monitoring
- New socket based transport in addition to HTTP
- The new transport has lower overhead (latency)
- Only one dependency: slf4j
- `@Compression` annotation to turn off compression. Not supported in HTTP
- Minimum JDK: 1.8

## 4.0.0 - 2017-05-04
Initial open source release.

377 changes: 242 additions & 135 deletions README.md

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions build/antbuild.bat
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ call %ANTBUILD_HOME%setenv.bat
set ANT_HOME=%ANTBUILD_HOME$

@REM Set the classpath
set ANT_CLASSPATH=%JDK_HOME%\jre\lib\rt.jar
set ANT_CLASSPATH=
set ANT_CLASSPATH=%ANT_CLASSPATH%;%ANTBUILD_HOME%lib\*
set ANT_CLASSPATH=%ANT_CLASSPATH%;%JDK_HOME%\lib\tools.jar

Expand All @@ -36,7 +36,7 @@ set JVM_ARGS=-ms16m -mx1024m -server -XX:MaxPermSize=256m -XX:+UseParallelGC -XX
set PATH=%ANTBUILD_HOME%\build\bin;%PATH%

echo on
%JDK_HOME%\jre\bin\java %JVM_ARGS% -classpath %ANT_CLASSPATH% %ANT_ARGS% org.apache.tools.ant.launch.Launcher -listener org.apache.tools.ant.listener.Log4jListener -f %1 %2 %3 %4 %5 %6 %7 %8
%JDK_HOME%\bin\java %JVM_ARGS% -classpath %ANT_CLASSPATH% %ANT_ARGS% org.apache.tools.ant.launch.Launcher -listener org.apache.tools.ant.listener.Log4jListener -f %1 %2 %3 %4 %5 %6 %7 %8
@echo off

endlocal
20 changes: 10 additions & 10 deletions build/build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,12 @@
<target name="all" depends="compile-jrpip"/>

<target name="sanity-check-build">
<available property="jdk.sanity.check" classname="java.sql.Connection" ignoresystemclasses="true">
<classpath>
<fileset dir="${jdk.home}" includes="**/*.jar"/>
</classpath>
</available>
<fail message="Could not find the JDK! Check ${jdk.home}." unless="jdk.sanity.check"/>
<!--<available property="jdk.sanity.check" classname="java.sql.Connection" ignoresystemclasses="true">-->
<!--<classpath>-->
<!--<fileset dir="${jdk.home}" includes="**/*.jar"/>-->
<!--</classpath>-->
<!--</available>-->
<!--<fail message="Could not find the JDK! Check ${jdk.home}." unless="jdk.sanity.check"/>-->
<available property="jrpip.sanity.check" file="${root}/src/main/java/com/gs/jrpip/MethodResolver.java"/>
<fail message="Could not find jrpip sources. Project root is ${root}, but there is nothing in ${root}/src/main/java/com/gs/jrpip/MethodResolver.java." unless="jrpip.sanity.check"/>
</target>
Expand Down Expand Up @@ -123,8 +123,8 @@
<target name="compile-jrpip" depends="init-jrpip, libboot-jrpip, main-dependset">
<javac destdir="${root}/target/classes"
debug="true"
source="1.6"
target="1.6"
source="1.8"
target="1.8"
nowarn="true"
includeAntRuntime="false">
<src path="${root}/src/main/java"/>
Expand All @@ -148,8 +148,8 @@
<target name="compile-jrpip-test" depends="compile-jrpip, test-dependset">
<javac destdir="${root}/target/test-classes"
debug="true"
source="1.6"
target="1.6"
source="1.8"
target="1.8"
nowarn="true"
includeAntRuntime="true">
<src path="${root}/src/test/java"/>
Expand Down
2 changes: 1 addition & 1 deletion build/jrpip-config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@
under the License.
-->
<project name="jrpip-config">
<property name="jrpip.version" value="4.0.0"/>
<property name="jrpip.version" value="5.0.0"/>
<property name="snapshot" value=""/>
</project>
2 changes: 1 addition & 1 deletion build/setenv.bat
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
set JDK_HOME=h:\tools\1.6.0_31_x64
set JDK_HOME=c:\devel\jdk1.8.0_144

@REM no need to modify stuff below:

Expand Down
13 changes: 13 additions & 0 deletions src/main/java/com/gs/jrpip/Compression.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.gs.jrpip;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.METHOD, ElementType.TYPE})
public @interface Compression
{
boolean compress() default true;
}
65 changes: 57 additions & 8 deletions src/main/java/com/gs/jrpip/MethodResolver.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,10 @@

public class MethodResolver
{
private final Map<Method, String> methodToNameMap = new HashMap<Method, String>();
private final Map<String, Method> nameToMethodMap = new HashMap<String, Method>();
private final Map<Method, Integer> methodToTimeoutMap = new HashMap<Method, Integer>();
private final Map<Method, String> methodToNameMap = new HashMap<>();
private final Map<String, Method> nameToMethodMap = new HashMap<>();
private final Map<Method, Integer> methodToTimeoutMap = new HashMap<>();
private final Map<Method, Boolean> methodToCompressionMap = new HashMap<>();

private final Class serviceClass;

Expand All @@ -35,18 +36,61 @@ public MethodResolver(Class serviceClass)
this.serviceClass = serviceClass;
Method[] methodList = serviceClass.getMethods();

Integer classTimeout = null;
if (this.serviceClass.isAnnotationPresent(Timeout.class))
{
classTimeout = (int) ((Timeout)this.serviceClass.getAnnotation(Timeout.class)).timeoutMillis();
}
Boolean classCompression = null;
if (this.serviceClass.isAnnotationPresent(Compression.class))
{
classCompression = ((Compression)this.serviceClass.getAnnotation(Compression.class)).compress();
}
for (Method method : methodList)
{
String mangledName = this.mangleName(method);
this.methodToNameMap.put(method, mangledName);
this.nameToMethodMap.put(mangledName, method);

Integer timeout = this.buildTimeoutFromProperty(method);
if (timeout != null)
configureTimeout(classTimeout, method);
configureCompression(classCompression, method);
}
}

private void configureTimeout(Integer classTimeout, Method method)
{
Integer timeout = this.buildTimeoutFromProperty(method);
if (timeout != null)
{
this.methodToTimeoutMap.put(method, timeout);
}
else
{
if (method.isAnnotationPresent(Timeout.class))
{
this.methodToTimeoutMap.put(method, timeout);
Timeout annotation = method.getAnnotation(Timeout.class);
this.methodToTimeoutMap.put(method, (int) annotation.timeoutMillis());
}
else if (classTimeout != null)
{
this.methodToTimeoutMap.put(method, classTimeout);
}
}
}

private void configureCompression(Boolean classCompression, Method method)
{
boolean compress = true;
if (method.isAnnotationPresent(Compression.class))
{
Compression annotation = method.getAnnotation(Compression.class);
compress = annotation.compress();
}
else if (classCompression != null)
{
compress = classCompression;
}
this.methodToCompressionMap.put(method, compress);
}

public String getMangledMethodName(Method method)
Expand All @@ -64,17 +108,22 @@ public Integer getMethodTimeout(Method method)
return this.methodToTimeoutMap.get(method);
}

public boolean getMethodCompression(Method method)
{
return this.methodToCompressionMap.get(method);
}

protected String mangleName(Method method)
{
StringBuilder sb = new StringBuilder();

sb.append(method.getName());

Class[] params = method.getParameterTypes();
for (int i = 0; i < params.length; i++)
for (Class pc: params)
{
sb.append('_');
this.mangleClass(sb, params[i]);
this.mangleClass(sb, pc);
}

return sb.toString();
Expand Down
13 changes: 13 additions & 0 deletions src/main/java/com/gs/jrpip/Timeout.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.gs.jrpip;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.METHOD, ElementType.TYPE})
public @interface Timeout
{
long timeoutMillis() default 0;
}
Loading

0 comments on commit 0d47168

Please sign in to comment.