Search in sources :

Example 1 with Versioned

use of org.apache.kafka.connect.components.Versioned in project kafka by apache.

the class Plugins method newPlugin.

public <T> T newPlugin(String klassName, AbstractConfig config, Class<T> pluginKlass) {
    T plugin;
    Class<? extends T> klass;
    try {
        klass = pluginClass(delegatingLoader, klassName, pluginKlass);
    } catch (ClassNotFoundException e) {
        String msg = String.format("Failed to find any class that implements %s and which " + "name matches %s", pluginKlass, klassName);
        throw new ConnectException(msg);
    }
    ClassLoader savedLoader = compareAndSwapLoaders(klass.getClassLoader());
    try {
        plugin = newPlugin(klass);
        if (plugin instanceof Versioned) {
            Versioned versionedPlugin = (Versioned) plugin;
            if (Utils.isBlank(versionedPlugin.version())) {
                throw new ConnectException("Version not defined for '" + klassName + "'");
            }
        }
        if (plugin instanceof Configurable) {
            ((Configurable) plugin).configure(config.originals());
        }
    } finally {
        compareAndSwapLoaders(savedLoader);
    }
    return plugin;
}
Also used : Versioned(org.apache.kafka.connect.components.Versioned) Configurable(org.apache.kafka.common.Configurable) ConnectException(org.apache.kafka.connect.errors.ConnectException)

Aggregations

Configurable (org.apache.kafka.common.Configurable)1 Versioned (org.apache.kafka.connect.components.Versioned)1 ConnectException (org.apache.kafka.connect.errors.ConnectException)1