Skip to content

Commit 087986c

Browse files
committed
feat: finish vrflux and add vrreflect
1 parent 184982d commit 087986c

File tree

5 files changed

+109
-7
lines changed

5 files changed

+109
-7
lines changed

pom.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
<module>vrml-metric</module>
6161
<module>vrml-netty</module>
6262
<module>vrml-reactor</module>
63+
<module>vrml-reflect</module>
6364
<module>vrml-request</module>
6465
<module>vrml-resource</module>
6566
<module>vrml-shutdown</module>
@@ -167,6 +168,11 @@
167168
<artifactId>vrml-reactor</artifactId>
168169
<version>${project.version}</version>
169170
</dependency>
171+
<dependency>
172+
<groupId>group.rxcloud</groupId>
173+
<artifactId>vrml-reflect</artifactId>
174+
<version>${project.version}</version>
175+
</dependency>
170176
<dependency>
171177
<groupId>group.rxcloud</groupId>
172178
<artifactId>vrml-request</artifactId>

vrml-all/pom.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,10 @@
7171
<groupId>group.rxcloud</groupId>
7272
<artifactId>vrml-reactor</artifactId>
7373
</dependency>
74+
<dependency>
75+
<groupId>group.rxcloud</groupId>
76+
<artifactId>vrml-reflect</artifactId>
77+
</dependency>
7478
<dependency>
7579
<groupId>group.rxcloud</groupId>
7680
<artifactId>vrml-request</artifactId>

vrml-reactor/src/main/java/group/rxcloud/vrml/reactor/VrFlux.java

Lines changed: 55 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,16 +42,64 @@ public static <T> void subscribeAfterInit(Flux<T> flux, Duration firstLoad, Cons
4242
}
4343

4444
/**
45-
* 非必须的
45+
* Flux: Subscribe after init not essential.
46+
*
47+
* @param <T> the type parameter
48+
* @param flux the flux
49+
* @param consumer the consumer
50+
* @return {@code true} if subscribe success.
4651
*/
47-
public static <T> void subscribeAfterInitNonEssential(Flux<T> flux, Consumer<? super T> consumer) {
48-
T t = null;
52+
public static <T> boolean subscribeAfterInitNonEssential(Flux<T> flux, Consumer<? super T> consumer) {
4953
try {
50-
t = flux.blockFirst();
54+
T t = flux.blockFirst();
55+
if (t != null) {
56+
consumer.accept(t);
57+
}
5158
} catch (Exception e) {
52-
throw new RuntimeException(e);
59+
if (log.isWarnEnabled()) {
60+
log.warn("[Vrml.flux] [subscribeAfterInitNonEssential] blockFirst error", e);
61+
}
62+
}
63+
try {
64+
flux.subscribe(consumer);
65+
return true;
66+
} catch (Exception e) {
67+
if (log.isWarnEnabled()) {
68+
log.warn("[Vrml.flux] [subscribeAfterInitNonEssential] subscribe error", e);
69+
}
70+
return false;
71+
}
72+
}
73+
74+
/**
75+
* Flux: Subscribe after init not essential.
76+
*
77+
* @param <T> the type parameter
78+
* @param flux the flux
79+
* @param firstLoad the first load timeout
80+
* @param consumer the consumer
81+
* @return {@code true} if subscribe success.
82+
*/
83+
public static <T> boolean subscribeAfterInitNonEssential(Flux<T> flux, Duration firstLoad, Consumer<? super T> consumer) {
84+
try {
85+
T t = flux.blockFirst(firstLoad);
86+
if (t != null) {
87+
consumer.accept(t);
88+
}
89+
} catch (Exception e) {
90+
if (log.isWarnEnabled()) {
91+
log.warn("[Vrml.flux] [subscribeAfterInitNonEssential] blockFirst error, firstLoad[{}]",
92+
firstLoad, e);
93+
}
94+
}
95+
try {
96+
flux.subscribe(consumer);
97+
return true;
98+
} catch (Exception e) {
99+
if (log.isWarnEnabled()) {
100+
log.warn("[Vrml.flux] [subscribeAfterInitNonEssential] subscribe error", e);
101+
}
102+
return false;
53103
}
54-
consumer.accept(t);
55-
flux.subscribe(consumer);
56104
}
57105
}

vrml-reflect/pom.xml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
7+
<parent>
8+
<artifactId>vrml</artifactId>
9+
<groupId>group.rxcloud</groupId>
10+
<version>1.1.2</version>
11+
</parent>
12+
13+
<artifactId>vrml-reflect</artifactId>
14+
<packaging>jar</packaging>
15+
16+
<properties>
17+
</properties>
18+
19+
</project>
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package group.rxcloud.vrml.reflect;
2+
3+
import java.lang.reflect.Constructor;
4+
import java.lang.reflect.InvocationTargetException;
5+
6+
/**
7+
* The Vrml reflect utils.
8+
*/
9+
public class VrReflectUtils {
10+
11+
/**
12+
* Create obj by class object.
13+
*
14+
* @param clazz the clazz
15+
* @return the object
16+
* @throws NoSuchMethodException the no such method exception
17+
* @throws InvocationTargetException the invocation target exception
18+
* @throws InstantiationException the instantiation exception
19+
* @throws IllegalAccessException the illegal access exception
20+
*/
21+
public static <T> T createObjByClass(Class<T> clazz) throws NoSuchMethodException, InvocationTargetException, InstantiationException, IllegalAccessException {
22+
Constructor<T> constructor = clazz.getConstructor();
23+
return constructor.newInstance();
24+
}
25+
}

0 commit comments

Comments
 (0)