You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by GitBox <gi...@apache.org> on 2022/09/02 02:33:22 UTC

[GitHub] [pulsar] AnonHxy commented on a diff in pull request #17347: [refactor][broker]refactor reflection method in delayed,intercept,protocol,service module

AnonHxy commented on code in PR #17347:
URL: https://github.com/apache/pulsar/pull/17347#discussion_r961237220


##########
pulsar-broker/src/main/java/org/apache/pulsar/broker/protocol/ProtocolHandlerUtils.java:
##########
@@ -133,13 +134,8 @@ static ProtocolHandlerWithClassLoader load(ProtocolHandlerMetadata metadata,
         }
 
         try {
-            Class handlerClass = ncl.loadClass(phDef.getHandlerClass());
-            Object handler = handlerClass.getDeclaredConstructor().newInstance();
-            if (!(handler instanceof ProtocolHandler)) {
-                throw new IOException("Class " + phDef.getHandlerClass()
-                    + " does not implement protocol handler interface");
-            }
-            ProtocolHandler ph = (ProtocolHandler) handler;
+            ProtocolHandler ph = Reflections.createInstance(phDef.getHandlerClass(), ProtocolHandler.class,
+                    Thread.currentThread().getContextClassLoader());

Review Comment:
   Should use `NarClassLoader`



##########
pulsar-broker/src/main/java/org/apache/pulsar/broker/intercept/BrokerInterceptorUtils.java:
##########
@@ -133,13 +134,8 @@ BrokerInterceptorWithClassLoader load(BrokerInterceptorMetadata metadata, String
         }
 
         try {
-            Class interceptorClass = ncl.loadClass(def.getInterceptorClass());
-            Object interceptor = interceptorClass.getDeclaredConstructor().newInstance();
-            if (!(interceptor instanceof BrokerInterceptor)) {
-                throw new IOException("Class " + def.getInterceptorClass()
-                        + " does not implement broker interceptor interface");
-            }
-            BrokerInterceptor pi = (BrokerInterceptor) interceptor;
+            BrokerInterceptor pi = Reflections.createInstance(def.getInterceptorClass(), BrokerInterceptor.class,
+                    Thread.currentThread().getContextClassLoader());

Review Comment:
   Should use `NarClassLoader`



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org