Skip to content

Commit

Permalink
build: pre release
Browse files Browse the repository at this point in the history
  • Loading branch information
AlphaLxy committed Mar 16, 2022
1 parent bee2623 commit 53bc180
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 8 deletions.
53 changes: 47 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
# FastProxy
Alternatives to `java.lang.Proxy`.
FastProxy is a library to create dynamic proxy class using `org.ow2.asm:asm`.

### Getting started
```xml
<dependency>
<groupId>com.alphalxy</groupId>
<artifactId>fast-proxy</artifactId>
<version>0.0.1</version>
<groupId>com.alphalxy</groupId>
<artifactId>fast-proxy</artifactId>
<version>0.0.1</version>
</dependency>
```

Expand Down Expand Up @@ -45,9 +46,49 @@ FastProxy.isProxyInstance(f);
FastProxy.isProxyClass(Foo.class);
```

### Benchmark

### How

Use lambda express as `MethodInvoker` for each method.

For any interface
```java
public interface Foo {
String bar(String string);
void baz(String string);
}
```
generate a `$Proxy` class using `org.ow2.asm:asm`.

```java
import com.alphalxy.MethodInterceptor;
import java.lang.reflect.Method;

public final class $Proxy implements Foo {
private final MethodInterceptor interceptor;
private static final Method M_0 = Foo.class.getMethod("bar", String.class);
private static final Method M_1 = Foo.class.getMethod("baz", String.class);

public $Proxy(MethodInterceptor interceptor) {
this.interceptor = interceptor;
}

public String bar(String string) {
return interceptor.intercept(this, M_0, (target, args) -> {
return ((Foo)target).bar((String)args[0]);
}, new Object[] {string});
}

public void baz(String string) {
interceptor.intercept(this, M_1, (target, args) -> {
((Foo)target).baz((String)args[0]);
return null;
}, new Object[] {string});
}
}
```

## How

Generate lambda express as `MethodInvoker` for each method.


2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<version>0.0.1</version>

<name>fast-proxy</name>
<description>Alternatives to java.lang.Proxy</description>
<description>FastProxy is a library to create dynamic proxy class.</description>

<licenses>
<license>
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/alphalxy/FastProxy.java
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public static boolean isProxyClass(Class<?> cl) {
*
* @param object the object to test.
* @return {@code true} if the object is a proxy instance and {@code false} otherwise.
* @throws NullPointerException if {@code cl} is {@code null}.
* @throws NullPointerException if {@code object} is {@code null}.
*/
public static boolean isProxyInstance(Object object) {
return PROXY_CONSTRUCTORS.containsKey(Objects.requireNonNull(object).getClass());
Expand Down

0 comments on commit 53bc180

Please sign in to comment.