kafka-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ewe...@apache.org
Subject kafka git commit: MINOR: speed up connect startup when full connector class name is provided
Date Fri, 08 Jan 2016 23:04:48 GMT
Repository: kafka
Updated Branches:
  refs/heads/trunk ccdf55274 -> 58def1cba


MINOR: speed up connect startup when full connector class name is provided

Author: Jason Gustafson <jason@confluent.io>

Reviewers: Liquan Pei <liquanpei@gmail.com>, Ewen Cheslack-Postava <ewen@confluent.io>

Closes #746 from hachikuji/worker-startup-improvement


Project: http://git-wip-us.apache.org/repos/asf/kafka/repo
Commit: http://git-wip-us.apache.org/repos/asf/kafka/commit/58def1cb
Tree: http://git-wip-us.apache.org/repos/asf/kafka/tree/58def1cb
Diff: http://git-wip-us.apache.org/repos/asf/kafka/diff/58def1cb

Branch: refs/heads/trunk
Commit: 58def1cba022987b83e9bc72588aaee0c1965f77
Parents: ccdf552
Author: Jason Gustafson <jason@confluent.io>
Authored: Fri Jan 8 15:04:27 2016 -0800
Committer: Ewen Cheslack-Postava <me@ewencp.org>
Committed: Fri Jan 8 15:04:27 2016 -0800

----------------------------------------------------------------------
 .../org/apache/kafka/connect/runtime/Worker.java   | 17 +++++++++++------
 1 file changed, 11 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/kafka/blob/58def1cb/connect/runtime/src/main/java/org/apache/kafka/connect/runtime/Worker.java
----------------------------------------------------------------------
diff --git a/connect/runtime/src/main/java/org/apache/kafka/connect/runtime/Worker.java b/connect/runtime/src/main/java/org/apache/kafka/connect/runtime/Worker.java
index 4766cf7..88b4c10 100644
--- a/connect/runtime/src/main/java/org/apache/kafka/connect/runtime/Worker.java
+++ b/connect/runtime/src/main/java/org/apache/kafka/connect/runtime/Worker.java
@@ -202,9 +202,18 @@ public class Worker {
         return SinkConnector.class.isAssignableFrom(connectors.get(connName).getClass());
     }
 
-
-    // Iterate over our entire classpath to find all the connectors and hopefully one of
them matches the alias from the connector configration
     private Class<? extends Connector> getConnectorClass(String connectorAlias) {
+        // Avoid the classpath scan if the full class name was provided
+        try {
+            Class<?> clazz = Class.forName(connectorAlias);
+            if (!Connector.class.isAssignableFrom(clazz))
+                throw new ConnectException("Class " + connectorAlias + " does not implement
Connector");
+            return (Class<? extends Connector>) clazz;
+        } catch (ClassNotFoundException e) {
+            // Fall through to scan for the alias
+        }
+
+        // Iterate over our entire classpath to find all the connectors and hopefully one
of them matches the alias from the connector configration
         Reflections reflections = new Reflections(new ConfigurationBuilder()
                 .setUrls(ClasspathHelper.forJavaClassPath()));
 
@@ -213,10 +222,6 @@ public class Worker {
         List<Class<? extends Connector>> results = new ArrayList<>();
 
         for (Class<? extends Connector> connector: connectors) {
-            // Configuration included the fully qualified class name
-            if (connector.getName().equals(connectorAlias))
-                results.add(connector);
-
             // Configuration included the class name but not package
             if (connector.getSimpleName().equals(connectorAlias))
                 results.add(connector);


Mime
View raw message