mirror of
https://github.com/alibaba/canal.git
synced 2026-11-04 00:30:15 +08:00
= cold cleanup
* using lambda if possible (we are already building in Java8) * using diamond when new generic instance * remove used improt
This commit is contained in:
@@ -42,7 +42,7 @@ public class AviaterRegexFilter {
|
||||
this.defaultEmptyValue = defaultEmptyValue;
|
||||
List<String> list = null;
|
||||
if (StringUtils.isEmpty(pattern)) {
|
||||
list = new ArrayList<String>();
|
||||
list = new ArrayList<>();
|
||||
} else {
|
||||
String[] ss = StringUtils.split(pattern, SPLIT);
|
||||
list = Arrays.asList(ss);
|
||||
@@ -66,7 +66,7 @@ public class AviaterRegexFilter {
|
||||
return defaultEmptyValue;
|
||||
}
|
||||
|
||||
Map<String, Object> env = new HashMap<String, Object>();
|
||||
Map<String, Object> env = new HashMap<>();
|
||||
env.put("pattern", pattern);
|
||||
env.put("target", filtered.toLowerCase());
|
||||
return (Boolean) exp.execute(env);
|
||||
@@ -112,7 +112,7 @@ public class AviaterRegexFilter {
|
||||
*/
|
||||
|
||||
private List<String> completionPattern(List<String> patterns) {
|
||||
List<String> result = new ArrayList<String>();
|
||||
List<String> result = new ArrayList<>();
|
||||
for (String pattern : patterns) {
|
||||
StringBuffer stringBuffer = new StringBuffer();
|
||||
stringBuffer.append("^");
|
||||
|
||||
@@ -35,7 +35,7 @@ public abstract class AbstractMQProducer implements CanalMQProducer {
|
||||
parallelBuildThreadSize,
|
||||
0,
|
||||
TimeUnit.SECONDS,
|
||||
new ArrayBlockingQueue<Runnable>(parallelBuildThreadSize * 2),
|
||||
new ArrayBlockingQueue<>(parallelBuildThreadSize * 2),
|
||||
new NamedThreadFactory("MQ-Parallel-Builder"),
|
||||
new ThreadPoolExecutor.CallerRunsPolicy());
|
||||
|
||||
@@ -44,7 +44,7 @@ public abstract class AbstractMQProducer implements CanalMQProducer {
|
||||
parallelSendThreadSize,
|
||||
0,
|
||||
TimeUnit.SECONDS,
|
||||
new ArrayBlockingQueue<Runnable>(parallelSendThreadSize * 2),
|
||||
new ArrayBlockingQueue<>(parallelSendThreadSize * 2),
|
||||
new NamedThreadFactory("MQ-Parallel-Sender"),
|
||||
new ThreadPoolExecutor.CallerRunsPolicy());
|
||||
}
|
||||
|
||||
@@ -75,64 +75,58 @@ public class MQMessageUtils {
|
||||
|
||||
private static Map<String, List<DynamicTopicData>> dynamicTopicDatas = MigrateMap.makeComputingMap(CacheBuilder.newBuilder()
|
||||
.softValues(),
|
||||
new Function<String, List<DynamicTopicData>>() {
|
||||
pkHashConfigs -> {
|
||||
List<DynamicTopicData> datas = Lists.newArrayList();
|
||||
String[] dynamicTopicArray = StringUtils.split(StringUtils.replace(pkHashConfigs,
|
||||
",",
|
||||
";"),
|
||||
";");
|
||||
// schema.table
|
||||
for (String dynamicTopic : dynamicTopicArray) {
|
||||
DynamicTopicData data = new DynamicTopicData();
|
||||
|
||||
public List<DynamicTopicData> apply(String pkHashConfigs) {
|
||||
List<DynamicTopicData> datas = Lists.newArrayList();
|
||||
String[] dynamicTopicArray = StringUtils.split(StringUtils.replace(pkHashConfigs,
|
||||
",",
|
||||
";"),
|
||||
";");
|
||||
// schema.table
|
||||
for (String dynamicTopic : dynamicTopicArray) {
|
||||
DynamicTopicData data = new DynamicTopicData();
|
||||
if (!isWildCard(dynamicTopic)) {
|
||||
data.simpleName = dynamicTopic;
|
||||
} else {
|
||||
if (dynamicTopic.contains("\\.")) {
|
||||
data.tableRegexFilter = new AviaterRegexFilter(dynamicTopic);
|
||||
} else {
|
||||
data.schemaRegexFilter = new AviaterRegexFilter(dynamicTopic);
|
||||
}
|
||||
}
|
||||
datas.add(data);
|
||||
}
|
||||
|
||||
if (!isWildCard(dynamicTopic)) {
|
||||
data.simpleName = dynamicTopic;
|
||||
} else {
|
||||
if (dynamicTopic.contains("\\.")) {
|
||||
data.tableRegexFilter = new AviaterRegexFilter(dynamicTopic);
|
||||
} else {
|
||||
data.schemaRegexFilter = new AviaterRegexFilter(dynamicTopic);
|
||||
}
|
||||
}
|
||||
datas.add(data);
|
||||
}
|
||||
|
||||
return datas;
|
||||
}
|
||||
});
|
||||
return datas;
|
||||
});
|
||||
|
||||
private static Map<String, List<TopicPartitionData>> topicPartitionDatas = MigrateMap.makeComputingMap(CacheBuilder.newBuilder()
|
||||
.softValues(),
|
||||
new Function<String, List<TopicPartitionData>>() {
|
||||
|
||||
public List<TopicPartitionData> apply(String tPConfigs) {
|
||||
List<TopicPartitionData> datas = Lists.newArrayList();
|
||||
String[] tPArray = StringUtils.split(StringUtils.replace(tPConfigs,
|
||||
",",
|
||||
";"),
|
||||
";");
|
||||
for (String tPConfig : tPArray) {
|
||||
TopicPartitionData data = new TopicPartitionData();
|
||||
int i = tPConfig.lastIndexOf(":");
|
||||
if (i > 0) {
|
||||
String tStr = tPConfig.substring(0, i);
|
||||
String pStr = tPConfig.substring(i + 1);
|
||||
if (!isWildCard(tStr)) {
|
||||
data.simpleName = tStr;
|
||||
} else {
|
||||
data.regexFilter = new AviaterRegexFilter(tStr);
|
||||
}
|
||||
if (!StringUtils.isEmpty(pStr) && StringUtils.isNumeric(pStr)) {
|
||||
data.partitionNum = Integer.valueOf(pStr);
|
||||
}
|
||||
datas.add(data);
|
||||
tPConfigs -> {
|
||||
List<TopicPartitionData> datas = Lists.newArrayList();
|
||||
String[] tPArray = StringUtils.split(StringUtils.replace(tPConfigs,
|
||||
",",
|
||||
";"),
|
||||
";");
|
||||
for (String tPConfig : tPArray) {
|
||||
TopicPartitionData data = new TopicPartitionData();
|
||||
int i = tPConfig.lastIndexOf(":");
|
||||
if (i > 0) {
|
||||
String tStr = tPConfig.substring(0, i);
|
||||
String pStr = tPConfig.substring(i + 1);
|
||||
if (!isWildCard(tStr)) {
|
||||
data.simpleName = tStr;
|
||||
} else {
|
||||
data.regexFilter = new AviaterRegexFilter(tStr);
|
||||
}
|
||||
if (!StringUtils.isEmpty(pStr) && StringUtils.isNumeric(pStr)) {
|
||||
data.partitionNum = Integer.valueOf(pStr);
|
||||
}
|
||||
datas.add(data);
|
||||
}
|
||||
|
||||
return datas;
|
||||
}
|
||||
|
||||
return datas;
|
||||
});
|
||||
|
||||
/**
|
||||
@@ -206,19 +200,15 @@ public class MQMessageUtils {
|
||||
int i = 0;
|
||||
for (ByteString byteString : rawEntries) {
|
||||
final int index = i;
|
||||
template.submit(new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
Entry entry = Entry.parseFrom(byteString);
|
||||
CanalEntry.RowChange rowChange = CanalEntry.RowChange.parseFrom(entry.getStoreValue());
|
||||
datas[index] = new EntryRowData();
|
||||
datas[index].entry = entry;
|
||||
datas[index].rowChange = rowChange;
|
||||
} catch (InvalidProtocolBufferException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
template.submit(() -> {
|
||||
try {
|
||||
Entry entry = Entry.parseFrom(byteString);
|
||||
RowChange rowChange = RowChange.parseFrom(entry.getStoreValue());
|
||||
datas[index] = new EntryRowData();
|
||||
datas[index].entry = entry;
|
||||
datas[index].rowChange = rowChange;
|
||||
} catch (InvalidProtocolBufferException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -232,18 +222,14 @@ public class MQMessageUtils {
|
||||
int i = 0;
|
||||
for (Entry entry : message.getEntries()) {
|
||||
final int index = i;
|
||||
template.submit(new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
CanalEntry.RowChange rowChange = CanalEntry.RowChange.parseFrom(entry.getStoreValue());
|
||||
datas[index] = new EntryRowData();
|
||||
datas[index].entry = entry;
|
||||
datas[index].rowChange = rowChange;
|
||||
} catch (InvalidProtocolBufferException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
template.submit(() -> {
|
||||
try {
|
||||
RowChange rowChange = RowChange.parseFrom(entry.getStoreValue());
|
||||
datas[index] = new EntryRowData();
|
||||
datas[index].entry = entry;
|
||||
datas[index].rowChange = rowChange;
|
||||
} catch (InvalidProtocolBufferException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -679,7 +665,7 @@ public class MQMessageUtils {
|
||||
CanalEntry.Entry entry) {
|
||||
Message message = messageMap.get(topicName);
|
||||
if (message == null) {
|
||||
message = new Message(messageId, new ArrayList<CanalEntry.Entry>());
|
||||
message = new Message(messageId, new ArrayList<>());
|
||||
messageMap.put(topicName, message);
|
||||
}
|
||||
message.getEntries().add(entry);
|
||||
|
||||
@@ -120,13 +120,7 @@ public class CanalRabbitMQProducer extends AbstractMQProducer implements CanalMQ
|
||||
final String topicName = entry.getKey().replace('.', '_');
|
||||
final com.alibaba.otter.canal.protocol.Message messageSub = entry.getValue();
|
||||
|
||||
template.submit(new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
send(destination, topicName, messageSub);
|
||||
}
|
||||
});
|
||||
template.submit(() -> send(destination, topicName, messageSub));
|
||||
}
|
||||
|
||||
template.waitForResult();
|
||||
|
||||
Reference in New Issue
Block a user