From 7daff2b8a9bc7dccfd5a2d887a5ce32c1d8580c7 Mon Sep 17 00:00:00 2001
From: DanLi39 <147678474+DanLi39@users.noreply.github.com>
Date: Thu, 11 Jan 2024 17:06:17 +0800
Subject: [PATCH] feat: support flux type in dynamic (#372)
---
.../common/arex-common/pom.xml | 23 +++
.../io/arex/inst/common/util/FluxUtil.java | 96 ++++++++++
.../arex/inst/common/util/FluxUtilTest.java | 55 ++++++
.../dynamic/arex-dynamic-common/pom.xml | 17 +-
.../dynamic/common/DynamicClassExtractor.java | 15 ++
.../dynamic/common/listener/FluxConsumer.java | 57 ++++++
.../dynamic/common/listener/MonoConsumer.java | 14 +-
.../common/DynamicClassExtractorTest.java | 71 +++++++-
.../common/listener/FluxConsumerTest.java | 165 ++++++++++++++++++
arex-instrumentation/pom.xml | 2 +-
10 files changed, 495 insertions(+), 20 deletions(-)
create mode 100644 arex-instrumentation/common/arex-common/pom.xml
create mode 100644 arex-instrumentation/common/arex-common/src/main/java/io/arex/inst/common/util/FluxUtil.java
create mode 100644 arex-instrumentation/common/arex-common/src/test/java/io/arex/inst/common/util/FluxUtilTest.java
create mode 100644 arex-instrumentation/dynamic/arex-dynamic-common/src/main/java/io/arex/inst/dynamic/common/listener/FluxConsumer.java
create mode 100644 arex-instrumentation/dynamic/arex-dynamic-common/src/test/java/io/arex/inst/dynamic/common/listener/FluxConsumerTest.java
diff --git a/arex-instrumentation/common/arex-common/pom.xml b/arex-instrumentation/common/arex-common/pom.xml
new file mode 100644
index 000000000..fc0dbdc2f
--- /dev/null
+++ b/arex-instrumentation/common/arex-common/pom.xml
@@ -0,0 +1,23 @@
+
+
+
+ arex-instrumentation-parent
+ io.arex
+ ${revision}
+ ../../pom.xml
+
+ 4.0.0
+
+ arex-common
+
+
+
+ io.projectreactor
+ reactor-core
+ ${reactor.version}
+ provided
+
+
+
diff --git a/arex-instrumentation/common/arex-common/src/main/java/io/arex/inst/common/util/FluxUtil.java b/arex-instrumentation/common/arex-common/src/main/java/io/arex/inst/common/util/FluxUtil.java
new file mode 100644
index 000000000..9d3ed3aa3
--- /dev/null
+++ b/arex-instrumentation/common/arex-common/src/main/java/io/arex/inst/common/util/FluxUtil.java
@@ -0,0 +1,96 @@
+package io.arex.inst.common.util;
+
+import io.arex.inst.runtime.serializer.Serializer;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.List;
+import reactor.core.publisher.Flux;
+import io.arex.agent.bootstrap.util.CollectionUtil;
+
+public class FluxUtil {
+
+ static final String FLUX_FROM_ITERATOR = "reactor.core.publisher.FluxIterable-";
+ static final String FLUX_FROM_ARRAY = "reactor.core.publisher.FluxArray-";
+ static final String FLUX_FROM_STREAM = "reactor.core.publisher.FluxStream-";
+
+ private FluxUtil() {
+ }
+
+ public static Flux> restore(Object fluxObj) {
+ if(fluxObj == null){
+ return Flux.empty();
+ }
+ FluxResult fluxResult = (FluxResult) fluxObj;
+ List fluxElementResults = fluxResult.getFluxElementResults();
+ if (CollectionUtil.isEmpty(fluxElementResults)) {
+ return Flux.empty();
+ }
+ List