Search in sources :

Example 1 with Hook

use of com.alibaba.datax.common.spi.Hook in project DataX by alibaba.

the class HookInvoker method doInvoke.

private void doInvoke(String path) {
    ClassLoader oldClassLoader = Thread.currentThread().getContextClassLoader();
    try {
        JarLoader jarLoader = new JarLoader(new String[] { path });
        Thread.currentThread().setContextClassLoader(jarLoader);
        Iterator<Hook> hookIt = ServiceLoader.load(Hook.class).iterator();
        if (!hookIt.hasNext()) {
            LOG.warn("No hook defined under path: " + path);
        } else {
            Hook hook = hookIt.next();
            LOG.info("Invoke hook [{}], path: {}", hook.getName(), path);
            hook.invoke(conf, msg);
        }
    } catch (Exception e) {
        LOG.error("Exception when invoke hook", e);
        throw DataXException.asDataXException(CommonErrorCode.HOOK_INTERNAL_ERROR, "Exception when invoke hook", e);
    } finally {
        Thread.currentThread().setContextClassLoader(oldClassLoader);
    }
}
Also used : Hook(com.alibaba.datax.common.spi.Hook) JarLoader(com.alibaba.datax.core.util.container.JarLoader) DataXException(com.alibaba.datax.common.exception.DataXException)

Aggregations

DataXException (com.alibaba.datax.common.exception.DataXException)1 Hook (com.alibaba.datax.common.spi.Hook)1 JarLoader (com.alibaba.datax.core.util.container.JarLoader)1