use of com.alibaba.otter.canal.parse.CanalEventParser in project canal by alibaba.
the class AbstractCanalInstance method subscribeChange.
@Override
public boolean subscribeChange(ClientIdentity identity) {
if (StringUtils.isNotEmpty(identity.getFilter())) {
logger.info("subscribe filter change to " + identity.getFilter());
AviaterRegexFilter aviaterFilter = new AviaterRegexFilter(identity.getFilter());
boolean isGroup = (eventParser instanceof GroupEventParser);
if (isGroup) {
// 处理group的模式
List<CanalEventParser> eventParsers = ((GroupEventParser) eventParser).getEventParsers();
for (CanalEventParser singleEventParser : eventParsers) {
// 需要遍历启动
if (singleEventParser instanceof AbstractEventParser) {
((AbstractEventParser) singleEventParser).setEventFilter(aviaterFilter);
}
}
} else {
if (eventParser instanceof AbstractEventParser) {
((AbstractEventParser) eventParser).setEventFilter(aviaterFilter);
}
}
}
// 后续内存版的一对多分发,可以考虑
return true;
}
use of com.alibaba.otter.canal.parse.CanalEventParser in project canal by alibaba.
the class ParserCollector method groupHolder.
private GroupParserMetricsHolder groupHolder(String destination, GroupEventParser group) {
List<CanalEventParser> parsers = group.getEventParsers();
GroupParserMetricsHolder groupHolder = new GroupParserMetricsHolder();
int num = parsers.size();
for (int i = 0; i < num; i++) {
CanalEventParser parser = parsers.get(i);
if (parser instanceof AbstractMysqlEventParser) {
ParserMetricsHolder single = singleHolder(destination, (AbstractMysqlEventParser) parser, Integer.toString(i + 1));
groupHolder.holders.add(single);
} else {
logger.warn("Null or non AbstractMysqlEventParser, ignore.");
}
}
return groupHolder;
}
use of com.alibaba.otter.canal.parse.CanalEventParser in project canal by alibaba.
the class BaseCanalServerWithEmbededTest method testSwitch.
// @Test
public void testSwitch() {
int maxEmptyCount = 10;
int emptyCount = 0;
int totalCount = 0;
int thresold = 50;
int batchSize = 11;
server.subscribe(clientIdentity);
while (emptyCount < maxEmptyCount) {
Message message = server.get(clientIdentity, batchSize);
if (CollectionUtils.isEmpty(message.getEntries())) {
emptyCount++;
try {
Thread.sleep(emptyCount * 300L);
} catch (InterruptedException e) {
Assert.fail();
}
System.out.println("empty count : " + emptyCount);
} else {
emptyCount = 0;
totalCount += message.getEntries().size();
if ((totalCount + 1) % 100 >= thresold && (totalCount + 1) % 100 <= thresold + batchSize) {
CanalEventParser eventParser = server.getCanalInstances().get(DESTINATION).getEventParser();
if (eventParser instanceof CanalHASwitchable) {
// 执行切换
((CanalHASwitchable) eventParser).doSwitch();
try {
// 等待parser启动
Thread.sleep(5 * 1000);
} catch (InterruptedException e) {
Assert.fail();
}
}
}
}
}
System.out.println("!!!!!! testGet totalCount : " + totalCount);
server.unsubscribe(clientIdentity);
}
Aggregations