diff --git a/rxlib-x/src/main/java/org/rx/jdbc/JdbcUtil.java b/rxlib-x/src/main/java/org/rx/jdbc/JdbcUtil.java index b40d912b..35e7a9bb 100644 --- a/rxlib-x/src/main/java/org/rx/jdbc/JdbcUtil.java +++ b/rxlib-x/src/main/java/org/rx/jdbc/JdbcUtil.java @@ -205,6 +205,16 @@ public static void print(ResultSet resultSet) { } } + @SneakyThrows + public static T executeScalar(ResultSet resultSet) { + try (ResultSet rs = resultSet) { + if (rs.next()) { + return (T) rs.getObject(1); + } + return null; + } + } + public static final BiFunc TO_CAMEL_COLUMN_MAPPING = p -> CaseFormat.LOWER_UNDERSCORE.to(CaseFormat.LOWER_CAMEL, p); public static List readAs(ResultSet resultSet, Type type) { diff --git a/rxlib-x/src/main/java/org/rx/spring/BeanRegister.java b/rxlib-x/src/main/java/org/rx/spring/BeanRegister.java index 1725bf7e..760a89b0 100644 --- a/rxlib-x/src/main/java/org/rx/spring/BeanRegister.java +++ b/rxlib-x/src/main/java/org/rx/spring/BeanRegister.java @@ -45,7 +45,7 @@ public RateLimiterAdapter httpRateLimiterAdapter(RedisCache rCache, Middle } String rk = "RateLimiter:" + clientIp; - RateLimiterAdapter adapter = IOC.weakMap(false) + RateLimiterAdapter adapter = IOC.weakMap(true) .computeIfAbsent(rk, k -> RedisUtil.wrapRateLimiter(new RedisRateLimiter(rCache, k, conf.getLimiterPermits()))); return adapter.tryAcquire(); }; diff --git a/rxlib/src/main/java/org/rx/Main.java b/rxlib/src/main/java/org/rx/Main.java index 3ad6340b..6c6b2de3 100644 --- a/rxlib/src/main/java/org/rx/Main.java +++ b/rxlib/src/main/java/org/rx/Main.java @@ -12,6 +12,7 @@ import org.rx.net.TransportFlags; import org.rx.net.dns.DnsClient; import org.rx.net.dns.DnsServer; +import org.rx.net.http.*; import org.rx.net.rpc.Remoting; import org.rx.net.rpc.RpcClientConfig; import org.rx.net.rpc.RpcServerConfig; @@ -31,6 +32,7 @@ import java.math.BigInteger; import java.net.InetAddress; import java.net.InetSocketAddress; +import java.net.Proxy; import java.util.Collections; import java.util.List; import java.util.Map; @@ -88,8 +90,8 @@ public static class RSSConf { public String udp2rawEndpoint; } - static RSSConf conf; static boolean udp2raw = false; + static RSSConf conf; @SneakyThrows static void launchClient(Map options, Integer port, Integer connectTimeout) { @@ -302,11 +304,36 @@ public void addWhiteList(InetAddress endpoint) { }); } - app.ddns(); + clientInit(); log.info("Server started.."); app.await(); } + static void clientInit() { + Tasks.schedulePeriod(() -> { + if (conf == null) { + log.warn("conf is null"); + } + + InetAddress wanIp = InetAddress.getByName(IPSearcher.DEFAULT.currentIp()); + for (String ddns : conf.ddnsDomains) { + List currentIps = DnsClient.inlandClient().resolveAll(ddns); + if (currentIps.contains(wanIp)) { + continue; + } + int i = ddns.indexOf("."); + String domain = ddns.substring(i + 1), name = ddns.substring(0, i); + log.info("ddns-{}.{}: {}->{}", name, domain, currentIps, wanIp); + AuthenticProxy p = conf.godaddyProxy != null + ? new AuthenticProxy(Proxy.Type.SOCKS, Sockets.parseEndpoint(conf.godaddyProxy)) + : null; + IPSearcher.godaddyDns(conf.getGodaddyKey(), domain, name, wanIp.getHostAddress(), p); + } + }, conf.ddnsSeconds * 1000L); + } + + static HttpServer httpServer; + static void launchServer(Map options, Integer port, Integer connectTimeout) { AuthenticEndpoint shadowUser = Reflects.convertQuietly(options.get("shadowUser"), AuthenticEndpoint.class); if (shadowUser == null) { @@ -330,34 +357,24 @@ static void launchServer(Map options, Integer port, Integer conn rpcConf.getTcpConfig().setTransportFlags(TransportFlags.FRONTEND_AES_COMBO.flags()); Main app = new Main(backSvr); Remoting.register(app, rpcConf); + serverInit(); app.await(); } - final SocksProxyServer proxyServer; - - void ddns() { -// Tasks.schedulePeriod(() -> { -// if (conf == null) { -// log.warn("conf is null"); -// } -// -// InetAddress wanIp = InetAddress.getByName(IPSearcher.DEFAULT.currentIp()); -// for (String ddns : conf.ddnsDomains) { -// List currentIps = DnsClient.inlandClient().resolveAll(ddns); -// if (currentIps.contains(wanIp)) { -// continue; -// } -// int i = ddns.indexOf("."); -// String domain = ddns.substring(i + 1), name = ddns.substring(0, i); -// log.info("ddns-{}.{}: {}->{}", name, domain, currentIps, wanIp); -// AuthenticProxy p = conf.godaddyProxy != null -// ? new AuthenticProxy(Proxy.Type.SOCKS, Sockets.parseEndpoint(conf.godaddyProxy)) -// : null; -// IPSearcher.godaddyDns(conf.getGodaddyKey(), domain, name, wanIp.getHostAddress(), p); -// } -// }, conf.ddnsSeconds * 1000L); + static void serverInit() { + httpServer = new HttpServer(8082, true).requestMapping("/hf", (request, response) -> { + String url = request.getQueryString().getFirst("fu"); + Integer tm = Reflects.convertQuietly(request.getQueryString().getFirst("tm"), Integer.class); + HttpClient client = new HttpClient(); + if (tm != null) { + client.withTimeoutMillis(tm); + } + response.jsonBody(client.get(url).toJson()); + }); } + final SocksProxyServer proxyServer; + @Override public void fakeEndpoint(BigInteger hash, String endpoint) { SocksSupport.fakeDict().putIfAbsent(hash, UnresolvedEndpoint.valueOf(endpoint)); diff --git a/rxlib/src/main/java/org/rx/bean/WeakIdentityMap.java b/rxlib/src/main/java/org/rx/bean/ConcurrentWeakMap.java similarity index 65% rename from rxlib/src/main/java/org/rx/bean/WeakIdentityMap.java rename to rxlib/src/main/java/org/rx/bean/ConcurrentWeakMap.java index e6708787..84a44cb3 100644 --- a/rxlib/src/main/java/org/rx/bean/WeakIdentityMap.java +++ b/rxlib/src/main/java/org/rx/bean/ConcurrentWeakMap.java @@ -1,5 +1,7 @@ package org.rx.bean; +import lombok.NonNull; + import java.lang.ref.Reference; import java.lang.ref.ReferenceQueue; import java.lang.ref.WeakReference; @@ -9,18 +11,25 @@ import java.util.concurrent.ConcurrentHashMap; import java.util.function.Function; -//ReferenceIdentityMap -public class WeakIdentityMap implements AbstractMap { - final Map, V> map; +//不要放值类型 +//ReferenceMap, ReferenceIdentityMap +public class ConcurrentWeakMap implements AbstractMap { final ReferenceQueue refQueue = new ReferenceQueue<>(); - transient MapView.EntrySetView, K, V> entrySet; + final Map, V> map; + final boolean identityReference; + transient MapView.EntrySetView, K, V> entrySet; - public WeakIdentityMap() { - this(16); + public ConcurrentWeakMap(boolean identityReference) { + this(identityReference, 16); } - public WeakIdentityMap(int initialCapacity) { + public ConcurrentWeakMap(boolean identityReference, int initialCapacity) { map = new ConcurrentHashMap<>(initialCapacity); + this.identityReference = identityReference; + } + + Reference toKeyReference(K key) { + return identityReference ? new IdentityWeakReference<>(key, refQueue) : new WeakReference<>(key, refQueue); } @Override @@ -30,43 +39,35 @@ public int size() { } @Override - public V get(Object key) { + public V get(@NonNull Object key) { expunge(); - Objects.requireNonNull(key, "key"); - WeakReference keyref = new IdentityWeakReference<>((K) key); - return map.get(keyref); + return map.get(toKeyReference((K) key)); } @Override - public V put(K key, V value) { + public V put(@NonNull K key, V value) { expunge(); - Objects.requireNonNull(key, "key"); - WeakReference keyref = new IdentityWeakReference<>(key, refQueue); - return map.put(keyref, value); + return map.put(toKeyReference(key), value); } @Override - public V remove(Object key) { + public V remove(@NonNull Object key) { expunge(); - Objects.requireNonNull(key, "key"); - WeakReference keyref = new IdentityWeakReference<>((K) key); - return map.remove(keyref); + return map.remove(toKeyReference((K) key)); } @Override public Set> entrySet() { expunge(); - MapView.EntrySetView, K, V> es; + MapView.EntrySetView, K, V> es; return (es = entrySet) != null ? es : (entrySet = new MapView.EntrySetView<>(map, Reference::get)); } @Override - public V computeIfAbsent(K key, Function mappingFunction) { + public V computeIfAbsent(@NonNull K key, Function mappingFunction) { expunge(); - Objects.requireNonNull(key, "key"); Objects.requireNonNull(mappingFunction, "mappingFunction"); - WeakReference keyref = new IdentityWeakReference<>(key, refQueue); - return map.computeIfAbsent(keyref, p -> mappingFunction.apply(key)); + return map.computeIfAbsent(toKeyReference(key), p -> mappingFunction.apply(key)); } // public Stream keysForValue(V value) { @@ -115,11 +116,10 @@ public boolean equals(Object o) { if (this == o) { return true; } - if (!(o instanceof WeakIdentityMap.IdentityWeakReference)) { + if (!(o instanceof IdentityWeakReference)) { return false; } - Object got = get(); - return got != null && got == ((IdentityWeakReference) o).get(); + return get() == ((IdentityWeakReference) o).get(); } @Override diff --git a/rxlib/src/main/java/org/rx/bean/DataTable.java b/rxlib/src/main/java/org/rx/bean/DataTable.java index 95238ed4..311ac4f6 100644 --- a/rxlib/src/main/java/org/rx/bean/DataTable.java +++ b/rxlib/src/main/java/org/rx/bean/DataTable.java @@ -1,6 +1,5 @@ package org.rx.bean; -import com.alibaba.fastjson2.JSONObject; import lombok.*; import lombok.extern.slf4j.Slf4j; import org.h2.expression.Alias; diff --git a/rxlib/src/main/java/org/rx/bean/Tuple.java b/rxlib/src/main/java/org/rx/bean/Tuple.java index 417e0bcc..0dda65c0 100644 --- a/rxlib/src/main/java/org/rx/bean/Tuple.java +++ b/rxlib/src/main/java/org/rx/bean/Tuple.java @@ -23,10 +23,10 @@ public static Tuple of(T1 t1, T2 t2) { return new Tuple<>(t1, t2); } + public static Map.Entry toMapEntry(T1 t1, T2 t2) { + return new AbstractMap.SimpleImmutableEntry<>(t1, t2); + } + public T1 left; public T2 right; - - public Map.Entry toMapEntry() { - return new AbstractMap.SimpleImmutableEntry<>(left, right); - } } diff --git a/rxlib/src/main/java/org/rx/core/CpuWatchman.java b/rxlib/src/main/java/org/rx/core/CpuWatchman.java index 2cf48eda..c3ce5ac7 100644 --- a/rxlib/src/main/java/org/rx/core/CpuWatchman.java +++ b/rxlib/src/main/java/org/rx/core/CpuWatchman.java @@ -159,7 +159,7 @@ static int decrSize(ThreadPoolExecutor pool) { return poolSize; } - final Map> holder = new WeakIdentityMap<>(8); + final Map> holder = new ConcurrentWeakMap<>(true, 8); private CpuWatchman() { timer.newTimeout(this, RxConfig.INSTANCE.threadPool.samplingPeriod, TimeUnit.MILLISECONDS); diff --git a/rxlib/src/main/java/org/rx/core/IOC.java b/rxlib/src/main/java/org/rx/core/IOC.java index 9ec62308..ca20393a 100644 --- a/rxlib/src/main/java/org/rx/core/IOC.java +++ b/rxlib/src/main/java/org/rx/core/IOC.java @@ -2,7 +2,10 @@ import lombok.NonNull; import lombok.SneakyThrows; -import org.rx.bean.WeakIdentityMap; +import org.apache.commons.collections4.map.AbstractReferenceMap; +import org.apache.commons.collections4.map.ReferenceIdentityMap; +import org.apache.commons.collections4.map.ReferenceMap; +import org.rx.bean.ConcurrentWeakMap; import org.rx.exception.InvalidException; import java.util.*; @@ -13,9 +16,9 @@ @SuppressWarnings(NON_UNCHECKED) public final class IOC { static final Map, Object> container = new ConcurrentHashMap<>(8); - static final Map WEAK_MAP = Collections.synchronizedMap(new WeakHashMap<>()); - //不要放值类型 - static final Map WEAK_IDENTITY_MAP = new WeakIdentityMap<>(); + // static final Map WEAK_KEY_MAP = Collections.synchronizedMap(new WeakHashMap<>()); + static final Map WEAK_KEY_MAP = new ConcurrentWeakMap<>(false); + static Map weakValMap, wKeyIdentityMap, wValIdentityMap; public static boolean isInit(Class type) { return container.containsKey(type); @@ -67,11 +70,32 @@ public static void unregister(Class type) { container.remove(type); } - public static Map weakMap(boolean identity) { - return identity ? WEAK_IDENTITY_MAP : WEAK_MAP; + public static Map weakMap(boolean weakValue) { + if (!weakValue) { + return WEAK_KEY_MAP; + } + synchronized (WEAK_KEY_MAP) { + if (weakValMap == null) { + weakValMap = Collections.synchronizedMap(new ReferenceMap<>(AbstractReferenceMap.ReferenceStrength.HARD, AbstractReferenceMap.ReferenceStrength.WEAK)); + } + return weakValMap; + } + } + + static Map weakMap(Object ref, boolean weakValue) { + return (Map) weakMap(weakValue).computeIfAbsent(ref, k -> new ConcurrentHashMap<>(4)); } - static Map weakMap(Object ref, boolean identity) { - return (Map) (identity ? WEAK_IDENTITY_MAP : WEAK_MAP).computeIfAbsent(ref, k -> new ConcurrentHashMap<>(4)); + public synchronized static Map weakIdentityMap(boolean weakValue) { + if (weakValue) { + if (wValIdentityMap == null) { + wValIdentityMap = Collections.synchronizedMap(new ReferenceIdentityMap<>(AbstractReferenceMap.ReferenceStrength.HARD, AbstractReferenceMap.ReferenceStrength.WEAK)); + } + return wValIdentityMap; + } + if (wKeyIdentityMap == null) { + wKeyIdentityMap = new ConcurrentWeakMap<>(true); + } + return wKeyIdentityMap; } } diff --git a/rxlib/src/main/java/org/rx/core/Locker.java b/rxlib/src/main/java/org/rx/core/Locker.java index 958a3e84..05eb076a 100644 --- a/rxlib/src/main/java/org/rx/core/Locker.java +++ b/rxlib/src/main/java/org/rx/core/Locker.java @@ -1,21 +1,21 @@ -package org.rx.core; - -import lombok.AccessLevel; -import lombok.NoArgsConstructor; -import org.rx.bean.WeakIdentityMap; - -import java.util.Map; -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.locks.ReentrantLock; - -@NoArgsConstructor(access = AccessLevel.PRIVATE) -public class Locker { - public static final Locker INSTANCE = new Locker(); - //key1: ref, key2: key - final Map> holder = new WeakIdentityMap<>(); - - public ReentrantLock getLock(Object ref, Object key) { - return holder.computeIfAbsent(ref, k -> new ConcurrentHashMap<>()) - .computeIfAbsent(key, k -> new ReentrantLock()); - } -} +//package org.rx.core; +// +//import lombok.AccessLevel; +//import lombok.NoArgsConstructor; +//import org.rx.bean.WeakIdentityMap; +// +//import java.util.Map; +//import java.util.concurrent.ConcurrentHashMap; +//import java.util.concurrent.locks.ReentrantLock; +// +//@NoArgsConstructor(access = AccessLevel.PRIVATE) +//public class Locker { +// public static final Locker INSTANCE = new Locker(); +// //key1: ref, key2: key +// final Map> holder = new WeakIdentityMap<>(); +// +// public ReentrantLock getLock(Object ref, Object key) { +// return holder.computeIfAbsent(ref, k -> new ConcurrentHashMap<>()) +// .computeIfAbsent(key, k -> new ReentrantLock()); +// } +//} diff --git a/rxlib/src/main/java/org/rx/core/Numbers.java b/rxlib/src/main/java/org/rx/core/Numbers.java index c72e0d79..16e184b3 100644 --- a/rxlib/src/main/java/org/rx/core/Numbers.java +++ b/rxlib/src/main/java/org/rx/core/Numbers.java @@ -1,7 +1,6 @@ package org.rx.core; import org.apache.commons.lang3.math.NumberUtils; -import org.rx.exception.InvalidException; import java.math.BigDecimal; diff --git a/rxlib/src/main/java/org/rx/core/ObjectChangeTracker.java b/rxlib/src/main/java/org/rx/core/ObjectChangeTracker.java index dedcc113..e052e5d6 100644 --- a/rxlib/src/main/java/org/rx/core/ObjectChangeTracker.java +++ b/rxlib/src/main/java/org/rx/core/ObjectChangeTracker.java @@ -3,7 +3,7 @@ import lombok.*; import lombok.extern.slf4j.Slf4j; import org.rx.annotation.Metadata; -import org.rx.bean.WeakIdentityMap; +import org.rx.bean.ConcurrentWeakMap; import org.rx.exception.InvalidException; import org.rx.exception.TraceHandler; import org.springframework.cglib.proxy.Enhancer; @@ -173,7 +173,7 @@ static Object getTarget(Object sourceObj) { //endregion public static final ObjectChangeTracker DEFAULT = new ObjectChangeTracker(); - final Map> sources = new WeakIdentityMap<>(); + final Map> sources = new ConcurrentWeakMap<>(true); final EventBus bus = EventBus.DEFAULT; public ObjectChangeTracker() { diff --git a/rxlib/src/main/java/org/rx/io/CompositeLock.java b/rxlib/src/main/java/org/rx/io/CompositeLock.java index 66e79e59..e7e8606f 100644 --- a/rxlib/src/main/java/org/rx/io/CompositeLock.java +++ b/rxlib/src/main/java/org/rx/io/CompositeLock.java @@ -32,7 +32,7 @@ enum Flags implements NEnum { private final FileStream owner; private final FlagsEnum flags; - // private final ConcurrentHashMap> rwLocks = new ConcurrentHashMap<>(); + //同一时间有锁就行 final Map rwLocks = Collections.synchronizedMap(new WeakHashMap<>()); @SneakyThrows diff --git a/rxlib/src/main/java/org/rx/net/NetEventWait.java b/rxlib/src/main/java/org/rx/net/NetEventWait.java index 1fbfbad4..9cadf645 100644 --- a/rxlib/src/main/java/org/rx/net/NetEventWait.java +++ b/rxlib/src/main/java/org/rx/net/NetEventWait.java @@ -9,7 +9,7 @@ import lombok.Setter; import lombok.extern.slf4j.Slf4j; import org.apache.commons.collections4.CollectionUtils; -import org.rx.bean.WeakIdentityMap; +import org.rx.bean.ConcurrentWeakMap; import org.rx.core.*; import org.rx.exception.TraceHandler; import org.rx.io.Bytes; @@ -88,7 +88,7 @@ public NetEventWait(@NonNull String group, @NonNull InetSocketAddress multicastE this.multicastEndpoint = multicastEndpoint; idString = group + "@" + Integer.toHexString(hashCode()); channel = channels.computeIfAbsent(multicastEndpoint, k -> (NioDatagramChannel) Sockets.udpBootstrap(MemoryMode.LOW, true, c -> { - c.attr(REF).set(Collections.newSetFromMap(new WeakIdentityMap<>())); + c.attr(REF).set(Collections.newSetFromMap(new ConcurrentWeakMap<>(true))); c.pipeline().addLast(Handler.DEFAULT); }) .bind(multicastEndpoint.getPort()).addListener((ChannelFutureListener) f -> { diff --git a/rxlib/src/main/java/org/rx/net/http/HttpClient.java b/rxlib/src/main/java/org/rx/net/http/HttpClient.java index fa1862fe..db03acd4 100644 --- a/rxlib/src/main/java/org/rx/net/http/HttpClient.java +++ b/rxlib/src/main/java/org/rx/net/http/HttpClient.java @@ -638,9 +638,9 @@ public RequestBody toBody() { } //todo get request body -// boolean isGet = Strings.equalsIgnoreCase(servletRequest.getMethod(), HttpMethod.GET.name()); -// ResponseContent resContent = new ResponseContent(getClient().newCall(createRequest(forwardUrl).method(servletRequest.getMethod(), isGet ? null : reqContent.toBody()).build()).execute()); - ResponseContent resContent = new ResponseContent(getClient().newCall(createRequest(forwardUrl).method(servletRequest.getMethod(), reqContent.toBody()).build()).execute()); + boolean isGet = Strings.equalsIgnoreCase(servletRequest.getMethod(), HttpMethod.GET.name()); + ResponseContent resContent = new ResponseContent(getClient().newCall(createRequest(forwardUrl).method(servletRequest.getMethod(), isGet ? null : reqContent.toBody()).build()).execute()); +// ResponseContent resContent = new ResponseContent(getClient().newCall(createRequest(forwardUrl).method(servletRequest.getMethod(), reqContent.toBody()).build()).execute()); resContent.cachingStream = (featureFlags & CACHING_STREAM_FLAG) == CACHING_STREAM_FLAG; servletResponse.setStatus(resContent.response.code()); for (Pair header : resContent.responseHeaders()) { diff --git a/rxlib/src/main/java/org/rx/spring/MxController.java b/rxlib/src/main/java/org/rx/spring/MxController.java index fa53c4ef..ebf3add9 100644 --- a/rxlib/src/main/java/org/rx/spring/MxController.java +++ b/rxlib/src/main/java/org/rx/spring/MxController.java @@ -15,6 +15,7 @@ import org.rx.io.IOStream; import org.rx.net.NetEventWait; import org.rx.net.Sockets; +import org.rx.net.http.HttpClient; import org.rx.net.socks.SocksContext; import org.rx.util.BeanMapFlag; import org.rx.util.BeanMapper; @@ -28,6 +29,7 @@ import javax.annotation.PostConstruct; import javax.servlet.ServletInputStream; import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; import java.lang.management.ManagementFactory; import java.lang.reflect.Method; import java.net.InetAddress; @@ -138,15 +140,23 @@ public Object health(HttpServletRequest request) { } } - // @PostMapping("directOffer") -// public void directOffer(String appName, String socksId, String endpoint, MultipartFile binary) { -// SendPack pack = new SendPack(appName, socksId, Sockets.parseEndpoint(endpoint)); -// pack.setBinary(binary); -// server.frontendOffer(pack); -// } -// + @RequestMapping("health/p") + public Object healthP(HttpServletRequest request, HttpServletResponse response) { + if ("1".equals(request.getParameter("mock"))) { + return 1; + } + String fu = request.getParameter("fu"); + Integer tm = Reflects.convertQuietly(request.getParameter("tm"), Integer.class); + HttpClient client = new HttpClient(); + if (tm != null) { + client.withTimeoutMillis(tm); + } + client.forward(request, response, fu); + return null; + } + // @SneakyThrows -// @PostMapping("directPoll") +// @PostMapping("directPoll/Offer") // public void directPoll(String appName, String socksId, String endpoint, HttpServletResponse response) { // ReceivePack pack = server.frontendPoll(new SendPack(appName, socksId, Sockets.parseEndpoint(endpoint))); // ServletOutputStream out = response.getOutputStream(); @@ -200,9 +210,7 @@ Map findTopUsage(Date begin, Date end) { return result; } - Map queryTraces(Date startTime, Date endTime, String level, String keyword, Boolean newest, - Boolean methodOccurMost, String methodNamePrefix, String metricsName, - Integer take) { + Map queryTraces(Date startTime, Date endTime, String level, String keyword, Boolean newest, Boolean methodOccurMost, String methodNamePrefix, String metricsName, Integer take) { Map result = new LinkedHashMap<>(3); ExceptionLevel el = null; if (!Strings.isBlank(level)) { @@ -275,9 +283,7 @@ Map svrState(HttpServletRequest request) { j.put("rxConfig", RxConfig.INSTANCE); j.put("requestHeaders", Linq.from(Collections.list(request.getHeaderNames())).select(p -> String.format("%s: %s", p, String.join("; ", Collections.list(request.getHeaders(p)))))); - j.putAll(queryTraces(null, null, null, null, null, - null, null, null, - take)); + j.putAll(queryTraces(null, null, null, null, null, null, null, null, take)); return j; } diff --git a/rxlib/src/main/java/org/rx/util/Validator.java b/rxlib/src/main/java/org/rx/util/Validator.java index fa460295..7b92a4da 100644 --- a/rxlib/src/main/java/org/rx/util/Validator.java +++ b/rxlib/src/main/java/org/rx/util/Validator.java @@ -134,4 +134,74 @@ public static void validateMethod(Method member, Object instance, Object[] param doThrow(violation); } } + +// void append(JSONObject j, Type type, Type[] typeArguments) { +// ParameterizedTypeImpl pt = as(type, ParameterizedTypeImpl.class); +// if (pt != null) { +// Type[] ats = ifNull(typeArguments, pt.getActualTypeArguments()); +// int atsOffset = 0; +// for (Field field : Reflects.getFieldMap(pt.getRawType()).values()) { +// if (field.getName().equals("serialVersionUID")) { +// continue; +// } +// ParameterizedTypeImpl gpt = as(field.getGenericType(), ParameterizedTypeImpl.class); +// if (gpt != null) { +// JSONObject n = new JSONObject(); +// if (Iterable.class.isAssignableFrom(gpt.getRawType())) { +// JSONArray arr = new JSONArray(); +// arr.add(n); +// j.put(field.getName(), arr); +// } else { +// j.put(field.getName(), n); +// } +// +// Type[] atas = gpt.getActualTypeArguments(); +// if (atas[0] instanceof TypeVariableImpl) { +// append(n, ats[atsOffset], Arrays.subarray(atas, atsOffset, atsOffset += atas.length)); +// } else { +// append(n, ats[atsOffset++], null); +// } +// continue; +// } +// +// j.put(field.getName(), getDesc(field)); +// } +// return; +// } +// +// Class clz = (Class) type; +// Type[] ats = typeArguments; +// int atsOffset = 0; +// for (Field field : Reflects.getFieldMap(clz).values()) { +// if (field.getName().equals("serialVersionUID")) { +// continue; +// } +// ParameterizedTypeImpl gpt = as(field.getGenericType(), ParameterizedTypeImpl.class); +// if (gpt != null) { +// JSONObject n = new JSONObject(); +// if (Iterable.class.isAssignableFrom(gpt.getRawType())) { +// JSONArray arr = new JSONArray(); +// arr.add(n); +// j.put(field.getName(), arr); +// } else { +// j.put(field.getName(), n); +// } +// +// Type[] atas = gpt.getActualTypeArguments(); +// if (atas[0] instanceof TypeVariableImpl && ats != null) { +// append(n, ats[atsOffset], Arrays.subarray(atas, atsOffset, atsOffset += atas.length)); +// } else { +// append(n, atas[0], null); +// } +// continue; +// } +// +// j.put(field.getName(), getDesc(field)); +// } +// } +// +// String getDesc(Field field) { +// ApiModelProperty attr = field.getAnnotation(ApiModelProperty.class); +// return field.getType().getSimpleName() + (attr == null ? "" : " " + attr.value()); +// } } diff --git a/rxlib/src/test/java/org/rx/util/TestUtil.java b/rxlib/src/test/java/org/rx/util/TestUtil.java index 16ca57d2..8a5dfdca 100644 --- a/rxlib/src/test/java/org/rx/util/TestUtil.java +++ b/rxlib/src/test/java/org/rx/util/TestUtil.java @@ -416,7 +416,7 @@ public static class UserDemo { @Test public void third() { - Map identityMap = new WeakIdentityMap<>(); + Map identityMap = new ConcurrentWeakMap<>(true); UserStruct k = new UserStruct(); identityMap.put(k, 1); k.age = 2;