mirror of
https://gitee.com/jd-platform-opensource/jlog.git
synced 2024-12-01 19:37:36 +08:00
filter修改
This commit is contained in:
parent
c71b71c4bf
commit
d1b669a3f7
@ -1,79 +0,0 @@
|
||||
package com.jd.platform.jlog.client.cache;
|
||||
|
||||
import org.reflections.Reflections;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import javax.servlet.ServletRequest;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
/**
|
||||
* @author tangbohu
|
||||
* @version 1.0.0
|
||||
* @ClassName ExtParamFactory.java
|
||||
* @Description TODO
|
||||
* @createTime 2022年03月21日 20:10:00
|
||||
*/
|
||||
public class ExtParamFactory {
|
||||
|
||||
|
||||
private static Logger LOGGER = LoggerFactory.getLogger(ExtParamFactory.class);
|
||||
|
||||
private static volatile ReqMap reqMap = null;
|
||||
|
||||
private static volatile RespMap respMap = null;
|
||||
|
||||
private static AtomicBoolean reqHasLoad = new AtomicBoolean(false);
|
||||
|
||||
private static AtomicBoolean respHasLoad = new AtomicBoolean(false);
|
||||
|
||||
|
||||
public static Map<String, Object> getReqMap(ServletRequest request) {
|
||||
try {
|
||||
if(!reqHasLoad.get() && reqMap == null){
|
||||
synchronized (ExtParamFactory.class){
|
||||
if(reqMap == null){
|
||||
Reflections reflections = new Reflections();
|
||||
Set<Class<? extends ReqMap>> subTypes = reflections.getSubTypesOf(ReqMap.class);
|
||||
for (Class<? extends ReqMap> subType : subTypes) {
|
||||
reqMap = subType.newInstance();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
reqHasLoad.set(true);
|
||||
}
|
||||
return reqMap == null ? new HashMap<>(0) : reqMap.appendResMap(request);
|
||||
}catch (Exception e){
|
||||
LOGGER.error("反射获取入参异常",e);
|
||||
}
|
||||
return new HashMap<>(0);
|
||||
}
|
||||
|
||||
public static Map<String, Object> getRespMap(String cnt) {
|
||||
|
||||
try {
|
||||
if(!respHasLoad.get() && respMap == null){
|
||||
synchronized (ExtParamFactory.class){
|
||||
if(respMap == null){
|
||||
Reflections reflections = new Reflections();
|
||||
Set<Class<? extends RespMap>> subTypes = reflections.getSubTypesOf(RespMap.class);
|
||||
for (Class<? extends RespMap> subType : subTypes) {
|
||||
respMap = subType.newInstance();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
respHasLoad.set(true);
|
||||
}
|
||||
return respMap == null ? new HashMap<>(0) : respMap.appendRespMap(cnt);
|
||||
}catch (Exception e){
|
||||
LOGGER.error("反射获取出参异常",e);
|
||||
}
|
||||
return new HashMap<>(0);
|
||||
}
|
||||
|
||||
}
|
@ -1,22 +0,0 @@
|
||||
package com.jd.platform.jlog.client.cache;
|
||||
|
||||
import javax.servlet.ServletRequest;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author tangbohu
|
||||
* @version 1.0.0
|
||||
* @ClassName ReqMap.java
|
||||
* @Description TODO
|
||||
* @createTime 2022年03月21日 19:18:00
|
||||
*/
|
||||
public interface ReqMap {
|
||||
|
||||
|
||||
/**
|
||||
* @param request
|
||||
* @return
|
||||
*/
|
||||
Map<String, Object> appendResMap(ServletRequest request);
|
||||
|
||||
}
|
@ -1,23 +0,0 @@
|
||||
package com.jd.platform.jlog.client.cache;
|
||||
|
||||
import javax.servlet.ServletResponse;
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
/**
|
||||
* @author tangbohu
|
||||
* @version 1.0.0
|
||||
* @ClassName RespMap.java
|
||||
* @Description TODO
|
||||
* @createTime 2022年03月21日 19:18:00
|
||||
*/
|
||||
public interface RespMap {
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @param cnt
|
||||
* @return
|
||||
*/
|
||||
Map<String, Object> appendRespMap(String cnt);
|
||||
}
|
@ -1,7 +1,6 @@
|
||||
package com.jd.platform.jlog.client.filter;
|
||||
|
||||
import com.jd.platform.jlog.client.Context;
|
||||
import com.jd.platform.jlog.client.cache.ExtParamFactory;
|
||||
import com.jd.platform.jlog.client.log.LogExceptionStackTrace;
|
||||
import com.jd.platform.jlog.client.percent.DefaultTracerPercentImpl;
|
||||
import com.jd.platform.jlog.client.percent.ITracerPercent;
|
||||
@ -9,8 +8,9 @@ import com.jd.platform.jlog.client.tracerholder.TracerHolder;
|
||||
import com.jd.platform.jlog.client.udp.UdpSender;
|
||||
import com.jd.platform.jlog.common.model.TracerBean;
|
||||
import com.jd.platform.jlog.common.handler.CompressHandler.Outcome;
|
||||
import com.jd.platform.jlog.common.utils.FastJsonUtils;
|
||||
import com.jd.platform.jlog.common.utils.IdWorker;
|
||||
import com.jd.platform.jlog.common.utils.IpUtils;
|
||||
import com.jd.platform.jlog.common.utils.StringUtil;
|
||||
import com.jd.platform.jlog.core.ClientHandler;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
@ -18,7 +18,6 @@ import org.slf4j.LoggerFactory;
|
||||
import javax.servlet.*;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
import java.util.*;
|
||||
@ -26,7 +25,7 @@ import java.util.*;
|
||||
|
||||
/**
|
||||
* HttpFilter
|
||||
* http://blog.chinaunix.net/uid-20783755-id-4729930.html
|
||||
* <a href="http://blog.chinaunix.net/uid-20783755-id-4729930.html">.参考.</a>
|
||||
*
|
||||
* @author wuweifeng
|
||||
* @version 1.0
|
||||
@ -118,7 +117,8 @@ public class HttpFilter implements Filter {
|
||||
byte[] contentBytes = mResp.getContent();
|
||||
String content = new String(contentBytes);
|
||||
|
||||
Map<String, Object> map = ExtParamFactory.getRespMap(content);
|
||||
Map<String, Object> map = FastJsonUtils.toMap(content);
|
||||
|
||||
Outcome outcome = ClientHandler.processResp(contentBytes, map);
|
||||
|
||||
//此处可以对content做处理,然后再把content写回到输出流中
|
||||
@ -142,8 +142,16 @@ public class HttpFilter implements Filter {
|
||||
requestMap.put(key, params.get(key)[0]);
|
||||
}
|
||||
tracerBean.setUid((String) requestMap.get("uid"));
|
||||
|
||||
//对于@RequestBody类型的,可以通过该方法读取字符串。是个json串
|
||||
String body = requestWrapper.getBody();
|
||||
if (StringUtil.isNotBlank(body)) {
|
||||
//将json转成map
|
||||
Map<String, Object> jsonMap = FastJsonUtils.toMap(body);
|
||||
// 自定义的其他的参数对
|
||||
requestMap.putAll(ExtParamFactory.getReqMap(requestWrapper));
|
||||
requestMap.putAll(jsonMap);
|
||||
}
|
||||
|
||||
Outcome out = ClientHandler.processReq(requestMap);
|
||||
tracerBean.setRequestContent((byte[]) out.getContent());
|
||||
}
|
||||
|
@ -101,7 +101,7 @@ public class UdpClient {
|
||||
}
|
||||
String[] ipPort = workerIpPort.split(Constant.SPLITER);
|
||||
//发往worker的ip
|
||||
remoteAddress= new InetSocketAddress(ipPort[0], Integer.valueOf(ipPort[1]));
|
||||
remoteAddress= new InetSocketAddress(ipPort[0], Integer.parseInt(ipPort[1]));
|
||||
}else{
|
||||
remoteAddress=tracerData.getAddress();
|
||||
}
|
||||
|
@ -35,23 +35,23 @@ public class UdpSender {
|
||||
/**
|
||||
* 本地队列满了后丢弃的数量
|
||||
*/
|
||||
private static AtomicLong FAIL_OFFER_COUNT = new AtomicLong();
|
||||
private static final AtomicLong FAIL_OFFER_COUNT = new AtomicLong();
|
||||
/**
|
||||
* 本地队列,已写入的总数量
|
||||
*/
|
||||
private static AtomicLong SUCCESS_OFFER_COUNT = new AtomicLong();
|
||||
private static final AtomicLong SUCCESS_OFFER_COUNT = new AtomicLong();
|
||||
/**
|
||||
* 本地logger日志队列,已写入的总数量
|
||||
*/
|
||||
private static AtomicLong SUCCESS_LOGGER_OFFER_COUNT = new AtomicLong();
|
||||
private static final AtomicLong SUCCESS_LOGGER_OFFER_COUNT = new AtomicLong();
|
||||
/**
|
||||
* 出入参集中营,最多积压5万条
|
||||
*/
|
||||
private static LinkedBlockingQueue<TracerBean> tracerBeanQueue = new LinkedBlockingQueue<>(50000);
|
||||
private static final LinkedBlockingQueue<TracerBean> tracerBeanQueue = new LinkedBlockingQueue<>(50000);
|
||||
/**
|
||||
* 日志集中营,最多积压5万条
|
||||
*/
|
||||
private static LinkedBlockingQueue<RunLogMessage> logBeanQueue = new LinkedBlockingQueue<>(50000);
|
||||
private static final LinkedBlockingQueue<RunLogMessage> logBeanQueue = new LinkedBlockingQueue<>(50000);
|
||||
|
||||
|
||||
/**
|
||||
|
@ -4,7 +4,6 @@ import com.google.protobuf.ByteString;
|
||||
import com.ibm.etcd.api.Event;
|
||||
import com.ibm.etcd.api.KeyValue;
|
||||
import com.ibm.etcd.api.RangeResponse;
|
||||
import com.ibm.etcd.client.EtcdClient;
|
||||
import com.ibm.etcd.client.kv.KvClient;
|
||||
import com.ibm.etcd.client.kv.WatchUpdate;
|
||||
import com.jd.platform.jlog.common.handler.JcProperties;
|
||||
@ -14,20 +13,14 @@ import com.jd.platform.jlog.core.ClientHandlerBuilder;
|
||||
import com.jd.platform.jlog.core.ConfigChangeEvent;
|
||||
import com.jd.platform.jlog.core.ConfigChangeListener;
|
||||
import com.jd.platform.jlog.core.ConfigChangeType;
|
||||
import io.netty.util.concurrent.DefaultThreadFactory;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.StringReader;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.LinkedBlockingQueue;
|
||||
import java.util.concurrent.ThreadPoolExecutor;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import static com.jd.platform.jlog.etcd.EtcdConfigurator.PROPERTIES;
|
||||
import static com.jd.platform.jlog.etcd.EtcdConfigurator.PROPERTIES_PATH;
|
||||
import static com.jd.platform.jlog.etcd.EtcdConfigurator.ROOT;
|
||||
|
||||
/**
|
||||
* @author tangbohu
|
||||
|
Loading…
Reference in New Issue
Block a user