17
17
18
18
package org .apache .seatunnel .transform .python ;
19
19
20
+ import lombok .extern .slf4j .Slf4j ;
20
21
import org .apache .seatunnel .api .table .type .SeaTunnelRowAccessor ;
21
22
import py4j .GatewayServer ;
22
23
24
+ import java .util .List ;
23
25
import java .util .Map ;
24
26
import java .util .concurrent .ConcurrentHashMap ;
25
27
28
+ @ Slf4j
26
29
public class PythonOperationProxy implements RowOperation {
27
30
28
31
private GatewayServer javaServer ;
29
- private final Map <Long ,SeaTunnelRowAccessor > threadDataMap = new ConcurrentHashMap <>();
30
- private final Map <Long ,Long > threadDataOffsetMap = new ConcurrentHashMap <>();
32
+ private final Map <Long , SeaTunnelRowAccessor > inputDataMap = new ConcurrentHashMap <>();
33
+
34
+ private final Map <Long , EndTagList > outputDataMap = new ConcurrentHashMap <>();
31
35
private PythonOperationProxy (){
32
36
if (INSTANCE != null ) {
33
37
throw new RuntimeException ("Please use newInstance() method for getting the single instance of this class." );
@@ -51,14 +55,33 @@ public void shutdown(){
51
55
}
52
56
53
57
public void putThreadData (long threadId , SeaTunnelRowAccessor inputRow ) {
54
- this .threadDataMap .put (threadId ,inputRow );
55
- this .threadDataOffsetMap .compute (threadId ,(thread ,offset ) ->{
56
- if (offset == null ){
57
- offset = 0L ;
58
- }else {
59
- offset = offset + 1 ;
60
- }
61
- return offset ;
62
- });
58
+ this .inputDataMap .put (threadId ,inputRow );
59
+ }
60
+
61
+ public Object [] getOutputData (long threadId ) {
62
+ EndTagList endTagList = outputDataMap .get (threadId );
63
+ while (endTagList == null || !endTagList .isEnd ()){
64
+ log .info ("wait python process data" );
65
+ }
66
+ return outputDataMap .get (threadId ).getList ().toArray (new Object [0 ]);
67
+ }
68
+
69
+ public void addData (Long threadId ,Object obj ){
70
+ EndTagList array = this .outputDataMap .getOrDefault (threadId , new EndTagList ());
71
+ array .add (obj );
72
+ this .outputDataMap .put (threadId ,array );
73
+ }
74
+
75
+ public void addDataList (Long threadId ,List <Object > dataList ){
76
+ EndTagList array = new EndTagList ();
77
+ this .outputDataMap .put (threadId ,array );
78
+ }
79
+
80
+
81
+ public void end (Long threadId ){
82
+ EndTagList endTagList = this .outputDataMap .get (threadId );
83
+ if (endTagList != null ){
84
+ endTagList .end ();
85
+ }
63
86
}
64
87
}
0 commit comments