File tree 4 files changed +56
-3
lines changed
seatunnel-transforms-v2/src/main/java/org/apache/seatunnel/transform
4 files changed +56
-3
lines changed Original file line number Diff line number Diff line change
1
+ /*
2
+ * Licensed to the Apache Software Foundation (ASF) under one or more
3
+ * contributor license agreements. See the NOTICE file distributed with
4
+ * this work for additional information regarding copyright ownership.
5
+ * The ASF licenses this file to You under the Apache License, Version 2.0
6
+ * (the "License"); you may not use this file except in compliance with
7
+ * the License. You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ package org .apache .seatunnel .transform .jsonpath ;
18
+
19
+
20
+ public class SingletonServer {
21
+ }
Original file line number Diff line number Diff line change 17
17
18
18
package org .apache .seatunnel .transform .python ;
19
19
20
- public class PythonOperationProxy implements RowOperation {}
20
+ import py4j .GatewayServer ;
21
+
22
+ public class PythonOperationProxy implements RowOperation {
23
+
24
+ private GatewayServer javaServer ;
25
+ private PythonOperationProxy (){
26
+ if (INSTANCE != null ) {
27
+ throw new RuntimeException ("Please use newInstance() method for getting the single instance of this class." );
28
+ }
29
+ }
30
+ private static volatile PythonOperationProxy INSTANCE ;
31
+ public static PythonOperationProxy newInstance (Integer javaServerPort ) {
32
+ if (INSTANCE == null ){
33
+ synchronized (PythonOperationProxy .class ){
34
+ if (INSTANCE == null ){
35
+ PythonOperationProxy operationProxy = new PythonOperationProxy ();
36
+ operationProxy .javaServer = new GatewayServer (operationProxy ,javaServerPort );
37
+ }
38
+ }
39
+ }
40
+ return INSTANCE ;
41
+ }
42
+
43
+ public void shutdown (){
44
+ this .javaServer .shutdown ();
45
+ }
46
+ }
Original file line number Diff line number Diff line change @@ -13,9 +13,16 @@ public class PythonTransform extends MultipleFieldOutputTransform {
13
13
14
14
private final PythonTransformConfig config ;
15
15
16
+ private final PythonOperationProxy pythonOperationProxy ;
17
+
16
18
public PythonTransform (@ NonNull CatalogTable inputCatalogTable , PythonTransformConfig transformConfig ) {
17
19
super (inputCatalogTable , transformConfig .getErrorHandleWay ());
18
20
this .config = transformConfig ;
21
+ pythonOperationProxy = initLocalSingletonJavaServer (config .getJavaServerPort ());
22
+ }
23
+
24
+ private PythonOperationProxy initLocalSingletonJavaServer (Integer javaServerPort ) {
25
+ return PythonOperationProxy .newInstance (javaServerPort );
19
26
}
20
27
21
28
@ Override
Original file line number Diff line number Diff line change @@ -105,8 +105,7 @@ public static PythonTransformConfig of(ReadonlyConfig config) {
105
105
private static String loadCodeFromPath (String filePath ) {
106
106
try {
107
107
// 读取整个文件内容到字符串
108
- String code = new String (Files .readAllBytes (Paths .get (filePath )));
109
- return code ;
108
+ return new String (Files .readAllBytes (Paths .get (filePath )));
110
109
} catch (IOException e ) {
111
110
// 处理可能发生的IO异常
112
111
throw new TransformException (LOAD_SOURCE_CODE_FROM_PATH_ERROR ,
You can’t perform that action at this time.
0 commit comments