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);
}
}
Aggregations