整理代码

This commit is contained in:
rewer
2019-02-07 13:49:35 +08:00
parent ad62275cd7
commit 0c5f5c128f
14 changed files with 3253 additions and 3243 deletions

View File

@@ -67,8 +67,8 @@ public class YmlConfigBinder {
} }
/** /**
* 将当前内容指定前缀部分绑定到指定对象并用环境变量中的属性替换占位符, 例: 当前内容有属性 zkServers: ${zookeeper.servers} * 将当前内容指定前缀部分绑定到指定对象并用环境变量中的属性替换占位符, 例: 当前内容有属性 zkServers:
* 在envProperties中有属性 zookeeper.servers: * ${zookeeper.servers} 在envProperties中有属性 zookeeper.servers:
* 192.168.0.1:2181,192.168.0.1:2181,192.168.0.1:2181 则当前内容 zkServers 会被替换为 * 192.168.0.1:2181,192.168.0.1:2181,192.168.0.1:2181 则当前内容 zkServers 会被替换为
* zkServers: 192.168.0.1:2181,192.168.0.1:2181,192.168.0.1:2181 注: 假设绑定的类中 * zkServers: 192.168.0.1:2181,192.168.0.1:2181,192.168.0.1:2181 注: 假设绑定的类中
* zkServers 属性是 List<String> 对象, 则会自动映射成List * zkServers 属性是 List<String> 对象, 则会自动映射成List
@@ -90,7 +90,7 @@ public class YmlConfigBinder {
} }
YamlPropertySourceLoader propertySourceLoader = new YamlPropertySourceLoader(); YamlPropertySourceLoader propertySourceLoader = new YamlPropertySourceLoader();
Resource configResource = new ByteArrayResource(contentBytes); Resource configResource = new ByteArrayResource(contentBytes);
PropertySource propertySource = propertySourceLoader.load("manualBindConfig", configResource, null); PropertySource<?> propertySource = propertySourceLoader.load("manualBindConfig", configResource, null);
if (propertySource == null) { if (propertySource == null) {
return null; return null;
@@ -102,15 +102,15 @@ public class YmlConfigBinder {
prefix = prefix + "."; prefix = prefix + ".";
} }
properties.putAll((Map) propertySource.getSource()); properties.putAll((Map<?, ?>) propertySource.getSource());
if (baseProperties != null) { if (baseProperties != null) {
baseProperties.putAll(properties); baseProperties.putAll(properties);
properties = baseProperties; properties = baseProperties;
} }
for (Object o : ((Map) propertySource.getSource()).entrySet()) { for (Object o : ((Map<?, ?>) propertySource.getSource()).entrySet()) {
Map.Entry entry = (Map.Entry) o; Map.Entry<?, ?> entry = (Map.Entry<?, ?>) o;
String key = (String) entry.getKey(); String key = (String) entry.getKey();
Object value = entry.getValue(); Object value = entry.getValue();

View File

@@ -6,7 +6,6 @@ import java.io.InputStream;
import java.util.Arrays; import java.util.Arrays;
import org.springframework.core.io.InputStreamResource; import org.springframework.core.io.InputStreamResource;
import org.springframework.core.io.InputStreamSource;
import org.springframework.core.io.Resource; import org.springframework.core.io.Resource;
import org.springframework.util.Assert; import org.springframework.util.Assert;

View File

@@ -80,7 +80,7 @@ public class SchemaItem {
columnFields = new LinkedHashMap<>(); columnFields = new LinkedHashMap<>();
getSelectFields() getSelectFields()
.forEach((fieldName, fieldItem) -> fieldItem.getColumnItems().forEach(columnItem -> { .forEach((fieldName, fieldItem) -> fieldItem.getColumnItems().forEach(columnItem -> {
TableItem tableItem = getAliasTableItems().get(columnItem.getOwner()); // TableItem tableItem = getAliasTableItems().get(columnItem.getOwner());
// if (!tableItem.isSubQuery()) { // if (!tableItem.isSubQuery()) {
List<FieldItem> fieldItems = columnFields.computeIfAbsent( List<FieldItem> fieldItems = columnFields.computeIfAbsent(
columnItem.getOwner() + "." + columnItem.getColumnName(), columnItem.getOwner() + "." + columnItem.getColumnName(),

View File

@@ -191,7 +191,7 @@ public class ESTemplate {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
esFieldData.forEach((key, value) -> { esFieldData.forEach((key, value) -> {
if (value instanceof Map) { if (value instanceof Map) {
HashMap mapValue = (HashMap) value; Map<?, ?> mapValue = (Map<?, ?>) value;
if (mapValue.containsKey("lon") && mapValue.containsKey("lat") && mapValue.size() == 2) { if (mapValue.containsKey("lon") && mapValue.containsKey("lat") && mapValue.size() == 2) {
sb.append("ctx._source") sb.append("ctx._source")
.append("['") .append("['")

View File

@@ -1,6 +1,7 @@
package com.alibaba.otter.canal.client.adapter.hbase.service; package com.alibaba.otter.canal.client.adapter.hbase.service;
import java.sql.*; import java.sql.ResultSetMetaData;
import java.sql.Timestamp;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Date; import java.util.Date;
@@ -10,19 +11,23 @@ import java.util.concurrent.Executors;
import java.util.concurrent.Future; import java.util.concurrent.Future;
import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicLong; import java.util.concurrent.atomic.AtomicLong;
import java.util.function.Function;
import javax.sql.DataSource; import javax.sql.DataSource;
import com.alibaba.otter.canal.client.adapter.support.Util;
import org.apache.hadoop.hbase.util.Bytes; import org.apache.hadoop.hbase.util.Bytes;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import com.alibaba.otter.canal.client.adapter.hbase.config.MappingConfig; import com.alibaba.otter.canal.client.adapter.hbase.config.MappingConfig;
import com.alibaba.otter.canal.client.adapter.hbase.support.*; import com.alibaba.otter.canal.client.adapter.hbase.support.HRow;
import com.alibaba.otter.canal.client.adapter.hbase.support.HbaseTemplate;
import com.alibaba.otter.canal.client.adapter.hbase.support.PhType;
import com.alibaba.otter.canal.client.adapter.hbase.support.PhTypeUtil;
import com.alibaba.otter.canal.client.adapter.hbase.support.Type;
import com.alibaba.otter.canal.client.adapter.hbase.support.TypeUtil;
import com.alibaba.otter.canal.client.adapter.support.EtlResult; import com.alibaba.otter.canal.client.adapter.support.EtlResult;
import com.alibaba.otter.canal.client.adapter.support.JdbcTypeUtil; import com.alibaba.otter.canal.client.adapter.support.JdbcTypeUtil;
import com.alibaba.otter.canal.client.adapter.support.Util;
import com.google.common.base.Joiner; import com.google.common.base.Joiner;
/** /**

View File

@@ -151,7 +151,7 @@ public class CanalAdapterLoader {
evnProperties = new Properties(); evnProperties = new Properties();
for (PropertySource<?> propertySource : ((StandardEnvironment) env).getPropertySources()) { for (PropertySource<?> propertySource : ((StandardEnvironment) env).getPropertySources()) {
if (propertySource instanceof EnumerablePropertySource) { if (propertySource instanceof EnumerablePropertySource) {
String[] names = ((EnumerablePropertySource) propertySource).getPropertyNames(); String[] names = ((EnumerablePropertySource<?>) propertySource).getPropertyNames();
for (String name : names) { for (String name : names) {
Object val = propertySource.getProperty(name); Object val = propertySource.getProperty(name);
if (val != null) { if (val != null) {

View File

@@ -139,9 +139,7 @@ public class DbRemoteConfigLoader implements RemoteConfigLoader {
/** /**
* 加载有变动的adapter配置 * 加载有变动的adapter配置
*/ */
@SuppressWarnings("unchecked")
private void loadModifiedAdapterConfigs() { private void loadModifiedAdapterConfigs() {
Map<String, ConfigItem>[] res = new Map[2];
Map<String, ConfigItem> remoteConfigStatus = new HashMap<>(); Map<String, ConfigItem> remoteConfigStatus = new HashMap<>();
String sql = "select id, category, name, modified_time from canal_adapter_config"; String sql = "select id, category, name, modified_time from canal_adapter_config";
try (Connection conn = dataSource.getConnection(); try (Connection conn = dataSource.getConnection();

View File

@@ -4,12 +4,10 @@ import java.util.LinkedHashMap;
import java.util.Map; import java.util.Map;
import java.util.Properties; import java.util.Properties;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.otter.canal.client.adapter.config.YmlConfigBinder;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.yaml.snakeyaml.Yaml;
import com.alibaba.otter.canal.client.adapter.config.YmlConfigBinder;
import com.alibaba.otter.canal.client.adapter.support.MappingConfigsLoader; import com.alibaba.otter.canal.client.adapter.support.MappingConfigsLoader;
/** /**

View File

@@ -4,7 +4,6 @@ import java.io.File;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import com.alibaba.otter.canal.client.adapter.rdb.config.MirrorDbConfig;
import org.apache.commons.io.filefilter.FileFilterUtils; import org.apache.commons.io.filefilter.FileFilterUtils;
import org.apache.commons.io.monitor.FileAlterationListenerAdaptor; import org.apache.commons.io.monitor.FileAlterationListenerAdaptor;
import org.apache.commons.io.monitor.FileAlterationMonitor; import org.apache.commons.io.monitor.FileAlterationMonitor;

View File

@@ -3,8 +3,16 @@ package com.alibaba.otter.canal.client.adapter.rdb.service;
import java.sql.Connection; import java.sql.Connection;
import java.sql.ResultSetMetaData; import java.sql.ResultSetMetaData;
import java.sql.SQLException; import java.sql.SQLException;
import java.util.*; import java.util.ArrayList;
import java.util.concurrent.*; import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.function.Function; import java.util.function.Function;
import javax.sql.DataSource; import javax.sql.DataSource;
@@ -51,7 +59,6 @@ public class RdbSyncService {
return columnsTypeCache; return columnsTypeCache;
} }
@SuppressWarnings("unchecked")
public RdbSyncService(DataSource dataSource, Integer threads, boolean skipDupException){ public RdbSyncService(DataSource dataSource, Integer threads, boolean skipDupException){
this(dataSource, threads, new ConcurrentHashMap<>(), skipDupException); this(dataSource, threads, new ConcurrentHashMap<>(), skipDupException);
} }
@@ -95,7 +102,7 @@ public class RdbSyncService {
} }
} }
if (toExecute) { if (toExecute) {
List<Future> futures = new ArrayList<>(); List<Future<Boolean>> futures = new ArrayList<>();
for (int i = 0; i < threads; i++) { for (int i = 0; i < threads; i++) {
int j = i; int j = i;
futures.add(executorThreads[i].submit(() -> { futures.add(executorThreads[i].submit(() -> {

View File

@@ -4,7 +4,6 @@ import java.util.*;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import com.google.common.collect.MapMaker;
import org.apache.kafka.clients.consumer.ConsumerRecord; import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.apache.kafka.clients.consumer.ConsumerRecords; import org.apache.kafka.clients.consumer.ConsumerRecords;
import org.apache.kafka.clients.consumer.KafkaConsumer; import org.apache.kafka.clients.consumer.KafkaConsumer;

View File

@@ -11,6 +11,9 @@ import org.springframework.beans.BeanUtils;
* @Date 2018/12/17 * @Date 2018/12/17
*/ */
public class KafkaFlatMessage extends FlatMessage { public class KafkaFlatMessage extends FlatMessage {
private static final long serialVersionUID = 5748024400508080710L;
/** /**
* Kafka 消息 offset * Kafka 消息 offset
*/ */

View File

@@ -11,6 +11,9 @@ import org.springframework.beans.BeanUtils;
* @Date 2018/12/17 * @Date 2018/12/17
*/ */
public class KafkaMessage extends Message { public class KafkaMessage extends Message {
private static final long serialVersionUID = -293120358490119447L;
/** /**
* Kafka 消息 offset * Kafka 消息 offset
*/ */
@@ -22,7 +25,6 @@ public class KafkaMessage extends Message {
this.offset = offset; this.offset = offset;
} }
public long getOffset() { public long getOffset() {
return offset; return offset;
} }