Skip to content

Commit 077e0bd

Browse files
authored
Support custom implementation of App and Service interfaces (linkedin#74)
1 parent baede83 commit 077e0bd

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

src/main/java/com/linkedin/kmf/KafkaMonitor.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
import com.fasterxml.jackson.databind.ObjectMapper;
1313
import com.linkedin.kmf.services.Service;
1414
import com.linkedin.kmf.apps.App;
15-
import com.linkedin.kmf.tests.Test;
1615
import java.util.concurrent.ConcurrentHashMap;
1716
import java.util.concurrent.ConcurrentMap;
1817
import java.util.concurrent.atomic.AtomicBoolean;
@@ -55,13 +54,15 @@ public KafkaMonitor(Map<String, Map> testProps) throws Exception {
5554
throw new IllegalArgumentException(name + " is not configured with " + CLASS_NAME_CONFIG);
5655
String className = (String) props.get(CLASS_NAME_CONFIG);
5756

58-
if (className.startsWith(App.class.getPackage().getName()) ||
59-
className.startsWith(Test.class.getPackage().getName())) {
57+
Class<?> cls = Class.forName(className);
58+
if (App.class.isAssignableFrom(cls)) {
6059
App test = (App) Class.forName(className).getConstructor(Map.class, String.class).newInstance(props, name);
6160
_apps.put(name, test);
62-
} else {
61+
} else if (Service.class.isAssignableFrom(cls)) {
6362
Service service = (Service) Class.forName(className).getConstructor(Map.class, String.class).newInstance(props, name);
6463
_services.put(name, service);
64+
} else {
65+
throw new IllegalArgumentException(className + " should implement either " + App.class.getSimpleName() + " or " + Service.class.getSimpleName());
6566
}
6667
}
6768
_executor = Executors.newSingleThreadScheduledExecutor();

0 commit comments

Comments
 (0)