Globally remove the Guava toolkit dependency (#759)

* Globally remove the Guava toolkit dependency

* update "Globally remove the Guava toolkit dependency"
pull/762/head
Lijx 3 years ago committed by GitHub
parent b5810ce296
commit 956bd20d6c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -22,12 +22,12 @@ import cn.hippo4j.adapter.base.ThreadPoolAdapterParameter;
import cn.hippo4j.adapter.base.ThreadPoolAdapterState;
import com.alibaba.dubbo.common.extension.ExtensionLoader;
import com.alibaba.dubbo.common.store.DataStore;
import com.google.common.collect.Maps;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.context.event.ApplicationStartedEvent;
import org.springframework.context.ApplicationListener;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ExecutorService;
@ -41,7 +41,7 @@ import static cn.hippo4j.common.constant.ChangeThreadPoolConstants.CHANGE_DELIMI
@Slf4j
public class AlibabaDubboThreadPoolAdapter implements ThreadPoolAdapter, ApplicationListener<ApplicationStartedEvent> {
private final Map<String, ThreadPoolExecutor> DUBBO_PROTOCOL_EXECUTOR = Maps.newHashMap();
private final Map<String, ThreadPoolExecutor> DUBBO_PROTOCOL_EXECUTOR = new HashMap<>();
@Override
public String mark() {

@ -18,10 +18,10 @@
package cn.hippo4j.adapter.base;
import cn.hippo4j.common.config.ApplicationContextHolder;
import com.google.common.collect.Maps;
import org.springframework.beans.factory.InitializingBean;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
/**
* Thread-pool adapter bean container.
@ -31,7 +31,7 @@ public class ThreadPoolAdapterBeanContainer implements InitializingBean {
/**
* Store three-party thread pool framework bean instances.
*/
public static final Map<String, ThreadPoolAdapter> THREAD_POOL_ADAPTER_BEAN_CONTAINER = Maps.newConcurrentMap();
public static final Map<String, ThreadPoolAdapter> THREAD_POOL_ADAPTER_BEAN_CONTAINER = new ConcurrentHashMap<>();
@Override
public void afterPropertiesSet() throws Exception {

@ -21,7 +21,6 @@ import cn.hippo4j.adapter.base.ThreadPoolAdapter;
import cn.hippo4j.adapter.base.ThreadPoolAdapterParameter;
import cn.hippo4j.adapter.base.ThreadPoolAdapterState;
import cn.hippo4j.common.toolkit.ReflectUtil;
import com.google.common.collect.Maps;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.common.Version;
import org.apache.dubbo.common.extension.ExtensionLoader;
@ -31,6 +30,7 @@ import org.springframework.boot.context.event.ApplicationStartedEvent;
import org.springframework.context.ApplicationListener;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentMap;
@ -45,7 +45,7 @@ import static cn.hippo4j.common.constant.ChangeThreadPoolConstants.CHANGE_DELIMI
@Slf4j
public class DubboThreadPoolAdapter implements ThreadPoolAdapter, ApplicationListener<ApplicationStartedEvent> {
private final Map<String, ThreadPoolExecutor> DUBBO_PROTOCOL_EXECUTOR = Maps.newHashMap();
private final Map<String, ThreadPoolExecutor> DUBBO_PROTOCOL_EXECUTOR = new HashMap<>();
@Override
public String mark() {

@ -20,8 +20,6 @@ package cn.hippo4j.adapter.hystrix;
import cn.hippo4j.adapter.base.*;
import cn.hippo4j.common.config.ApplicationContextHolder;
import cn.hippo4j.common.toolkit.CollectionUtil;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.netflix.hystrix.HystrixThreadPool;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.context.event.ApplicationStartedEvent;
@ -29,6 +27,7 @@ import org.springframework.context.ApplicationListener;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
@ -49,7 +48,7 @@ public class HystrixThreadPoolAdapter implements ThreadPoolAdapter, ApplicationL
private static final String THREAD_POOLS_FIELD = "threadPools";
private final Map<String, ThreadPoolExecutor> HYSTRIX_CONSUME_EXECUTOR = Maps.newHashMap();
private final Map<String, ThreadPoolExecutor> HYSTRIX_CONSUME_EXECUTOR = new HashMap<>();
private ThreadPoolAdapterScheduler threadPoolAdapterScheduler;
@ -112,7 +111,7 @@ public class HystrixThreadPoolAdapter implements ThreadPoolAdapter, ApplicationL
// Periodically refresh registration.
ThreadPoolAdapterRegisterAction threadPoolAdapterRegisterAction = ApplicationContextHolder.getBean(ThreadPoolAdapterRegisterAction.class);
Map<String, ? extends HystrixThreadPoolAdapter> beansOfType = ApplicationContextHolder.getBeansOfType(this.getClass());
Map<String, ThreadPoolAdapter> map = Maps.newHashMap(beansOfType);
Map<String, ThreadPoolAdapter> map = new HashMap<>(beansOfType);
ThreadPoolAdapterRegisterTask threadPoolAdapterRegisterTask = new ThreadPoolAdapterRegisterTask(scheduler, taskIntervalSeconds, map, threadPoolAdapterRegisterAction);
scheduler.schedule(threadPoolAdapterRegisterTask, threadPoolAdapterScheduler.getTaskIntervalSeconds(), TimeUnit.SECONDS);
}
@ -207,7 +206,7 @@ public class HystrixThreadPoolAdapter implements ThreadPoolAdapter, ApplicationL
ThreadPoolAdapterRegisterAction threadPoolAdapterRegisterAction;
private List<ThreadPoolAdapterCacheConfig> cacheConfigList = Lists.newArrayList();
private List<ThreadPoolAdapterCacheConfig> cacheConfigList = new ArrayList<>();
public ThreadPoolAdapterRegisterTask(ScheduledExecutorService scheduler, int taskIntervalSeconds,
Map<String, ThreadPoolAdapter> threadPoolAdapterMap,

@ -17,7 +17,7 @@
package cn.hippo4j.adapter.hystrix;
import com.google.common.util.concurrent.ThreadFactoryBuilder;
import cn.hutool.core.thread.ThreadFactoryBuilder;
import lombok.extern.slf4j.Slf4j;
import java.util.concurrent.ScheduledExecutorService;
@ -36,7 +36,7 @@ public class ThreadPoolAdapterScheduler {
public ThreadPoolAdapterScheduler() {
scheduler = new ScheduledThreadPoolExecutor(2,
new ThreadFactoryBuilder()
.setNameFormat("threadPoolAdapter")
.setNamePrefix("threadPoolAdapter")
.setDaemon(true)
.build());
}

@ -21,17 +21,13 @@ import cn.hippo4j.adapter.base.ThreadPoolAdapter;
import cn.hippo4j.adapter.base.ThreadPoolAdapterParameter;
import cn.hippo4j.adapter.base.ThreadPoolAdapterState;
import cn.hippo4j.common.toolkit.ReflectUtil;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.connection.AbstractConnectionFactory;
import org.springframework.boot.context.event.ApplicationStartedEvent;
import org.springframework.context.ApplicationListener;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.*;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.ThreadPoolExecutor;
@ -50,7 +46,7 @@ public class RabbitMQThreadPoolAdapter implements ThreadPoolAdapter, Application
private final Map<String, AbstractConnectionFactory> abstractConnectionFactoryMap;
private final Map<String, ThreadPoolExecutor> RABBITMQ_THREAD_POOL_TASK_EXECUTOR = Maps.newHashMap();
private final Map<String, ThreadPoolExecutor> RABBITMQ_THREAD_POOL_TASK_EXECUTOR = new HashMap<>();
@Override
public String mark() {
@ -71,7 +67,7 @@ public class RabbitMQThreadPoolAdapter implements ThreadPoolAdapter, Application
@Override
public List<ThreadPoolAdapterState> getThreadPoolStates() {
List<ThreadPoolAdapterState> adapterStateList = Lists.newArrayList();
List<ThreadPoolAdapterState> adapterStateList = new ArrayList<>();
RABBITMQ_THREAD_POOL_TASK_EXECUTOR.forEach(
(key, val) -> adapterStateList.add(getThreadPoolState(key)));
return adapterStateList;

@ -22,14 +22,15 @@ import cn.hippo4j.adapter.base.ThreadPoolAdapterParameter;
import cn.hippo4j.adapter.base.ThreadPoolAdapterState;
import cn.hippo4j.common.config.ApplicationContextHolder;
import cn.hippo4j.common.toolkit.ReflectUtil;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.client.consumer.DefaultMQPushConsumer;
import org.apache.rocketmq.client.impl.consumer.ConsumeMessageService;
import org.apache.rocketmq.spring.support.DefaultRocketMQListenerContainer;
import org.springframework.boot.context.event.ApplicationStartedEvent;
import org.springframework.context.ApplicationListener;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ThreadPoolExecutor;
@ -42,7 +43,7 @@ import static cn.hippo4j.common.constant.ChangeThreadPoolConstants.CHANGE_DELIMI
@Slf4j
public class RocketMQThreadPoolAdapter implements ThreadPoolAdapter, ApplicationListener<ApplicationStartedEvent> {
private final Map<String, ThreadPoolExecutor> ROCKET_MQ_CONSUME_EXECUTOR = Maps.newHashMap();
private final Map<String, ThreadPoolExecutor> ROCKET_MQ_CONSUME_EXECUTOR = new HashMap<>();
@Override
public String mark() {
@ -65,7 +66,7 @@ public class RocketMQThreadPoolAdapter implements ThreadPoolAdapter, Application
@Override
public List<ThreadPoolAdapterState> getThreadPoolStates() {
List<ThreadPoolAdapterState> adapterStateList = Lists.newArrayList();
List<ThreadPoolAdapterState> adapterStateList = new ArrayList<>();
ROCKET_MQ_CONSUME_EXECUTOR.forEach(
(key, val) -> adapterStateList.add(getThreadPoolState(key)));
return adapterStateList;

@ -23,8 +23,6 @@ import cn.hippo4j.adapter.base.ThreadPoolAdapterState;
import cn.hippo4j.common.config.ApplicationContextHolder;
import cn.hippo4j.common.toolkit.CollectionUtil;
import cn.hippo4j.common.toolkit.ReflectUtil;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.listener.AbstractMessageListenerContainer;
import org.springframework.amqp.rabbit.listener.DirectMessageListenerContainer;
@ -36,10 +34,7 @@ import org.springframework.cloud.stream.binding.InputBindingLifecycle;
import org.springframework.context.ApplicationListener;
import org.springframework.integration.amqp.inbound.AmqpInboundChannelAdapter;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.*;
import static cn.hippo4j.common.constant.ChangeThreadPoolConstants.CHANGE_DELIMITER;
@ -49,7 +44,7 @@ import static cn.hippo4j.common.constant.ChangeThreadPoolConstants.CHANGE_DELIMI
@Slf4j
public class SpringCloudStreamRabbitMQThreadPoolAdapter implements ThreadPoolAdapter, ApplicationListener<ApplicationStartedEvent> {
private final Map<String, AbstractMessageListenerContainer> ROCKET_MQ_SPRING_CLOUD_STREAM_CONSUME_EXECUTOR = Maps.newHashMap();
private final Map<String, AbstractMessageListenerContainer> ROCKET_MQ_SPRING_CLOUD_STREAM_CONSUME_EXECUTOR = new HashMap<>();
@Override
public String mark() {
@ -84,7 +79,7 @@ public class SpringCloudStreamRabbitMQThreadPoolAdapter implements ThreadPoolAda
@Override
public List<ThreadPoolAdapterState> getThreadPoolStates() {
List<ThreadPoolAdapterState> adapterStateList = Lists.newArrayList();
List<ThreadPoolAdapterState> adapterStateList = new ArrayList<>();
ROCKET_MQ_SPRING_CLOUD_STREAM_CONSUME_EXECUTOR.forEach(
(key, val) -> adapterStateList.add(getThreadPoolState(key)));
return adapterStateList;

@ -25,8 +25,6 @@ import cn.hippo4j.common.toolkit.CollectionUtil;
import cn.hippo4j.common.toolkit.ReflectUtil;
import com.alibaba.cloud.stream.binder.rocketmq.consuming.RocketMQListenerBindingContainer;
import com.alibaba.cloud.stream.binder.rocketmq.integration.RocketMQInboundChannelAdapter;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.client.consumer.DefaultMQPushConsumer;
import org.apache.rocketmq.client.impl.consumer.ConsumeMessageConcurrentlyService;
@ -37,10 +35,7 @@ import org.springframework.cloud.stream.binder.DefaultBinding;
import org.springframework.cloud.stream.binding.InputBindingLifecycle;
import org.springframework.context.ApplicationListener;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.*;
import java.util.concurrent.ThreadPoolExecutor;
import static cn.hippo4j.common.constant.ChangeThreadPoolConstants.CHANGE_DELIMITER;
@ -51,7 +46,7 @@ import static cn.hippo4j.common.constant.ChangeThreadPoolConstants.CHANGE_DELIMI
@Slf4j
public class SpringCloudStreamRocketMQThreadPoolAdapter implements ThreadPoolAdapter, ApplicationListener<ApplicationStartedEvent> {
private final Map<String, ThreadPoolExecutor> ROCKET_MQ_SPRING_CLOUD_STREAM_CONSUME_EXECUTOR = Maps.newHashMap();
private final Map<String, ThreadPoolExecutor> ROCKET_MQ_SPRING_CLOUD_STREAM_CONSUME_EXECUTOR = new HashMap<>();
@Override
public String mark() {
@ -74,7 +69,7 @@ public class SpringCloudStreamRocketMQThreadPoolAdapter implements ThreadPoolAda
@Override
public List<ThreadPoolAdapterState> getThreadPoolStates() {
List<ThreadPoolAdapterState> adapterStateList = Lists.newArrayList();
List<ThreadPoolAdapterState> adapterStateList = new ArrayList<>();
ROCKET_MQ_SPRING_CLOUD_STREAM_CONSUME_EXECUTOR.forEach(
(key, val) -> adapterStateList.add(getThreadPoolState(key)));
return adapterStateList;

@ -61,11 +61,6 @@
<artifactId>spring-boot-starter-json</artifactId>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
</dependency>
<dependency>
<groupId>cn.hutool</groupId>
<artifactId>hutool-all</artifactId>
@ -76,6 +71,11 @@
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.github.ben-manes.caffeine</groupId>
<artifactId>caffeine</artifactId>
</dependency>
</dependencies>
<build>

@ -17,10 +17,7 @@
package cn.hippo4j.common.toolkit;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.*;
/**
* Collection util.
@ -123,4 +120,43 @@ public class CollectionUtil {
public static boolean isNotEmpty(Collection<?> collection) {
return !isEmpty(collection);
}
/**
* reference google guava
*
* @param elements
* @return
*/
@SafeVarargs
public static <E> ArrayList<E> newArrayList(E... elements) {
Objects.requireNonNull(elements);// for GWT
// Avoid integer overflow when a large array is passed in
int capacity = computeArrayListCapacity(elements.length);
ArrayList<E> list = new ArrayList<>(capacity);
Collections.addAll(list, elements);
return list;
}
private static int computeArrayListCapacity(int arraySize) {
checkNonnegative(arraySize);
// TODO(kevinb): Figure out the right behavior, and document it
return saturatedCast(5L + arraySize + (arraySize / 10));
}
private static void checkNonnegative(int value) {
if (value < 0) {
throw new IllegalArgumentException("arraySize cannot be negative but was: " + value);
}
}
private static int saturatedCast(long value) {
if (value > Integer.MAX_VALUE) {
return Integer.MAX_VALUE;
}
if (value < Integer.MIN_VALUE) {
return Integer.MIN_VALUE;
}
return (int) value;
}
}

@ -0,0 +1,90 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package cn.hippo4j.common.toolkit;
import java.io.IOException;
import java.util.Arrays;
import java.util.Iterator;
import java.util.Objects;
/**
* reference google guava
*
*/
public class Joiner {
private final String separator;
private Joiner(String separator) {
this.separator = Objects.requireNonNull(separator);
}
/** Returns a joiner which automatically places {@code separator} between consecutive elements. */
public static Joiner on(String separator) {
return new Joiner(separator);
}
/**
* Returns a string containing the string representation of each of {@code parts}, using the
* previously configured separator between each.
*
*/
public final String join(Object[] parts) {
return join(Arrays.asList(parts));
}
public final String join(Iterable<?> parts) {
return join(parts.iterator());
}
/**
* Returns a string containing the string representation of each of {@code parts}, using the
* previously configured separator between each.
*
*/
public final String join(Iterator<?> parts) {
return appendTo(new StringBuilder(), parts).toString();
}
public final StringBuilder appendTo(StringBuilder builder, Iterator<?> parts) {
try {
appendTo((Appendable) builder, parts);
} catch (IOException impossible) {
throw new AssertionError(impossible);
}
return builder;
}
public <A extends Appendable> A appendTo(A appendable, Iterator<?> parts) throws IOException {
Objects.requireNonNull(appendable);
if (parts.hasNext()) {
appendable.append(toString(parts.next()));
while (parts.hasNext()) {
appendable.append(separator);
appendable.append(toString(parts.next()));
}
}
return appendable;
}
CharSequence toString(Object part) {
Objects.requireNonNull(part);
return (part instanceof CharSequence) ? (CharSequence) part : part.toString();
}
}

@ -191,4 +191,5 @@ public class StringUtil {
}
return sb.toString();
}
}

@ -18,8 +18,8 @@
package cn.hippo4j.common.toolkit;
import cn.hippo4j.common.function.Matcher;
import com.google.common.base.Strings;
import org.junit.Test;
import org.springframework.util.StringUtils;
public class ArrayUtilTest {
@ -39,11 +39,11 @@ public class ArrayUtilTest {
public void assertFirstMatch() {
Matcher<String> matcher = (str) -> "1".equalsIgnoreCase(str);
String[] array = new String[0];
Assert.isTrue(Strings.isNullOrEmpty(ArrayUtil.firstMatch(matcher, array)));
Assert.isTrue(StringUtils.isEmpty(ArrayUtil.firstMatch(matcher, array)));
array = new String[]{"0"};
Assert.isTrue(Strings.isNullOrEmpty(ArrayUtil.firstMatch(matcher, array)));
Assert.isTrue(StringUtils.isEmpty(ArrayUtil.firstMatch(matcher, array)));
array = new String[]{"1"};
Assert.isTrue(!Strings.isNullOrEmpty(ArrayUtil.firstMatch(matcher, array)));
Assert.isTrue(!StringUtils.isEmpty(ArrayUtil.firstMatch(matcher, array)));
}
@Test

@ -17,10 +17,10 @@
package cn.hippo4j.common.toolkit;
import com.google.common.collect.Maps;
import org.assertj.core.util.Lists;
import org.junit.Test;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
@ -44,7 +44,7 @@ public class CollectionUtilTest {
Assert.isTrue(!CollectionUtil.isEmpty(list));
Map map = null;
Assert.isTrue(CollectionUtil.isEmpty(map));
map = Maps.newHashMap();
map = new HashMap<>();
Assert.isTrue(CollectionUtil.isEmpty(map));
map.put("key", "value");
Assert.isTrue(!CollectionUtil.isEmpty(map));
@ -66,7 +66,7 @@ public class CollectionUtilTest {
Assert.isTrue(CollectionUtil.isNotEmpty(list));
Map map = null;
Assert.isTrue(!CollectionUtil.isNotEmpty(map));
map = Maps.newHashMap();
map = new HashMap<>();
Assert.isTrue(!CollectionUtil.isNotEmpty(map));
map.put("key", "value");
Assert.isTrue(CollectionUtil.isNotEmpty(map));

@ -17,14 +17,8 @@
package cn.hippo4j.common.toolkit;
import org.checkerframework.checker.units.qual.A;
import org.junit.Test;
import java.util.Arrays;
import java.util.List;
import static org.junit.Assert.*;
public class GroupKeyTest {
@Test

@ -15,6 +15,12 @@
</properties>
<dependencies>
<dependency>
<groupId>cn.hippo4j</groupId>
<artifactId>hippo4j-common</artifactId>
<version>${revision}</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>

@ -20,10 +20,10 @@ package cn.hippo4j.config.monitor;
import cn.hippo4j.common.config.ApplicationContextHolder;
import cn.hippo4j.common.monitor.Message;
import cn.hippo4j.common.monitor.MessageTypeEnum;
import com.google.common.collect.Maps;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;
import java.util.HashMap;
import java.util.Map;
/**
@ -35,7 +35,7 @@ public class QueryMonitorExecuteChoose implements CommandLineRunner {
/**
* Storage monitoring data execution container.
*/
private Map<String, AbstractMonitorDataExecuteStrategy> monitorDataExecuteStrategyChooseMap = Maps.newHashMap();
private Map<String, AbstractMonitorDataExecuteStrategy> monitorDataExecuteStrategyChooseMap = new HashMap<>();
/**
* Choose by {@link cn.hippo4j.common.monitor.MessageTypeEnum}.

@ -24,6 +24,7 @@ import cn.hippo4j.common.design.observer.Observer;
import cn.hippo4j.common.design.observer.ObserverMessage;
import cn.hippo4j.common.toolkit.CollectionUtil;
import cn.hippo4j.common.toolkit.JSONUtil;
import cn.hippo4j.common.toolkit.Joiner;
import cn.hippo4j.common.toolkit.Md5Util;
import cn.hippo4j.config.event.LocalDataChangeEvent;
import cn.hippo4j.config.model.CacheItem;
@ -33,9 +34,6 @@ import cn.hippo4j.config.service.biz.ConfigService;
import cn.hippo4j.config.toolkit.MapUtil;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.StrUtil;
import com.google.common.base.Joiner;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import lombok.extern.slf4j.Slf4j;
import org.springframework.util.StringUtils;
@ -79,7 +77,7 @@ public class ConfigCacheService {
* @return
*/
private synchronized static String getContentMd5IsNullPut(String groupKey, String clientIdentify) {
Map<String, CacheItem> cacheItemMap = Optional.ofNullable(CLIENT_CONFIG_CACHE.get(groupKey)).orElse(Maps.newHashMap());
Map<String, CacheItem> cacheItemMap = Optional.ofNullable(CLIENT_CONFIG_CACHE.get(groupKey)).orElse(new HashMap<>());
CacheItem cacheItem = null;
if (CollUtil.isNotEmpty(cacheItemMap) && (cacheItem = cacheItemMap.get(clientIdentify)) != null) {
return cacheItem.md5;
@ -129,7 +127,7 @@ public class ConfigCacheService {
return item;
}
CacheItem tmp = new CacheItem(groupKey);
Map<String, CacheItem> cacheItemMap = Maps.newHashMap();
Map<String, CacheItem> cacheItemMap = new HashMap<>();
cacheItemMap.put(ip, tmp);
CLIENT_CONFIG_CACHE.putIfAbsent(groupKey, cacheItemMap);
return tmp;
@ -137,7 +135,7 @@ public class ConfigCacheService {
public static Map<String, CacheItem> getContent(String identification) {
List<String> identificationList = MapUtil.parseMapForFilter(CLIENT_CONFIG_CACHE, identification);
Map<String, CacheItem> returnStrCacheItemMap = Maps.newHashMap();
Map<String, CacheItem> returnStrCacheItemMap = new HashMap<>();
identificationList.forEach(each -> returnStrCacheItemMap.putAll(CLIENT_CONFIG_CACHE.get(each)));
return returnStrCacheItemMap;
}
@ -150,13 +148,13 @@ public class ConfigCacheService {
public static List<String> getIdentifyList(String tenantId, String itemId, String threadPoolId) {
List<String> identifyList = null;
String buildKey = Joiner.on(GROUP_KEY_DELIMITER).join(Lists.newArrayList(threadPoolId, itemId, tenantId));
String buildKey = Joiner.on(GROUP_KEY_DELIMITER).join(CollectionUtil.newArrayList(threadPoolId, itemId, tenantId));
List<String> keys = MapUtil.parseMapForFilter(CLIENT_CONFIG_CACHE, buildKey);
if (CollectionUtil.isNotEmpty(keys)) {
identifyList = new ArrayList(keys.size());
identifyList = new ArrayList<>(keys.size());
for (String each : keys) {
String[] keyArray = each.split(GROUP_KEY_DELIMITER_TRANSLATION);
if (keyArray != null && keyArray.length > 2) {
if (keyArray.length > 2) {
identifyList.add(keyArray[3]);
}
}

@ -17,8 +17,8 @@
package cn.hippo4j.config.service;
import com.google.common.cache.Cache;
import com.google.common.cache.CacheBuilder;
import com.github.benmanes.caffeine.cache.Cache;
import com.github.benmanes.caffeine.cache.Caffeine;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
@ -39,7 +39,7 @@ public class ConfigServletInner {
@NonNull
private final LongPollingService longPollingService;
private final Cache<String, Long> deWeightCache = CacheBuilder.newBuilder()
private final Cache<String, Long> deWeightCache = Caffeine.newBuilder()
.maximumSize(1024)
.build();

@ -17,6 +17,7 @@
package cn.hippo4j.config.service;
import cn.hippo4j.common.toolkit.CollectionUtil;
import cn.hippo4j.common.toolkit.JSONUtil;
import cn.hippo4j.common.toolkit.Md5Util;
import cn.hippo4j.common.web.base.Results;
@ -30,7 +31,6 @@ import cn.hippo4j.config.toolkit.Md5ConfigUtil;
import cn.hippo4j.config.toolkit.RequestUtil;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.StrUtil;
import com.google.common.collect.Lists;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
@ -117,7 +117,7 @@ public class LongPollingService {
for (Iterator<ClientLongPolling> iter = allSubs.iterator(); iter.hasNext();) {
ClientLongPolling clientSub = iter.next();
String identity = groupKey + GROUP_KEY_DELIMITER + identify;
List<String> parseMapForFilter = Lists.newArrayList(identity);
List<String> parseMapForFilter = CollectionUtil.newArrayList(identity);
if (StrUtil.isBlank(identify)) {
parseMapForFilter = MapUtil.parseMapForFilter(clientSub.clientMd5Map, groupKey);
}

@ -31,12 +31,11 @@ import cn.hippo4j.config.model.biz.adapter.ThreadPoolAdapterRespDTO;
import cn.hutool.core.text.StrBuilder;
import cn.hutool.http.HttpUtil;
import com.fasterxml.jackson.core.type.TypeReference;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.Collectors;
import static cn.hippo4j.common.constant.Constants.HTTP_EXECUTE_TIMEOUT;
@ -52,7 +51,7 @@ public class ThreadPoolAdapterService {
/**
* Map<mark, Map<tenantItem, Map<threadPoolKey, List<ThreadPoolAdapterState>>>>
*/
private static final Map<String, Map<String, Map<String, List<ThreadPoolAdapterState>>>> THREAD_POOL_ADAPTER_MAP = Maps.newConcurrentMap();
private static final Map<String, Map<String, Map<String, List<ThreadPoolAdapterState>>>> THREAD_POOL_ADAPTER_MAP = new ConcurrentHashMap<>();
static {
AbstractSubjectCenter.register(AbstractSubjectCenter.SubjectType.CLEAR_CONFIG_CACHE, new ClearThreadPoolAdapterCache());
@ -64,19 +63,19 @@ public class ThreadPoolAdapterService {
String mark = each.getMark();
Map<String, Map<String, List<ThreadPoolAdapterState>>> actual = THREAD_POOL_ADAPTER_MAP.get(mark);
if (CollectionUtil.isEmpty(actual)) {
actual = Maps.newHashMap();
actual = new HashMap<>();
THREAD_POOL_ADAPTER_MAP.put(mark, actual);
}
Map<String, List<ThreadPoolAdapterState>> tenantItemMap = actual.get(each.getTenantItemKey());
if (CollectionUtil.isEmpty(tenantItemMap)) {
tenantItemMap = Maps.newHashMap();
tenantItemMap = new HashMap<>();
actual.put(each.getTenantItemKey(), tenantItemMap);
}
List<ThreadPoolAdapterState> threadPoolAdapterStates = each.getThreadPoolAdapterStates();
for (ThreadPoolAdapterState adapterState : threadPoolAdapterStates) {
List<ThreadPoolAdapterState> adapterStateList = tenantItemMap.get(adapterState.getThreadPoolKey());
if (CollectionUtil.isEmpty(adapterStateList)) {
adapterStateList = Lists.newArrayList();
adapterStateList = new ArrayList<>();
tenantItemMap.put(adapterState.getThreadPoolKey(), adapterStateList);
}
Optional<ThreadPoolAdapterState> first = adapterStateList.stream().filter(state -> Objects.equals(state.getClientAddress(), each.getClientAddress())).findFirst();
@ -95,12 +94,12 @@ public class ThreadPoolAdapterService {
List<ThreadPoolAdapterState> actual = Optional.ofNullable(THREAD_POOL_ADAPTER_MAP.get(requestParameter.getMark()))
.map(each -> each.get(requestParameter.getTenant() + IDENTIFY_SLICER_SYMBOL + requestParameter.getItem()))
.map(each -> each.get(requestParameter.getThreadPoolKey()))
.orElse(Lists.newArrayList());
.orElse(new ArrayList<>());
List<String> addressList = actual.stream().map(ThreadPoolAdapterState::getClientAddress).collect(Collectors.toList());
List<ThreadPoolAdapterRespDTO> result = new ArrayList<>(addressList.size());
addressList.forEach(each -> {
String urlString = StrBuilder.create("http://", each, "/adapter/thread-pool/info").toString();
Map<String, Object> param = Maps.newHashMap();
Map<String, Object> param = new HashMap<>();
param.put("mark", requestParameter.getMark());
param.put("threadPoolKey", requestParameter.getThreadPoolKey());
try {

@ -27,7 +27,10 @@ import cn.hippo4j.common.web.exception.ServiceException;
import cn.hippo4j.config.event.LocalDataChangeEvent;
import cn.hippo4j.config.mapper.ConfigInfoMapper;
import cn.hippo4j.config.mapper.ConfigInstanceMapper;
import cn.hippo4j.config.model.*;
import cn.hippo4j.config.model.ConfigAllInfo;
import cn.hippo4j.config.model.ConfigInfoBase;
import cn.hippo4j.config.model.ConfigInstanceInfo;
import cn.hippo4j.config.model.LogRecordInfo;
import cn.hippo4j.config.model.biz.notify.NotifyReqDTO;
import cn.hippo4j.config.service.ConfigCacheService;
import cn.hippo4j.config.service.ConfigChangePublisher;
@ -38,7 +41,6 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.toolkit.SqlHelper;
import com.google.common.collect.Lists;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
@ -152,7 +154,8 @@ public class ConfigServiceImpl implements ConfigService {
}
DynamicThreadPoolRegisterServerNotifyParameter serverNotifyParameter = registerWrapper.getDynamicThreadPoolRegisterServerNotifyParameter();
if (serverNotifyParameter != null) {
ArrayList<String> notifyTypes = Lists.newArrayList("CONFIG", "ALARM");
ArrayList<String> notifyTypes = new ArrayList<>();
Collections.addAll(notifyTypes, "CONFIG", "ALARM");
notifyTypes.forEach(each -> {
NotifyReqDTO notifyReqDTO = new NotifyReqDTO();
notifyReqDTO.setType(each)

@ -36,12 +36,12 @@ import cn.hippo4j.config.toolkit.BeanUtil;
import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.google.common.collect.Lists;
import lombok.AllArgsConstructor;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.concurrent.atomic.AtomicBoolean;
@ -90,15 +90,15 @@ public class HisRunDataServiceImpl extends ServiceImpl<HisRunDataMapper, HisRunD
.between(HisRunDataInfo::getTimestamp, startTime, currentDate.getTime())
.orderByAsc(HisRunDataInfo::getTimestamp)
.list();
List<String> times = Lists.newArrayList();
List<Long> poolSizeList = Lists.newArrayList();
List<Long> activeSizeList = Lists.newArrayList();
List<Long> queueCapacityList = Lists.newArrayList();
List<Long> queueSizeList = Lists.newArrayList();
List<Long> completedTaskCountList = Lists.newArrayList();
List<Long> rejectCountList = Lists.newArrayList();
List<Long> queueRemainingCapacityList = Lists.newArrayList();
List<Long> currentLoadList = Lists.newArrayList();
List<String> times = new ArrayList<>();
List<Long> poolSizeList = new ArrayList<>();
List<Long> activeSizeList = new ArrayList<>();
List<Long> queueCapacityList = new ArrayList<>();
List<Long> queueSizeList = new ArrayList<>();
List<Long> completedTaskCountList = new ArrayList<>();
List<Long> rejectCountList = new ArrayList<>();
List<Long> queueRemainingCapacityList = new ArrayList<>();
List<Long> currentLoadList = new ArrayList<>();
long countTemp = 0L;
AtomicBoolean firstFlag = new AtomicBoolean(Boolean.TRUE);
for (HisRunDataInfo each : hisRunDataInfos) {
@ -146,7 +146,7 @@ public class HisRunDataServiceImpl extends ServiceImpl<HisRunDataMapper, HisRunD
@Transactional(rollbackFor = Exception.class)
public void save(Message message) {
List<RuntimeMessage> runtimeMessages = message.getMessages();
List<HisRunDataInfo> hisRunDataInfos = Lists.newArrayList();
List<HisRunDataInfo> hisRunDataInfos = new ArrayList<>();
runtimeMessages.forEach(each -> {
HisRunDataInfo hisRunDataInfo = BeanUtil.convert(each, HisRunDataInfo.class);
String[] parseKey = GroupKey.parseKey(each.getGroupKey());

@ -18,6 +18,7 @@
package cn.hippo4j.config.service.biz.impl;
import cn.hippo4j.common.enums.EnableEnum;
import cn.hippo4j.common.toolkit.BooleanUtil;
import cn.hippo4j.common.toolkit.GroupKey;
import cn.hippo4j.common.web.exception.ServiceException;
import cn.hippo4j.config.mapper.NotifyInfoMapper;
@ -29,17 +30,16 @@ import cn.hippo4j.config.model.biz.notify.NotifyRespDTO;
import cn.hippo4j.config.service.biz.NotifyService;
import cn.hippo4j.config.toolkit.BeanUtil;
import cn.hutool.core.collection.CollUtil;
import cn.hippo4j.common.toolkit.BooleanUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.google.common.collect.Lists;
import lombok.AllArgsConstructor;
import org.springframework.dao.DuplicateKeyException;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
@ -54,7 +54,7 @@ public class NotifyServiceImpl implements NotifyService {
@Override
public List<NotifyListRespDTO> listNotifyConfig(NotifyQueryReqDTO reqDTO) {
List<NotifyListRespDTO> notifyListRespList = Lists.newArrayList();
List<NotifyListRespDTO> notifyListRespList = new ArrayList<>();
reqDTO.getGroupKeys().forEach(each -> {
String[] parseKey = GroupKey.parseKey(each);
List<NotifyInfo> notifyInfos = listNotifyCommon("CONFIG", parseKey);
@ -93,7 +93,7 @@ public class NotifyServiceImpl implements NotifyService {
if (BooleanUtil.isTrue(requestParam.getAlarmType())) {
existNotify("ALARM", requestParam);
}
List<NotifyInfo> notifyInfos = Lists.newArrayList();
List<NotifyInfo> notifyInfos = new ArrayList<>();
if (BooleanUtil.isTrue(requestParam.getAlarmType())) {
NotifyInfo alarmNotifyInfo = BeanUtil.convert(requestParam, NotifyInfo.class);
alarmNotifyInfo.setType("ALARM");

@ -18,8 +18,8 @@
package cn.hippo4j.config.toolkit;
import cn.hutool.core.collection.CollUtil;
import com.google.common.collect.Lists;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Objects;
@ -53,7 +53,7 @@ public class MapUtil {
* @return
*/
public static List<String> parseMapForFilter(Map<String, ?> sourceMap, String filters) {
List<String> resultList = Lists.newArrayList();
List<String> resultList = new ArrayList<>();
if (CollUtil.isEmpty(sourceMap)) {
return resultList;
}

@ -19,9 +19,6 @@ package cn.hippo4j.config.toolkit;
import cn.hippo4j.common.toolkit.Assert;
import com.github.dozermapper.core.converters.ConversionException;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.google.common.collect.Sets;
import lombok.*;
import org.junit.Test;
@ -50,7 +47,7 @@ public class BeanUtilTest {
@Test
public void mapToBeanConvertTest() {
// 测试MapToBean
final HashMap<String, Object> map = Maps.newHashMap();
final HashMap<String, Object> map = new HashMap<>();
map.put("name", "Hippo4j");
map.put("age", 1);
map.put("address", "hippo4j.cn");
@ -64,7 +61,7 @@ public class BeanUtilTest {
@Test
public void ListToListConvertTest() {
final List<Person> list = Lists.newArrayList();
final List<Person> list = new ArrayList<>();
list.add(Person.builder().name("one").age(1).build());
list.add(Person.builder().name("two").age(2).build());
list.add(Person.builder().name("three").age(3).build());
@ -75,7 +72,7 @@ public class BeanUtilTest {
@Test
public void SetToSetConvertTest() {
final Set<Person> sets = Sets.newHashSet();
final Set<Person> sets = new HashSet<>();
sets.add(Person.builder().name("one").age(1).build());
sets.add(Person.builder().name("two").age(2).build());
sets.add(Person.builder().name("three").age(3).build());

@ -19,7 +19,6 @@ package cn.hippo4j.config.toolkit;
import cn.hippo4j.common.toolkit.Assert;
import cn.hutool.core.collection.CollectionUtil;
import com.google.common.collect.ImmutableMap;
import org.junit.Test;
import java.util.HashMap;
@ -35,14 +34,20 @@ public class MapUtilTest {
@Test
public void parseMapForFilterRetIsEmptyTest() {
Map<String, Object> map = ImmutableMap.of("abc", "123", "bcd", "456", "cde", "789");
HashMap<String, Object> map = new HashMap<>();
map.put("abc", "123");
map.put("bcd", "456");
map.put("cde", "789");
List<String> ret = MapUtil.parseMapForFilter(map, "x");
Assert.isTrue(CollectionUtil.isEmpty(ret));
}
@Test
public void parseMapForFilterRetIsNotEmptyTest() {
Map<String, Object> map = ImmutableMap.of("abc", "123", "bcd", "456", "cde", "789");
HashMap<String, Object> map = new HashMap<>();
map.put("abc", "123");
map.put("bcd", "456");
map.put("cde", "789");
List<String> ret = MapUtil.parseMapForFilter(map, "b");
Assert.isTrue(CollectionUtil.isNotEmpty(ret));
}

@ -24,6 +24,7 @@ import org.assertj.core.util.Lists;
import org.junit.Test;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Objects;
/**
@ -62,7 +63,7 @@ public class Md5ConfigUtilTest {
public void compareMd5ResultStringEmptyTest() {
String key = null;
try {
key = Md5ConfigUtil.compareMd5ResultString(Lists.newArrayList());
key = Md5ConfigUtil.compareMd5ResultString(new ArrayList<>());
} catch (IOException ignored) {
}

@ -42,11 +42,11 @@ import cn.hutool.core.text.StrBuilder;
import cn.hutool.core.util.StrUtil;
import cn.hutool.http.HttpUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.google.common.collect.Lists;
import lombok.AllArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
@ -131,9 +131,9 @@ public class ThreadPoolController {
List<Lease<InstanceInfo>> leases = baseInstanceRegistry.listInstance(itemId);
Lease<InstanceInfo> first = CollUtil.getFirst(leases);
if (first == null) {
return Results.success(Lists.newArrayList());
return Results.success(new ArrayList<>());
}
List<WebThreadPoolRespDTO> returnThreadPool = Lists.newArrayList();
List<WebThreadPoolRespDTO> returnThreadPool = new ArrayList<>();
for (Lease<InstanceInfo> each : leases) {
Result poolBaseState;
try {
@ -185,7 +185,7 @@ public class ThreadPoolController {
List<Lease<InstanceInfo>> leases = baseInstanceRegistry.listInstance(itemId);
Lease<InstanceInfo> first = CollUtil.getFirst(leases);
if (first == null) {
return Results.success(Lists.newArrayList());
return Results.success(new ArrayList<>());
}
InstanceInfo holder = first.getHolder();
String itemTenantKey = holder.getGroupKey();
@ -197,7 +197,7 @@ public class ThreadPoolController {
Map<String, String> clientBasePathMap = leases.stream().map(each -> each.getHolder())
.filter(each -> StringUtil.isNotBlank(each.getClientBasePath()))
.collect(Collectors.toMap(InstanceInfo::getIdentify, InstanceInfo::getClientBasePath));
List<ThreadPoolInstanceInfo> returnThreadPool = Lists.newArrayList();
List<ThreadPoolInstanceInfo> returnThreadPool = new ArrayList<>();
content.forEach((key, val) -> {
ThreadPoolInstanceInfo threadPoolInstanceInfo =
BeanUtil.convert(val.configAllInfo, ThreadPoolInstanceInfo.class);

@ -19,6 +19,7 @@ package cn.hippo4j.console.service.impl;
import cn.hippo4j.common.enums.DelEnum;
import cn.hippo4j.common.model.InstanceInfo;
import cn.hippo4j.common.toolkit.CollectionUtil;
import cn.hippo4j.common.toolkit.GroupKey;
import cn.hippo4j.config.mapper.ConfigInfoMapper;
import cn.hippo4j.config.mapper.HisRunDataMapper;
@ -36,7 +37,6 @@ import cn.hutool.core.date.DateUtil;
import cn.hutool.core.lang.Dict;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.google.common.collect.Lists;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;
@ -83,11 +83,11 @@ public class DashboardServiceImpl implements DashboardService {
Date currentDate = new Date();
DateTime startTime = DateUtil.offsetMinute(currentDate, -10);
List<HisRunDataMapper.ThreadPoolTaskRanking> threadPoolTaskRankings = hisRunDataMapper.queryThreadPoolMaxRanking(startTime.getTime(), currentDate.getTime());
List<Object> oneList = Lists.newArrayList();
List<Object> twoList = Lists.newArrayList();
List<Object> threeList = Lists.newArrayList();
List<Object> fourList = Lists.newArrayList();
ArrayList<List<Object>> lists = Lists.newArrayList(oneList, twoList, threeList, fourList);
List<Object> oneList = new ArrayList<>();
List<Object> twoList = new ArrayList<>();
List<Object> threeList = new ArrayList<>();
List<Object> fourList = new ArrayList<>();
ArrayList<List<Object>> lists = CollectionUtil.newArrayList(oneList, twoList, threeList, fourList);
for (int i = 0; i < threadPoolTaskRankings.size(); i++) {
List<Object> eachList = lists.get(i);
HisRunDataMapper.ThreadPoolTaskRanking taskRanking = threadPoolTaskRankings.get(i);
@ -101,7 +101,7 @@ public class DashboardServiceImpl implements DashboardService {
@Override
public TenantChart getTenantChart() {
List<Map<String, Object>> tenantChartList = Lists.newArrayList();
List<Map<String, Object>> tenantChartList = new ArrayList<>();
List<TenantInfo> tenantInfos = tenantInfoMapper.selectList(Wrappers.lambdaQuery(TenantInfo.class).eq(TenantInfo::getDelFlag, DelEnum.NORMAL.getIntCode()));
for (TenantInfo tenant : tenantInfos) {
int tenantThreadPoolNum = 0;
@ -118,7 +118,7 @@ public class DashboardServiceImpl implements DashboardService {
Dict dict = Dict.create().set("name", tenant.getTenantId()).set("value", tenantThreadPoolNum);
tenantChartList.add(dict);
}
List resultTenantChartList = tenantChartList.stream()
List<Map<String, Object>> resultTenantChartList = tenantChartList.stream()
.sorted((one, two) -> (int) two.get("value") - (int) one.get("value"))
.limit(5)
.collect(Collectors.toList());
@ -129,7 +129,7 @@ public class DashboardServiceImpl implements DashboardService {
public PieChartInfo getPieChart() {
LambdaQueryWrapper<ItemInfo> itemQueryWrapper = Wrappers.lambdaQuery(ItemInfo.class).eq(ItemInfo::getDelFlag, DelEnum.NORMAL.getIntCode()).select(ItemInfo::getItemId);
List<Object> itemNameList = itemInfoMapper.selectObjs(itemQueryWrapper);
List<Map<String, Object>> pieDataList = Lists.newArrayList();
List<Map<String, Object>> pieDataList = new ArrayList<>();
for (Object each : itemNameList) {
LambdaQueryWrapper<ConfigAllInfo> threadPoolQueryWrapper = Wrappers.lambdaQuery(ConfigAllInfo.class)
.eq(ConfigInfoBase::getItemId, each)
@ -141,7 +141,7 @@ public class DashboardServiceImpl implements DashboardService {
}
}
pieDataList.sort((one, two) -> (int) two.get("value") - (int) one.get("value"));
List<String> resultItemIds = Lists.newArrayList();
List<String> resultItemIds = new ArrayList<>();
List<Map<String, Object>> resultPieDataList = pieDataList.stream()
.limit(5)
.map(each -> {
@ -156,7 +156,7 @@ public class DashboardServiceImpl implements DashboardService {
public RankingChart getRankingChart() {
Date currentDate = new Date();
DateTime tenTime = DateUtil.offsetMinute(currentDate, -10);
List<RankingChart.RankingChartInfo> resultList = Lists.newArrayList();
List<RankingChart.RankingChartInfo> resultList = new ArrayList<>();
List<HisRunDataMapper.ThreadPoolTaskRanking> threadPoolTaskRankings = hisRunDataMapper.queryThreadPoolTaskSumRanking(tenTime.getTime(), currentDate.getTime());
threadPoolTaskRankings.forEach(each -> {
RankingChart.RankingChartInfo rankingChartInfo = new RankingChart.RankingChartInfo();

@ -22,8 +22,8 @@ import cn.hippo4j.common.model.ThreadPoolParameter;
import cn.hippo4j.common.model.register.DynamicThreadPoolRegisterWrapper;
import cn.hippo4j.core.executor.DynamicThreadPoolWrapper;
import cn.hippo4j.core.executor.support.service.DynamicThreadPoolService;
import com.google.common.collect.Lists;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Optional;
@ -123,7 +123,7 @@ public class GlobalThreadPoolManage {
* @return
*/
public static List<String> listThreadPoolId() {
return Lists.newArrayList(EXECUTOR_MAP.keySet());
return new ArrayList<>(EXECUTOR_MAP.keySet());
}
/**

@ -18,12 +18,12 @@
package cn.hippo4j.core.toolkit;
import cn.hippo4j.common.config.ApplicationContextHolder;
import cn.hippo4j.common.toolkit.CollectionUtil;
import cn.hippo4j.common.toolkit.Joiner;
import cn.hippo4j.common.toolkit.ThreadUtil;
import cn.hippo4j.core.toolkit.inet.InetUtils;
import cn.hutool.core.util.IdUtil;
import cn.hutool.core.util.StrUtil;
import com.google.common.base.Joiner;
import com.google.common.collect.Lists;
import org.springframework.core.env.ConfigurableEnvironment;
import java.util.ArrayList;
@ -89,7 +89,7 @@ public class IdentifyUtil {
* @return
*/
public static String getThreadPoolIdentify(String threadPoolId, String itemId, String namespace) {
ArrayList<String> params = Lists.newArrayList(threadPoolId, itemId, namespace, getIdentify());
ArrayList<String> params = CollectionUtil.newArrayList(threadPoolId, itemId, namespace, getIdentify());
return Joiner.on(GROUP_KEY_DELIMITER).join(params);
}
}

@ -29,11 +29,6 @@
<artifactId>hippo4j-common</artifactId>
<version>${revision}</version>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
</dependency>
</dependencies>
<build>

@ -20,8 +20,7 @@ package cn.hippo4j.discovery.core;
import cn.hippo4j.common.design.observer.AbstractSubjectCenter;
import cn.hippo4j.common.model.InstanceInfo;
import cn.hippo4j.common.model.InstanceInfo.InstanceStatus;
import com.google.common.collect.Lists;
import com.google.common.util.concurrent.ThreadFactoryBuilder;
import cn.hutool.core.thread.ThreadFactoryBuilder;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
@ -57,9 +56,9 @@ public class BaseInstanceRegistry implements InstanceRegistry<InstanceInfo> {
public List<Lease<InstanceInfo>> listInstance(String appName) {
Map<String, Lease<InstanceInfo>> appNameLeaseMap = registry.get(appName);
if (CollectionUtils.isEmpty(appNameLeaseMap)) {
return Lists.newArrayList();
return new ArrayList<>();
}
List<Lease<InstanceInfo>> appNameLeaseList = Lists.newArrayList();
List<Lease<InstanceInfo>> appNameLeaseList = new ArrayList<>();
appNameLeaseMap.values().forEach(each -> appNameLeaseList.add(each));
return appNameLeaseList;
}
@ -82,7 +81,7 @@ public class BaseInstanceRegistry implements InstanceRegistry<InstanceInfo> {
registrant = existingLease.getHolder();
}
}
Lease<InstanceInfo> lease = new Lease(registrant);
Lease<InstanceInfo> lease = new Lease<>(registrant);
if (existingLease != null) {
lease.setServiceUpTimestamp(existingLease.getServiceUpTimestamp());
}
@ -190,7 +189,7 @@ public class BaseInstanceRegistry implements InstanceRegistry<InstanceInfo> {
new ScheduledThreadPoolExecutor(
SCHEDULED_THREAD_CORE_NUM,
new ThreadFactoryBuilder()
.setNameFormat("registry-eviction")
.setNamePrefix("registry-eviction")
.setDaemon(true)
.build());

@ -39,11 +39,6 @@
<artifactId>commons-codec</artifactId>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
</dependency>
<dependency>
<groupId>cn.hutool</groupId>
<artifactId>hutool-all</artifactId>

@ -17,6 +17,8 @@
package cn.hippo4j.message.platform;
import cn.hippo4j.common.toolkit.CollectionUtil;
import cn.hippo4j.common.toolkit.FileUtil;
import cn.hippo4j.common.toolkit.Singleton;
import cn.hippo4j.common.toolkit.StringUtil;
import cn.hippo4j.message.dto.NotifyConfigDTO;
@ -25,11 +27,9 @@ import cn.hippo4j.message.platform.base.AbstractRobotSendMessageHandler;
import cn.hippo4j.message.platform.base.RobotMessageActualContent;
import cn.hippo4j.message.platform.base.RobotMessageExecuteDTO;
import cn.hippo4j.message.platform.constant.DingAlarmConstants;
import cn.hippo4j.common.toolkit.FileUtil;
import com.dingtalk.api.DefaultDingTalkClient;
import com.dingtalk.api.DingTalkClient;
import com.dingtalk.api.request.OapiRobotSendRequest;
import com.google.common.collect.Lists;
import com.taobao.api.ApiException;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.codec.binary.Base64;
@ -93,7 +93,7 @@ public class DingSendMessageHandler extends AbstractRobotSendMessageHandler {
markdown.setTitle(Objects.equals(notifyConfig.getType(), "CONFIG") ? DING_NOTICE_TITLE : DING_ALARM_TITLE);
markdown.setText(robotMessageExecuteDTO.getText());
OapiRobotSendRequest.At at = new OapiRobotSendRequest.At();
at.setAtMobiles(Lists.newArrayList(notifyConfig.getReceives().split(",")));
at.setAtMobiles(CollectionUtil.newArrayList(notifyConfig.getReceives().split(",")));
request.setAt(at);
request.setMarkdown(markdown);
try {

@ -17,6 +17,7 @@
package cn.hippo4j.message.platform.base;
import cn.hippo4j.common.toolkit.Joiner;
import cn.hippo4j.common.toolkit.StringUtil;
import cn.hippo4j.message.dto.NotifyConfigDTO;
import cn.hippo4j.message.enums.NotifyTypeEnum;
@ -25,7 +26,6 @@ import cn.hippo4j.message.request.ChangeParameterNotifyRequest;
import cn.hippo4j.message.service.SendMessageHandler;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.StrUtil;
import com.google.common.base.Joiner;
import java.util.Objects;

@ -21,11 +21,12 @@ import cn.hippo4j.common.constant.Constants;
import cn.hippo4j.message.dto.AlarmControlDTO;
import cn.hutool.core.util.IdUtil;
import cn.hutool.core.util.StrUtil;
import com.google.common.cache.Cache;
import com.google.common.cache.CacheBuilder;
import com.google.common.collect.Maps;
import com.github.benmanes.caffeine.cache.Cache;
import com.github.benmanes.caffeine.cache.Caffeine;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.ReentrantLock;
@ -34,9 +35,9 @@ import java.util.concurrent.locks.ReentrantLock;
*/
public class AlarmControlHandler {
private final Map<String, ReentrantLock> threadPoolLock = Maps.newHashMap();
private final Map<String, ReentrantLock> threadPoolLock = new HashMap<>();
private final Map<String, Cache<String, String>> threadPoolAlarmCache = Maps.newConcurrentMap();
private final Map<String, Cache<String, String>> threadPoolAlarmCache = new ConcurrentHashMap<>();
/**
* Control message push alarm frequency.
@ -77,7 +78,7 @@ public class AlarmControlHandler {
*/
public void initCacheAndLock(String threadPoolId, String platform, Integer interval) {
String threadPoolKey = StrUtil.builder(threadPoolId, Constants.GROUP_KEY_DELIMITER, platform).toString();
Cache<String, String> cache = CacheBuilder.newBuilder()
Cache<String, String> cache = Caffeine.newBuilder()
.expireAfterWrite(interval, TimeUnit.MINUTES)
.build();
threadPoolAlarmCache.put(threadPoolKey, cache);

@ -17,8 +17,8 @@
package cn.hippo4j.message.service;
import cn.hippo4j.message.api.NotifyConfigBuilder;
import cn.hippo4j.common.config.ApplicationContextHolder;
import cn.hippo4j.message.api.NotifyConfigBuilder;
import cn.hippo4j.message.dto.AlarmControlDTO;
import cn.hippo4j.message.dto.NotifyConfigDTO;
import cn.hippo4j.message.enums.NotifyTypeEnum;
@ -26,12 +26,12 @@ import cn.hippo4j.message.request.AlarmNotifyRequest;
import cn.hippo4j.message.request.ChangeParameterNotifyRequest;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.StrUtil;
import com.google.common.collect.Maps;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.CommandLineRunner;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@ -47,9 +47,9 @@ public class Hippo4jBaseSendMessageService implements Hippo4jSendMessageService,
private final AlarmControlHandler alarmControlHandler;
@Getter
public final Map<String, List<NotifyConfigDTO>> notifyConfigs = Maps.newHashMap();
public final Map<String, List<NotifyConfigDTO>> notifyConfigs = new HashMap<>();
private final Map<String, SendMessageHandler> sendMessageHandlers = Maps.newHashMap();
private final Map<String, SendMessageHandler> sendMessageHandlers = new HashMap<>();
@Override
public void sendAlarmMessage(NotifyTypeEnum typeEnum, AlarmNotifyRequest alarmNotifyRequest) {

@ -19,8 +19,6 @@ package cn.hippo4j.monitor.es;
import cn.hippo4j.common.config.ApplicationContextHolder;
import cn.hippo4j.common.toolkit.StringUtil;
import com.google.common.base.Throwables;
import com.google.common.collect.Lists;
import lombok.extern.slf4j.Slf4j;
import org.apache.http.HttpHost;
import org.apache.http.auth.AuthScope;
@ -30,6 +28,9 @@ import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestHighLevelClient;
import org.springframework.core.env.Environment;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.ArrayList;
import java.util.List;
/**
@ -65,7 +66,9 @@ public class EsClientHolder {
log.info("[ES RestHighLevelClient] success to connect eshost:{},scheme:{}", host, scheme);
return client;
} catch (Exception ex) {
log.error("[ES RestHighLevelClient] fail to connect es! cause:{}", Throwables.getStackTraceAsString(ex));
StringWriter stackTrace = new StringWriter();
ex.printStackTrace(new PrintWriter(stackTrace));
log.error("[ES RestHighLevelClient] fail to connect es! cause:{}", stackTrace);
}
return null;
}
@ -86,7 +89,7 @@ public class EsClientHolder {
private static List<HttpHost> parseHosts() {
String[] hostAndPorts = host.split(",");
List<HttpHost> hosts = Lists.newArrayList();
List<HttpHost> hosts = new ArrayList<>();
for (String hostAndPort : hostAndPorts) {
hostAndPort = hostAndPort.trim();
hosts.add(new HttpHost(hostAndPort.split(":")[0], Integer.parseInt(hostAndPort.split(":")[1]), scheme));

@ -19,17 +19,17 @@ package cn.hippo4j.monitor.micrometer;
import cn.hippo4j.common.config.ApplicationContextHolder;
import cn.hippo4j.common.model.ThreadPoolRunStateInfo;
import cn.hippo4j.common.toolkit.CollectionUtil;
import cn.hippo4j.core.executor.state.ThreadPoolRunStateHandler;
import cn.hutool.core.bean.BeanUtil;
import cn.hippo4j.monitor.base.AbstractDynamicThreadPoolMonitor;
import cn.hippo4j.monitor.base.MonitorTypeEnum;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import cn.hutool.core.bean.BeanUtil;
import io.micrometer.core.instrument.Metrics;
import io.micrometer.core.instrument.Tag;
import org.springframework.core.env.Environment;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
/**
* Micrometer monitor handler.
@ -42,7 +42,7 @@ public class MicrometerMonitorHandler extends AbstractDynamicThreadPoolMonitor {
private final static String APPLICATION_NAME_TAG = "application.name";
private final Map<String, ThreadPoolRunStateInfo> RUN_STATE_CACHE = Maps.newConcurrentMap();
private final Map<String, ThreadPoolRunStateInfo> RUN_STATE_CACHE = new ConcurrentHashMap<>();
public MicrometerMonitorHandler(ThreadPoolRunStateHandler threadPoolRunStateHandler) {
super(threadPoolRunStateHandler);
@ -58,7 +58,7 @@ public class MicrometerMonitorHandler extends AbstractDynamicThreadPoolMonitor {
}
Environment environment = ApplicationContextHolder.getInstance().getEnvironment();
String applicationName = environment.getProperty("spring.application.name", "application");
Iterable<Tag> tags = Lists.newArrayList(
Iterable<Tag> tags = CollectionUtil.newArrayList(
Tag.of(DYNAMIC_THREAD_POOL_ID_TAG, poolRunStateInfo.getTpId()),
Tag.of(APPLICATION_NAME_TAG, applicationName));
Metrics.gauge(metricName("current.load"), tags, poolRunStateInfo, ThreadPoolRunStateInfo::getSimpleCurrentLoad);

@ -18,7 +18,6 @@
package cn.hippo4j.server.init;
import cn.hippo4j.server.config.DataBaseProperties;
import com.google.common.base.Splitter;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.apache.ibatis.io.Resources;
@ -37,7 +36,6 @@ import java.io.InputStreamReader;
import java.io.Reader;
import java.nio.charset.StandardCharsets;
import java.sql.*;
import java.util.List;
import java.util.Objects;
/**
@ -105,7 +103,7 @@ public class LocalDataSourceLoader implements InstantiationAwareBeanPostProcesso
runner.setLogWriter(null);
runner.setAutoCommit(true);
Resources.setCharset(StandardCharsets.UTF_8);
List<String> initScripts = Splitter.on(";").splitToList(script);
String[] initScripts = StringUtils.split(script, ";");
for (String sqlScript : initScripts) {
if (sqlScript.startsWith(PRE_FIX)) {
String sqlFile = sqlScript.substring(PRE_FIX.length());

@ -18,19 +18,19 @@
package cn.hippo4j.config.springboot.starter.monitor;
import cn.hippo4j.common.config.ApplicationContextHolder;
import cn.hippo4j.common.spi.DynamicThreadPoolServiceLoader;
import cn.hippo4j.common.toolkit.StringUtil;
import cn.hippo4j.config.springboot.starter.config.BootstrapConfigProperties;
import cn.hippo4j.core.executor.manage.GlobalThreadPoolManage;
import cn.hippo4j.core.executor.support.ThreadFactoryBuilder;
import cn.hippo4j.common.spi.DynamicThreadPoolServiceLoader;
import cn.hippo4j.monitor.base.DynamicThreadPoolMonitor;
import cn.hippo4j.monitor.base.ThreadPoolMonitor;
import com.google.common.collect.Lists;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
@ -59,7 +59,7 @@ public class DynamicThreadPoolMonitorExecutor implements ApplicationRunner {
return;
}
log.info("Start monitoring the running status of dynamic thread pool.");
threadPoolMonitors = Lists.newArrayList();
threadPoolMonitors = new ArrayList<>();
collectExecutor = new ScheduledThreadPoolExecutor(
new Integer(1),
ThreadFactoryBuilder.builder().daemon(true).prefix("client.scheduled.collect.data").build());

@ -22,18 +22,14 @@ import cn.hippo4j.common.toolkit.StringUtil;
import cn.hippo4j.config.springboot.starter.config.BootstrapConfigProperties;
import cn.hippo4j.config.springboot.starter.config.ExecutorProperties;
import cn.hippo4j.config.springboot.starter.config.NotifyPlatformProperties;
import cn.hippo4j.message.service.AlarmControlHandler;
import cn.hippo4j.message.dto.NotifyConfigDTO;
import cn.hippo4j.message.api.NotifyConfigBuilder;
import cn.hippo4j.message.dto.NotifyConfigDTO;
import cn.hippo4j.message.service.AlarmControlHandler;
import cn.hutool.core.util.StrUtil;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.*;
import java.util.stream.Collectors;
/**
@ -49,7 +45,7 @@ public class CoreNotifyConfigBuilder implements NotifyConfigBuilder {
@Override
public Map<String, List<NotifyConfigDTO>> buildNotify() {
Map<String, List<NotifyConfigDTO>> resultMap = Maps.newHashMap();
Map<String, List<NotifyConfigDTO>> resultMap = new HashMap<>();
boolean globalAlarm = Optional.ofNullable(configProperties.getDefaultExecutor()).map(each -> each.getAlarm()).orElse(true);
List<ExecutorProperties> executors = configProperties.getExecutors();
if (CollectionUtil.isEmpty(executors)) {
@ -75,10 +71,10 @@ public class CoreNotifyConfigBuilder implements NotifyConfigBuilder {
* @return
*/
public Map<String, List<NotifyConfigDTO>> buildSingleNotifyConfig(ExecutorProperties executorProperties) {
Map<String, List<NotifyConfigDTO>> resultMap = Maps.newHashMap();
Map<String, List<NotifyConfigDTO>> resultMap = new HashMap<>();
String threadPoolId = executorProperties.getThreadPoolId();
String alarmBuildKey = threadPoolId + "+ALARM";
List<NotifyConfigDTO> alarmNotifyConfigs = Lists.newArrayList();
List<NotifyConfigDTO> alarmNotifyConfigs = new ArrayList<>();
List<NotifyPlatformProperties> notifyPlatforms = configProperties.getNotifyPlatforms();
for (NotifyPlatformProperties platformProperties : notifyPlatforms) {
NotifyConfigDTO notifyConfig = new NotifyConfigDTO();
@ -96,7 +92,7 @@ public class CoreNotifyConfigBuilder implements NotifyConfigBuilder {
}
resultMap.put(alarmBuildKey, alarmNotifyConfigs);
String changeBuildKey = threadPoolId + "+CONFIG";
List<NotifyConfigDTO> changeNotifyConfigs = Lists.newArrayList();
List<NotifyConfigDTO> changeNotifyConfigs = new ArrayList<>();
for (NotifyPlatformProperties platformProperties : notifyPlatforms) {
NotifyConfigDTO notifyConfig = new NotifyConfigDTO();
notifyConfig.setPlatform(platformProperties.getPlatform());

@ -17,20 +17,15 @@
package cn.hippo4j.config.springboot.starter.parser;
import com.google.common.collect.Lists;
import java.io.IOException;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.ServiceLoader;
import java.util.*;
/**
* Config parser handler.
*/
public class ConfigParserHandler {
private static final List<ConfigParser> PARSERS = Lists.newArrayList();
private static final List<ConfigParser> PARSERS = new ArrayList<>();
private ConfigParserHandler() {
ServiceLoader<ConfigParser> loader = ServiceLoader.load(ConfigParser.class);

@ -17,7 +17,7 @@
package cn.hippo4j.config.springboot.starter.parser;
import com.google.common.collect.Lists;
import cn.hippo4j.common.toolkit.CollectionUtil;
import java.io.IOException;
import java.io.StringReader;
@ -39,6 +39,6 @@ public class PropertiesConfigParser extends AbstractConfigParser {
@Override
public List<ConfigFileTypeEnum> getConfigFileTypes() {
return Lists.newArrayList(ConfigFileTypeEnum.PROPERTIES);
return CollectionUtil.newArrayList(ConfigFileTypeEnum.PROPERTIES);
}
}

@ -17,14 +17,12 @@
package cn.hippo4j.config.springboot.starter.parser;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import cn.hippo4j.common.toolkit.CollectionUtil;
import org.springframework.beans.factory.config.YamlPropertiesFactoryBean;
import org.springframework.core.io.ByteArrayResource;
import org.springframework.util.StringUtils;
import java.util.List;
import java.util.Map;
import java.util.*;
/**
* Yaml config parser.
@ -34,7 +32,7 @@ public class YamlConfigParser extends AbstractConfigParser {
@Override
public Map<Object, Object> doParse(String content) {
if (StringUtils.isEmpty(content)) {
return Maps.newHashMapWithExpectedSize(0);
return new HashMap<>(1);
}
YamlPropertiesFactoryBean yamlPropertiesFactoryBean = new YamlPropertiesFactoryBean();
yamlPropertiesFactoryBean.setResources(new ByteArrayResource(content.getBytes()));
@ -43,6 +41,6 @@ public class YamlConfigParser extends AbstractConfigParser {
@Override
public List<ConfigFileTypeEnum> getConfigFileTypes() {
return Lists.newArrayList(ConfigFileTypeEnum.YML, ConfigFileTypeEnum.YAML);
return CollectionUtil.newArrayList(ConfigFileTypeEnum.YML, ConfigFileTypeEnum.YAML);
}
}

@ -24,10 +24,10 @@ import com.ctrip.framework.apollo.ConfigFile;
import com.ctrip.framework.apollo.ConfigService;
import com.ctrip.framework.apollo.core.enums.ConfigFileFormat;
import com.ctrip.framework.apollo.model.ConfigChange;
import com.google.common.collect.Maps;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import java.util.HashMap;
import java.util.Map;
/**
@ -60,7 +60,7 @@ public class ApolloRefresherHandler extends AbstractConfigThreadPoolDynamicRefre
String namespace = this.namespace.replaceAll("." + bootstrapConfigProperties.getConfigFileType().getValue(), "");
ConfigFileFormat configFileFormat = ConfigFileFormat.fromString(bootstrapConfigProperties.getConfigFileType().getValue());
ConfigFile configFile = ConfigService.getConfigFile(namespace, configFileFormat);
Map<String, Object> newChangeValueMap = Maps.newHashMap();
Map<String, Object> newChangeValueMap = new HashMap<>();
configChangeEvent.changedKeys().stream().filter(each -> each.contains(BootstrapConfigProperties.PREFIX)).forEach(each -> {
ConfigChange change = configChangeEvent.getChange(each);
String newValue = change.getNewValue();

@ -25,13 +25,13 @@ import cn.hippo4j.config.springboot.starter.config.ExecutorProperties;
import cn.hippo4j.config.springboot.starter.config.NotifyPlatformProperties;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.bean.copier.CopyOptions;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import org.springframework.boot.context.properties.bind.Bindable;
import org.springframework.boot.context.properties.bind.Binder;
import org.springframework.boot.context.properties.source.ConfigurationPropertySource;
import org.springframework.boot.context.properties.source.MapConfigurationPropertySource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@ -74,7 +74,7 @@ public class BootstrapConfigPropertiesBinderAdapt {
BootstrapConfigProperties bindableConfigProperties;
try {
// filter
Map<Object, Object> targetMap = Maps.newHashMap();
Map<Object, Object> targetMap = new HashMap<>();
configInfo.forEach((key, val) -> {
boolean containFlag = key != null
&& StringUtil.isNotBlank((String) key)
@ -87,12 +87,12 @@ public class BootstrapConfigPropertiesBinderAdapt {
}
});
// convert
List<ExecutorProperties> executorPropertiesList = Lists.newArrayList();
List<NotifyPlatformProperties> notifyPropertiesList = Lists.newArrayList();
List<ExecutorProperties> executorPropertiesList = new ArrayList<>();
List<NotifyPlatformProperties> notifyPropertiesList = new ArrayList<>();
for (int i = 0; i < Integer.MAX_VALUE; i++) {
Map<String, Object> executorSingleMap = Maps.newHashMap();
Map<String, Object> platformSingleMap = Maps.newHashMap();
Map<String, Object> notifySingleMap = Maps.newHashMap();
Map<String, Object> executorSingleMap = new HashMap<>();
Map<String, Object> platformSingleMap = new HashMap<>();
Map<String, Object> notifySingleMap = new HashMap<>();
for (Map.Entry entry : targetMap.entrySet()) {
String key = entry.getKey().toString();

@ -17,18 +17,17 @@
package cn.hippo4j.config.springboot.starter.refresher;
import java.util.Map;
import java.util.Objects;
import com.google.common.collect.Maps;
import com.tencent.polaris.configuration.api.core.ConfigFileService;
import com.tencent.polaris.configuration.api.core.ConfigKVFile;
import com.tencent.polaris.configuration.api.core.ConfigKVFileChangeListener;
import com.tencent.polaris.configuration.api.core.ConfigPropertyChangeInfo;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Value;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
/**
*@author : wh
*@date : 2022/10/1 15:24
@ -68,7 +67,7 @@ public class PolarisRefresherHandler extends AbstractConfigThreadPoolDynamicRefr
ConfigKVFile configFile = getConfigKVFile();
configFile.addChangeListener((ConfigKVFileChangeListener) event -> {
String content = configFile.getContent();
Map<String, Object> newChangeValueMap = Maps.newHashMap();
Map<String, Object> newChangeValueMap = new HashMap<>();
for (String key : event.changedKeys()) {
ConfigPropertyChangeInfo changeInfo = event.getChangeInfo(key);
newChangeValueMap.put(key, changeInfo.getNewValue());

@ -19,7 +19,6 @@ package cn.hippo4j.config.springboot.starter.refresher;
import cn.hippo4j.core.executor.manage.GlobalNotifyAlarmManage;
import cn.hippo4j.message.service.ThreadPoolNotifyAlarm;
import com.google.common.base.Charsets;
import lombok.extern.slf4j.Slf4j;
import org.apache.curator.framework.CuratorFramework;
import org.apache.curator.framework.CuratorFrameworkFactory;
@ -32,6 +31,7 @@ import org.apache.curator.retry.ExponentialBackoffRetry;
import org.apache.curator.utils.ZKPaths;
import org.apache.zookeeper.WatchedEvent;
import java.nio.charset.StandardCharsets;
import java.util.List;
import java.util.Map;
@ -121,7 +121,7 @@ public class ZookeeperRefresherHandler extends AbstractConfigThreadPoolDynamicRe
final GetDataBuilder data = curatorFramework.getData();
String value = "";
try {
value = new String(data.watched().forPath(n), Charsets.UTF_8);
value = new String(data.watched().forPath(n), StandardCharsets.UTF_8);
} catch (Exception ex) {
log.error("Load zookeeper node error", ex);
}

@ -21,7 +21,6 @@ import cn.hippo4j.common.executor.support.BlockingQueueTypeEnum;
import cn.hippo4j.common.executor.support.RejectedPolicyTypeEnum;
import cn.hippo4j.common.executor.support.ResizableCapacityLinkedBlockingQueue;
import cn.hippo4j.common.toolkit.CollectionUtil;
import cn.hippo4j.config.springboot.starter.config.AdapterExecutorProperties;
import cn.hippo4j.config.springboot.starter.config.BootstrapConfigProperties;
import cn.hippo4j.config.springboot.starter.config.ExecutorProperties;
import cn.hippo4j.config.springboot.starter.notify.CoreNotifyConfigBuilder;
@ -36,15 +35,11 @@ import cn.hippo4j.message.dto.NotifyConfigDTO;
import cn.hippo4j.message.request.ChangeParameterNotifyRequest;
import cn.hippo4j.message.service.Hippo4jBaseSendMessageService;
import cn.hippo4j.message.service.ThreadPoolNotifyAlarm;
import com.google.common.collect.Lists;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.core.annotation.Order;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.*;
import java.util.concurrent.RejectedExecutionHandler;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
@ -160,7 +155,7 @@ public class DynamicThreadPoolRefreshListener extends AbstractRefreshListener<Ex
private void checkNotifyConsistencyAndReplace(ExecutorProperties executorProperties) {
boolean checkNotifyConfig = false;
boolean checkNotifyAlarm = false;
List<String> changeKeys = Lists.newArrayList();
List<String> changeKeys = new ArrayList<>();
Map<String, List<NotifyConfigDTO>> newDynamicThreadPoolNotifyMap = coreNotifyConfigBuilder.buildSingleNotifyConfig(executorProperties);
Map<String, List<NotifyConfigDTO>> notifyConfigs = hippo4jBaseSendMessageService.getNotifyConfigs();
if (CollectionUtil.isNotEmpty(notifyConfigs)) {

@ -18,9 +18,8 @@
package cn.hippo4j.config.springboot.starter.support;
import cn.hippo4j.common.toolkit.CollectionUtil;
import cn.hippo4j.config.springboot.starter.config.BootstrapConfigProperties;
import cn.hippo4j.config.springboot.starter.config.AdapterExecutorProperties;
import com.google.common.collect.Maps;
import cn.hippo4j.config.springboot.starter.config.BootstrapConfigProperties;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.ApplicationArguments;
@ -28,6 +27,7 @@ import org.springframework.boot.ApplicationRunner;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import static cn.hippo4j.common.constant.Constants.IDENTIFY_SLICER_SYMBOL;
@ -40,7 +40,7 @@ public class DynamicThreadPoolAdapterRegister implements ApplicationRunner {
private final BootstrapConfigProperties bootstrapConfigProperties;
public static final Map<String, AdapterExecutorProperties> ADAPTER_EXECUTORS_MAP = Maps.newConcurrentMap();
public static final Map<String, AdapterExecutorProperties> ADAPTER_EXECUTORS_MAP = new ConcurrentHashMap<>();
@Override
public void run(ApplicationArguments args) throws Exception {

@ -18,16 +18,16 @@
package cn.hippo4j.config.springboot.starter.support;
import cn.hippo4j.config.springboot.starter.config.ExecutorProperties;
import com.google.common.collect.Maps;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
/**
* Global core thread-pool manage.
*/
public class GlobalCoreThreadPoolManage {
private static final Map<String, ExecutorProperties> EXECUTOR_PROPERTIES = Maps.newConcurrentMap();
private static final Map<String, ExecutorProperties> EXECUTOR_PROPERTIES = new ConcurrentHashMap<>();
/**
* Get properties.

@ -29,13 +29,13 @@ import cn.hippo4j.core.toolkit.inet.InetUtils;
import cn.hippo4j.springboot.starter.config.BootstrapProperties;
import cn.hippo4j.springboot.starter.remote.HttpAgent;
import cn.hippo4j.springboot.starter.toolkit.CloudCommonIdUtil;
import com.google.common.collect.Lists;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.core.env.ConfigurableEnvironment;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
@ -64,7 +64,7 @@ public class ThreadPoolAdapterRegister implements ApplicationRunner, ThreadPoolA
@Override
public List<ThreadPoolAdapterCacheConfig> getThreadPoolAdapterCacheConfigs(Map<String, ThreadPoolAdapter> threadPoolAdapterMap) {
List<ThreadPoolAdapterCacheConfig> adapterCacheConfigList = Lists.newArrayList();
List<ThreadPoolAdapterCacheConfig> adapterCacheConfigList = new ArrayList<>();
for (Map.Entry<String, ThreadPoolAdapter> threadPoolAdapterEntry : threadPoolAdapterMap.entrySet()) {
ThreadPoolAdapter threadPoolAdapter = threadPoolAdapterEntry.getValue();
List<ThreadPoolAdapterState> threadPoolStates = threadPoolAdapter.getThreadPoolStates();

@ -33,7 +33,6 @@ import cn.hippo4j.springboot.starter.monitor.collect.Collector;
import cn.hippo4j.springboot.starter.monitor.send.MessageSender;
import cn.hippo4j.springboot.starter.remote.ServerHealthCheck;
import cn.hutool.core.collection.CollUtil;
import com.google.common.collect.Lists;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import lombok.SneakyThrows;
@ -41,10 +40,7 @@ import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.DisposableBean;
import org.springframework.boot.CommandLineRunner;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.*;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.ScheduledThreadPoolExecutor;
@ -110,7 +106,7 @@ public class ReportingEventExecutor implements Runnable, CommandLineRunner, Disp
if (!properties.getCollect()) {
return;
}
threadPoolMonitors = Lists.newArrayList();
threadPoolMonitors = new ArrayList<>();
String collectType = Optional.ofNullable(StringUtil.emptyToNull(properties.getCollectType())).orElse(MonitorTypeEnum.SERVER.name().toLowerCase());
collectVesselExecutor = new ScheduledThreadPoolExecutor(
new Integer(collectType.split(",").length),

@ -22,13 +22,13 @@ import cn.hippo4j.common.monitor.AbstractMessage;
import cn.hippo4j.common.monitor.Message;
import cn.hippo4j.common.monitor.MessageTypeEnum;
import cn.hippo4j.common.monitor.RuntimeMessage;
import cn.hippo4j.springboot.starter.config.BootstrapProperties;
import cn.hippo4j.core.executor.manage.GlobalThreadPoolManage;
import cn.hippo4j.core.executor.state.AbstractThreadPoolRuntime;
import cn.hippo4j.springboot.starter.config.BootstrapProperties;
import cn.hutool.core.bean.BeanUtil;
import com.google.common.collect.Lists;
import lombok.AllArgsConstructor;
import java.util.ArrayList;
import java.util.List;
import static cn.hippo4j.core.toolkit.IdentifyUtil.getThreadPoolIdentify;
@ -44,7 +44,7 @@ public class RunTimeInfoCollector extends AbstractThreadPoolRuntime implements C
@Override
public Message collectMessage() {
AbstractMessage message = new RuntimeMessage();
List<Message> runtimeMessages = Lists.newArrayList();
List<Message> runtimeMessages = new ArrayList<>();
List<String> listThreadPoolId = GlobalThreadPoolManage.listThreadPoolId();
for (String each : listThreadPoolId) {
ThreadPoolRunStateInfo poolRunState = getPoolRunState(each);

@ -21,20 +21,20 @@ import cn.hippo4j.common.toolkit.GroupKey;
import cn.hippo4j.common.toolkit.JSONUtil;
import cn.hippo4j.common.web.base.Result;
import cn.hippo4j.core.executor.manage.GlobalThreadPoolManage;
import cn.hippo4j.message.service.AlarmControlHandler;
import cn.hippo4j.message.api.NotifyConfigBuilder;
import cn.hippo4j.message.dto.NotifyConfigDTO;
import cn.hippo4j.message.dto.ThreadPoolNotifyDTO;
import cn.hippo4j.message.api.NotifyConfigBuilder;
import cn.hippo4j.message.request.ThreadPoolNotifyRequest;
import cn.hippo4j.message.service.AlarmControlHandler;
import cn.hippo4j.springboot.starter.config.BootstrapProperties;
import cn.hippo4j.springboot.starter.remote.HttpAgent;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.StrUtil;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@ -58,14 +58,14 @@ public class ServerNotifyConfigBuilder implements NotifyConfigBuilder {
List<String> threadPoolIds = GlobalThreadPoolManage.listThreadPoolId();
if (CollUtil.isEmpty(threadPoolIds)) {
log.warn("The client does not have a dynamic thread pool instance configured.");
return Maps.newHashMap();
return new HashMap<>();
}
return getAndInitNotify(threadPoolIds);
}
public Map<String, List<NotifyConfigDTO>> getAndInitNotify(List<String> threadPoolIds) {
Map<String, List<NotifyConfigDTO>> resultMap = Maps.newHashMap();
List<String> groupKeys = Lists.newArrayList();
Map<String, List<NotifyConfigDTO>> resultMap = new HashMap<>();
List<String> groupKeys = new ArrayList<>();
threadPoolIds.forEach(each -> {
String groupKey = GroupKey.getKeyTenant(each, properties.getItemId(), properties.getNamespace());
groupKeys.add(groupKey);

@ -20,13 +20,13 @@ package cn.hippo4j.springboot.starter.remote;
import cn.hippo4j.common.config.ApplicationContextHolder;
import cn.hippo4j.common.constant.Constants;
import cn.hippo4j.common.web.base.Result;
import cn.hippo4j.core.executor.support.ThreadFactoryBuilder;
import cn.hippo4j.springboot.starter.config.BootstrapProperties;
import cn.hippo4j.springboot.starter.security.SecurityProxy;
import cn.hippo4j.springboot.starter.toolkit.HttpClientUtil;
import cn.hippo4j.core.executor.support.ThreadFactoryBuilder;
import cn.hutool.core.util.StrUtil;
import com.google.common.collect.Maps;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledThreadPoolExecutor;
@ -141,7 +141,7 @@ public class ServerHttpAgent implements HttpAgent {
@Deprecated
private String injectSecurityInfoByPath(String path) {
String resultPath = httpClientUtil.buildUrl(path, injectSecurityInfo(Maps.newHashMap()));
String resultPath = httpClientUtil.buildUrl(path, injectSecurityInfo(new HashMap<>()));
return resultPath;
}
}

@ -22,6 +22,7 @@ import cn.hippo4j.common.model.register.DynamicThreadPoolRegisterParameter;
import cn.hippo4j.common.model.register.DynamicThreadPoolRegisterWrapper;
import cn.hippo4j.common.toolkit.Assert;
import cn.hippo4j.common.toolkit.BooleanUtil;
import cn.hippo4j.common.toolkit.CollectionUtil;
import cn.hippo4j.common.toolkit.JSONUtil;
import cn.hippo4j.common.web.base.Result;
import cn.hippo4j.common.web.exception.ServiceException;
@ -38,8 +39,6 @@ import cn.hippo4j.springboot.starter.core.DynamicThreadPoolSubscribeConfig;
import cn.hippo4j.springboot.starter.event.ApplicationCompleteEvent;
import cn.hippo4j.springboot.starter.notify.ServerNotifyConfigBuilder;
import cn.hippo4j.springboot.starter.remote.HttpAgent;
import com.google.common.collect.Lists;
import cn.hippo4j.springboot.starter.remote.HttpAgent;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.ApplicationListener;
@ -117,7 +116,7 @@ public class DynamicThreadPoolConfigService extends AbstractDynamicThreadPoolSer
registerParameter.getActiveAlarm(),
registerParameter.getCapacityAlarm());
GlobalNotifyAlarmManage.put(registerParameter.getThreadPoolId(), threadPoolNotifyAlarm);
Map<String, List<NotifyConfigDTO>> builderNotify = notifyConfigBuilder.getAndInitNotify(Lists.newArrayList(registerParameter.getThreadPoolId()));
Map<String, List<NotifyConfigDTO>> builderNotify = notifyConfigBuilder.getAndInitNotify(CollectionUtil.newArrayList(registerParameter.getThreadPoolId()));
hippo4jBaseSendMessageService.putPlatform(builderNotify);
}

@ -29,6 +29,7 @@
<revision>1.4.2-SNAPSHOT</revision>
<!-- Tool -->
<dozer.version>6.5.0</dozer.version>
<caffeine.version>2.9.3</caffeine.version>
<guava.version>30.0-jre</guava.version>
<okhttp3.version>3.12.0</okhttp3.version>
<hutool-all.version>5.4.7</hutool-all.version>
@ -124,6 +125,12 @@
<artifactId>dozer-core</artifactId>
<version>${dozer.version}</version>
</dependency>
<dependency>
<groupId>com.github.ben-manes.caffeine</groupId>
<artifactId>caffeine</artifactId>
<version>${caffeine.version}</version>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>

Loading…
Cancel
Save