Skip to content

Commit

Permalink
feat: finish vrflux and add vrreflect
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinten10 committed Nov 30, 2022
1 parent 184982d commit 087986c
Show file tree
Hide file tree
Showing 5 changed files with 109 additions and 7 deletions.
6 changes: 6 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
<module>vrml-metric</module>
<module>vrml-netty</module>
<module>vrml-reactor</module>
<module>vrml-reflect</module>
<module>vrml-request</module>
<module>vrml-resource</module>
<module>vrml-shutdown</module>
Expand Down Expand Up @@ -167,6 +168,11 @@
<artifactId>vrml-reactor</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>group.rxcloud</groupId>
<artifactId>vrml-reflect</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>group.rxcloud</groupId>
<artifactId>vrml-request</artifactId>
Expand Down
4 changes: 4 additions & 0 deletions vrml-all/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@
<groupId>group.rxcloud</groupId>
<artifactId>vrml-reactor</artifactId>
</dependency>
<dependency>
<groupId>group.rxcloud</groupId>
<artifactId>vrml-reflect</artifactId>
</dependency>
<dependency>
<groupId>group.rxcloud</groupId>
<artifactId>vrml-request</artifactId>
Expand Down
62 changes: 55 additions & 7 deletions vrml-reactor/src/main/java/group/rxcloud/vrml/reactor/VrFlux.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,64 @@ public static <T> void subscribeAfterInit(Flux<T> flux, Duration firstLoad, Cons
}

/**
* 非必须的
* Flux: Subscribe after init not essential.
*
* @param <T> the type parameter
* @param flux the flux
* @param consumer the consumer
* @return {@code true} if subscribe success.
*/
public static <T> void subscribeAfterInitNonEssential(Flux<T> flux, Consumer<? super T> consumer) {
T t = null;
public static <T> boolean subscribeAfterInitNonEssential(Flux<T> flux, Consumer<? super T> consumer) {
try {
t = flux.blockFirst();
T t = flux.blockFirst();
if (t != null) {
consumer.accept(t);
}
} catch (Exception e) {
throw new RuntimeException(e);
if (log.isWarnEnabled()) {
log.warn("[Vrml.flux] [subscribeAfterInitNonEssential] blockFirst error", e);
}
}
try {
flux.subscribe(consumer);
return true;
} catch (Exception e) {
if (log.isWarnEnabled()) {
log.warn("[Vrml.flux] [subscribeAfterInitNonEssential] subscribe error", e);
}
return false;
}
}

/**
* Flux: Subscribe after init not essential.
*
* @param <T> the type parameter
* @param flux the flux
* @param firstLoad the first load timeout
* @param consumer the consumer
* @return {@code true} if subscribe success.
*/
public static <T> boolean subscribeAfterInitNonEssential(Flux<T> flux, Duration firstLoad, Consumer<? super T> consumer) {
try {
T t = flux.blockFirst(firstLoad);
if (t != null) {
consumer.accept(t);
}
} catch (Exception e) {
if (log.isWarnEnabled()) {
log.warn("[Vrml.flux] [subscribeAfterInitNonEssential] blockFirst error, firstLoad[{}]",
firstLoad, e);
}
}
try {
flux.subscribe(consumer);
return true;
} catch (Exception e) {
if (log.isWarnEnabled()) {
log.warn("[Vrml.flux] [subscribeAfterInitNonEssential] subscribe error", e);
}
return false;
}
consumer.accept(t);
flux.subscribe(consumer);
}
}
19 changes: 19 additions & 0 deletions vrml-reflect/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<artifactId>vrml</artifactId>
<groupId>group.rxcloud</groupId>
<version>1.1.2</version>
</parent>

<artifactId>vrml-reflect</artifactId>
<packaging>jar</packaging>

<properties>
</properties>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package group.rxcloud.vrml.reflect;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;

/**
* The Vrml reflect utils.
*/
public class VrReflectUtils {

/**
* Create obj by class object.
*
* @param clazz the clazz
* @return the object
* @throws NoSuchMethodException the no such method exception
* @throws InvocationTargetException the invocation target exception
* @throws InstantiationException the instantiation exception
* @throws IllegalAccessException the illegal access exception
*/
public static <T> T createObjByClass(Class<T> clazz) throws NoSuchMethodException, InvocationTargetException, InstantiationException, IllegalAccessException {
Constructor<T> constructor = clazz.getConstructor();
return constructor.newInstance();
}
}

0 comments on commit 087986c

Please sign in to comment.