package com.tmerclub.cloud.search.canal;

import com.tmerclub.cloud.search.canal.model.CanalBinLogEvent;
import com.tmerclub.cloud.search.canal.model.ModelTable;
import com.tmerclub.cloud.search.canal.support.adapter.SourceAdapterFacade;
import com.tmerclub.cloud.search.canal.support.processor.CanalBinlogEventProcessorFactory;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * @author throwable
 * @version v1
 * @description
 * @since 2020/9/23 0:54
 */
public class DefaultCanalGlue implements CanalGlue {

    @Autowired
    private CanalBinlogEventProcessorFactory canalBinlogEventProcessorFactory;

    @Override
    public void process(String content) {
        CanalBinLogEvent event = SourceAdapterFacade.X.adapt(CanalBinLogEvent.class, content);
        ModelTable modelTable = ModelTable.of(event.getDatabase(), event.getTable());
        canalBinlogEventProcessorFactory.get(modelTable).forEach(processor -> processor.process(event));
    }
}
