org.apache.kafka.connect.source.SourceConnector Java Examples

The following examples show how to use org.apache.kafka.connect.source.SourceConnector. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AbstractKafkaConnectSource.java    From hazelcast-jet-contrib with Apache License 2.0 5 votes vote down vote up
public AbstractKafkaConnectSource(Properties properties) {
    try {
        String connectorClazz = properties.getProperty("connector.class");
        Class<?> connectorClass = Thread.currentThread().getContextClassLoader().loadClass(connectorClazz);
        connector = (SourceConnector) connectorClass.getConstructor().newInstance();
        connector.initialize(new JetConnectorContext());
        connector.start((Map) properties);

        taskConfig = connector.taskConfigs(1).get(0);
        task = (SourceTask) connector.taskClass().getConstructor().newInstance();
    } catch (Exception e) {
        throw rethrow(e);
    }
}
 
Example #2
Source File: PluginLoader.java    From connect-utils with Apache License 2.0 5 votes vote down vote up
Set<Class<? extends SourceConnector>> findSourceConnectors() {
  return this.reflections.getSubTypesOf(SourceConnector.class)
      .stream()
      .filter(c -> c.getName().startsWith(pkg.getName()))
      .filter(c -> Modifier.isPublic(c.getModifiers()))
      .filter(c -> !Modifier.isAbstract(c.getModifiers()))
      .filter((Predicate<Class<? extends SourceConnector>>) aClass -> Arrays.stream(aClass.getConstructors())
          .filter(c -> Modifier.isPublic(c.getModifiers()))
          .anyMatch(c -> c.getParameterCount() == 0))
      .collect(Collectors.toSet());
}
 
Example #3
Source File: PluginLoader.java    From connect-utils with Apache License 2.0 5 votes vote down vote up
public Plugin load() {
  ImmutablePlugin.Builder builder = ImmutablePlugin.builder()
      .from(notes(this.pkg))
      .pluginName(AnnotationHelper.pluginName(this.pkg))
      .pluginOwner(AnnotationHelper.pluginOwner(this.pkg));
  List<Plugin.Transformation> transformations = loadTransformations();
  builder.addAllTransformations(transformations);
  List<Plugin.SinkConnector> sinkConnectors = loadSinkConnectors();
  builder.addAllSinkConnectors(sinkConnectors);
  List<Plugin.SourceConnector> sourceConnectors = loadSourceConnectors();
  builder.addAllSourceConnectors(sourceConnectors);
  List<Plugin.Converter> converters = loadConverters();
  builder.addAllConverters(converters);
  return builder.build();
}
 
Example #4
Source File: PluginLoaderTest.java    From connect-utils with Apache License 2.0 5 votes vote down vote up
@Test
public void findSourceConnectors() {
  final Set<Class<? extends SourceConnector>> expected = ImmutableSet.of(
      TestSourceConnector.class,
      NoDocTestSourceConnector.class
  );
  final Set<Class<? extends SourceConnector>> actual = pluginLoader.findSourceConnectors();

  assertEquals(expected, actual);
}
 
Example #5
Source File: MQSourceConnectorTest.java    From kafka-connect-mq-source with Apache License 2.0 4 votes vote down vote up
@Test
public void testConnectorType() {
    Connector connector = new MQSourceConnector();
    assertTrue(SourceConnector.class.isAssignableFrom(connector.getClass()));
}