|
@@ -10,7 +10,7 @@ import java.util.concurrent.Future;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
|
-import com.alibaba.otter.canal.client.adapter.CanalOuterAdapter;
|
|
|
+import com.alibaba.otter.canal.client.adapter.OuterAdapter;
|
|
|
import com.alibaba.otter.canal.client.adapter.support.MessageUtil;
|
|
|
import com.alibaba.otter.canal.protocol.Message;
|
|
|
|
|
@@ -25,43 +25,33 @@ public abstract class AbstractCanalAdapterWorker {
|
|
|
protected final Logger logger = LoggerFactory.getLogger(this.getClass());
|
|
|
|
|
|
protected String canalDestination; // canal实例
|
|
|
- protected List<List<CanalOuterAdapter>> canalOuterAdapters; // 外部适配器
|
|
|
+ protected List<List<OuterAdapter>> canalOuterAdapters; // 外部适配器
|
|
|
protected ExecutorService groupInnerExecutorService; // 组内工作线程池
|
|
|
protected volatile boolean running = false; // 是否运行中
|
|
|
protected Thread thread = null;
|
|
|
- protected Thread.UncaughtExceptionHandler handler = new Thread.UncaughtExceptionHandler() {
|
|
|
-
|
|
|
- @Override
|
|
|
- public void uncaughtException(Thread t, Throwable e) {
|
|
|
- logger.error("parse events has an error", e);
|
|
|
- }
|
|
|
- };
|
|
|
+ protected Thread.UncaughtExceptionHandler handler = (t, e) -> logger.error("parse events has an error", e);
|
|
|
|
|
|
protected void writeOut(final Message message) {
|
|
|
List<Future<Boolean>> futures = new ArrayList<>();
|
|
|
// 组间适配器并行运行
|
|
|
- for (List<CanalOuterAdapter> outerAdapters : canalOuterAdapters) {
|
|
|
- final List<CanalOuterAdapter> adapters = outerAdapters;
|
|
|
- futures.add(groupInnerExecutorService.submit(new Callable<Boolean>() {
|
|
|
-
|
|
|
- @Override
|
|
|
- public Boolean call() {
|
|
|
- try {
|
|
|
- // 组内适配器穿行运行,尽量不要配置组内适配器
|
|
|
- for (final CanalOuterAdapter c : adapters) {
|
|
|
- long begin = System.currentTimeMillis();
|
|
|
- MessageUtil.parse4Dml(message, c::writeOut);
|
|
|
-
|
|
|
- if (logger.isDebugEnabled()) {
|
|
|
- logger.debug("{} elapsed time: {}",
|
|
|
- c.getClass().getName(),
|
|
|
- (System.currentTimeMillis() - begin));
|
|
|
- }
|
|
|
+ for (List<OuterAdapter> outerAdapters : canalOuterAdapters) {
|
|
|
+ final List<OuterAdapter> adapters = outerAdapters;
|
|
|
+ futures.add(groupInnerExecutorService.submit(() -> {
|
|
|
+ try {
|
|
|
+ // 组内适配器穿行运行,尽量不要配置组内适配器
|
|
|
+ for (final OuterAdapter c : adapters) {
|
|
|
+ long begin = System.currentTimeMillis();
|
|
|
+ MessageUtil.parse4Dml(message, c::sync);
|
|
|
+
|
|
|
+ if (logger.isDebugEnabled()) {
|
|
|
+ logger.debug("{} elapsed time: {}",
|
|
|
+ c.getClass().getName(),
|
|
|
+ (System.currentTimeMillis() - begin));
|
|
|
}
|
|
|
- return true;
|
|
|
- } catch (Exception e) {
|
|
|
- return false;
|
|
|
}
|
|
|
+ return true;
|
|
|
+ } catch (Exception e) {
|
|
|
+ return false;
|
|
|
}
|
|
|
}));
|
|
|
|
|
@@ -131,9 +121,6 @@ public abstract class AbstractCanalAdapterWorker {
|
|
|
if ((System.currentTimeMillis() - begin) > 5 * 60 * 1000) {
|
|
|
logger.error("topic: {} batchId {} elapsed time: {} ms", topic, message.getId(), now - begin);
|
|
|
}
|
|
|
- if (logger.isDebugEnabled()) {
|
|
|
- logger.debug("topic: {} batchId {} elapsed time: {} ms", topic, message.getId(), now - begin);
|
|
|
- }
|
|
|
}
|
|
|
|
|
|
protected void stopOutAdapters() {
|
|
@@ -146,8 +133,8 @@ public abstract class AbstractCanalAdapterWorker {
|
|
|
}
|
|
|
groupInnerExecutorService.shutdown();
|
|
|
logger.info("topic connectors' worker thread dead!");
|
|
|
- for (List<CanalOuterAdapter> outerAdapters : canalOuterAdapters) {
|
|
|
- for (CanalOuterAdapter adapter : outerAdapters) {
|
|
|
+ for (List<OuterAdapter> outerAdapters : canalOuterAdapters) {
|
|
|
+ for (OuterAdapter adapter : outerAdapters) {
|
|
|
adapter.destroy();
|
|
|
}
|
|
|
}
|