Skip to content

Commit

Permalink
porter公共数据源配置前缀修改及全局变量SimpleDateFormat线程安全问题
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangkewei committed Nov 29, 2018
1 parent 9c2d2ce commit 3c51d90
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
* @author: zhangkewei[[email protected]]
Expand Down Expand Up @@ -79,8 +80,8 @@ public List<String> getChildren(String path) {
@Override
public Pair<String, Boolean> getData(String path) {
String content = null;
try (Stream<String> stream = Files.lines(Paths.get(getRealPath(path)))){
content = stream.reduce((p, n) -> p + n).orElse("");
try (Stream<String> stream = Files.lines(Paths.get(getRealPath(path)))) {
content = stream.reduce((p, n) -> p + n).orElse("");
} catch (IOException e) {
LOGGER.warn("getData {} fail.", path, e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,9 @@
import com.alibaba.fastjson.annotation.JSONField;
import lombok.Getter;
import lombok.Setter;
import org.apache.commons.lang3.time.FastDateFormat;
import org.slf4j.LoggerFactory;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.UUID;

Expand All @@ -44,7 +43,7 @@ public class StatisticData {
@JSONField(serialize = false, deserialize = false)
protected static final org.slf4j.Logger LOGGER = LoggerFactory.getLogger(StatisticData.class);
@JSONField(serialize = false, deserialize = false)
private final DateFormat idDateFormat = new SimpleDateFormat("yyyyMMddHHmmssSSS");
private final FastDateFormat idDateFormat = FastDateFormat.getInstance("yyyyMMddHHmmssSSS");
// 节点ID
@Setter
@Getter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
* @review: zhangkewei[[email protected]]/2017年12月19日 13:59
*/

@ConfigurationProperties(prefix = "node")
@ConfigurationProperties(prefix = "porter")
@Component
public class SourcesConfig {
private Map<String, Map<String, String>> source;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.time.FastDateFormat;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Map;

/**
Expand All @@ -43,8 +43,8 @@ public class OggJsonConverter implements EventConverter {

private static final Logger LOGGER = LoggerFactory.getLogger(OggJsonConverter.class);

private DateFormat opTsF = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss.SSS");
private DateFormat ctsf = new SimpleDateFormat("yyyy-MM-dd'T'hh:mm:ss.SSS");
private FastDateFormat opTsF = FastDateFormat.getInstance("yyyy-MM-dd hh:mm:ss.SSS");
private FastDateFormat ctsf = FastDateFormat.getInstance("yyyy-MM-dd'T'hh:mm:ss.SSS");

@Override
public String getName() {
Expand Down Expand Up @@ -72,15 +72,15 @@ public MessageEvent convert(Object... params) {
}
event.setOpType(eventType);
try {
String poTS = obj.getString("op_ts");
event.setOpTs(opTsF.parse(poTS.substring(0, poTS.length() - 3)));
String poTS = obj.containsKey("op_ts") ? obj.getString("op_ts") : null;
if (StringUtils.isNotEmpty(poTS)) event.setOpTs(opTsF.parse(poTS.substring(0, poTS.length() - 3)));
} catch (Exception e) {
LOGGER.error("op_ts", e);
}

try {
String currentTS = obj.getString("current_ts");
event.setCurrentTs(ctsf.parse(currentTS.substring(0, currentTS.length() - 3)));
String currentTS = obj.containsKey("current_ts") ? obj.getString("current_ts") : null;
if (StringUtils.isNotEmpty(currentTS)) event.setCurrentTs(ctsf.parse(currentTS.substring(0, currentTS.length() - 3)));
} catch (Exception e) {
LOGGER.error("解析current_ts出错", e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,14 @@
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import cn.vbill.middleware.porter.core.event.etl.ETLRow;
import org.apache.commons.lang.time.FastDateFormat;
import org.apache.commons.lang3.tuple.ImmutablePair;
import org.apache.commons.lang3.tuple.ImmutableTriple;
import org.apache.commons.lang3.tuple.Pair;
import org.apache.commons.lang3.tuple.Triple;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.stream.Stream;

Expand All @@ -52,8 +51,8 @@ public class KafkaLoader extends AbstractDataLoader {

private static final Logger LOGGER = LoggerFactory.getLogger(KafkaLoader.class);

private static final DateFormat OP_TS_F = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss.SSS");
private static final DateFormat C_TS_F = new SimpleDateFormat("yyyy-MM-dd'T'hh:mm:ss.SSS000");
private static final FastDateFormat OP_TS_F = FastDateFormat.getInstance("yyyy-MM-dd hh:mm:ss.SSS");
private static final FastDateFormat C_TS_F = FastDateFormat.getInstance("yyyy-MM-dd'T'hh:mm:ss.SSS000");
@Override
protected String getPluginName() {
return LoaderPlugin.KAFKA_SYNC.getCode();
Expand Down

0 comments on commit 3c51d90

Please sign in to comment.