This is an automated email from the ASF dual-hosted git repository.

roryqi pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-uniffle.git


The following commit(s) were added to refs/heads/master by this push:
     new 8b8801bb [#434] refactor: New utility method to cover dynamic class 
loading in RSSUtils (#1104)
8b8801bb is described below

commit 8b8801bbf504736d73276ed3b1f1fdc7bc62d532
Author: pegasas <[email protected]>
AuthorDate: Mon Aug 7 23:40:34 2023 +0800

    [#434] refactor: New utility method to cover dynamic class loading in 
RSSUtils (#1104)
    
    ### What changes were proposed in this pull request?
    New utility method to cover dynamic class loading in RSSUtils
    
    ### Why are the changes needed?
    
    Fix: #434
    
    ### Does this PR introduce _any_ user-facing change?
    
    No.
    
    ### How was this patch tested?
    CI passed.
---
 .../apache/uniffle/common/metrics/MetricReporterFactory.java   | 10 ++++------
 .../src/main/java/org/apache/uniffle/common/util/RssUtils.java |  7 +++++++
 2 files changed, 11 insertions(+), 6 deletions(-)

diff --git 
a/common/src/main/java/org/apache/uniffle/common/metrics/MetricReporterFactory.java
 
b/common/src/main/java/org/apache/uniffle/common/metrics/MetricReporterFactory.java
index d25a9527..20df4fe6 100644
--- 
a/common/src/main/java/org/apache/uniffle/common/metrics/MetricReporterFactory.java
+++ 
b/common/src/main/java/org/apache/uniffle/common/metrics/MetricReporterFactory.java
@@ -17,12 +17,11 @@
 
 package org.apache.uniffle.common.metrics;
 
-import java.lang.reflect.Constructor;
-
 import org.apache.commons.lang3.StringUtils;
 
 import org.apache.uniffle.common.config.RssBaseConf;
 import org.apache.uniffle.common.config.RssConf;
+import org.apache.uniffle.common.util.RssUtils;
 
 public class MetricReporterFactory {
 
@@ -31,9 +30,8 @@ public class MetricReporterFactory {
     if (StringUtils.isEmpty(name)) {
       return null;
     }
-    Class<?> klass = Class.forName(name);
-    Constructor<?> constructor;
-    constructor = klass.getConstructor(RssConf.class, String.class);
-    return (AbstractMetricReporter) constructor.newInstance(conf, instanceId);
+
+    return (AbstractMetricReporter)
+        RssUtils.getConstructor(name, RssConf.class, 
String.class).newInstance(conf, instanceId);
   }
 }
diff --git a/common/src/main/java/org/apache/uniffle/common/util/RssUtils.java 
b/common/src/main/java/org/apache/uniffle/common/util/RssUtils.java
index 273acd14..8a117fd1 100644
--- a/common/src/main/java/org/apache/uniffle/common/util/RssUtils.java
+++ b/common/src/main/java/org/apache/uniffle/common/util/RssUtils.java
@@ -401,4 +401,11 @@ public class RssUtils {
     }
     PlatformDependent.freeDirectBuffer(byteBuffer);
   }
+
+  public static Constructor<?> getConstructor(String className, Class<?>... 
parameterTypes)
+      throws ClassNotFoundException, NoSuchMethodException {
+    Class<?> klass = Class.forName(className);
+    Constructor<?> constructor = klass.getConstructor(parameterTypes);
+    return constructor;
+  }
 }

Reply via email to