Code formatting and redundant code removal

pull/458/head
chen.ma 2 years ago
parent 7e2933f3dd
commit 39240a7112

@ -25,9 +25,6 @@ import org.springframework.boot.context.properties.ConfigurationProperties;
/**
* Bootstrap properties.
*
* @author chen.ma
* @date 2021/6/22 09:14
*/
@Slf4j
@Getter

@ -37,9 +37,6 @@ import static cn.hippo4j.core.toolkit.IdentifyUtil.CLIENT_IDENTIFICATION_VALUE;
/**
* Dynamic threadPool discovery config.
*
* @author chen.ma
* @date 2021/8/6 21:35
*/
@AllArgsConstructor
public class DiscoveryConfiguration {

@ -59,9 +59,6 @@ import org.springframework.core.env.ConfigurableEnvironment;
/**
* Dynamic thread-pool auto-configuration.
*
* @author chen.ma
* @date 2021/6/22 09:20
*/
@Configuration
@AllArgsConstructor

@ -32,9 +32,6 @@ import java.util.concurrent.TimeUnit;
/**
* Http client config.
*
* @author chen.ma
* @date 2021/6/10 13:28
*/
public class HttpClientConfiguration {

@ -25,9 +25,6 @@ import org.springframework.context.annotation.Bean;
/**
* Netty ClientCon figuration
*
* @author lk
* @date 2022/6/18
*/
@ConditionalOnProperty(prefix = BootstrapProperties.PREFIX, name = "report-type", matchIfMissing = false, havingValue = "netty")
public class NettyClientConfiguration {

@ -1,37 +0,0 @@
/*
* 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.springboot.starter.config.condition;
import cn.hippo4j.common.toolkit.StringUtil;
import cn.hippo4j.springboot.starter.config.BootstrapProperties;
import com.example.monitor.base.MonitorTypeEnum;
import org.springframework.context.annotation.Condition;
import org.springframework.context.annotation.ConditionContext;
import org.springframework.core.type.AnnotatedTypeMetadata;
/**
* Prometheus monitor condition.
*/
public class PrometheusMonitorCondition implements Condition {
@Override
public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) {
String collectType = context.getEnvironment().getProperty(BootstrapProperties.PREFIX + ".collect-type", "");
return StringUtil.isNotEmpty(collectType) && collectType.contains(MonitorTypeEnum.PROMETHEUS.name().toLowerCase()) ? true : false;
}
}

@ -33,11 +33,7 @@ import java.util.concurrent.ThreadPoolExecutor;
/**
* Base thread detail state handler.
*
* <p> The Java 8 implementation is temporarily provided,
* {@link ThreadDetailState} interface can be customized.
*
* @author chen.ma
* @date 2022/1/9 13:01
* <p> The Java 8 implementation is temporarily provided, {@link ThreadDetailState} interface can be customized.
*/
@Slf4j
public class BaseThreadDetailStateHandler implements ThreadDetailState {
@ -62,7 +58,6 @@ public class BaseThreadDetailStateHandler implements ThreadDetailState {
if (CollectionUtil.isEmpty(workers)) {
return resultThreadState;
}
for (Object worker : workers) {
Thread thread;
try {
@ -75,7 +70,6 @@ public class BaseThreadDetailStateHandler implements ThreadDetailState {
log.error("Reflection get worker thread exception. Worker :: {}", worker, ex);
continue;
}
long threadId = thread.getId();
String threadName = thread.getName();
String threadStatus = thread.getState().name();

@ -28,9 +28,6 @@ import java.util.concurrent.CopyOnWriteArrayList;
/**
* Cache data.
*
* @author chen.ma
* @date 2021/6/22 20:46
*/
@Slf4j
public class CacheData {
@ -66,7 +63,6 @@ public class CacheData {
if (null == listener) {
throw new IllegalArgumentException("Listener is null.");
}
ManagerListenerWrapper managerListenerWrap = new ManagerListenerWrapper(md5, listener);
if (listeners.addIfAbsent(managerListenerWrap)) {
log.info("Add listener status :: ok, thread pool id :: {}, listeners count :: {}", tpId, listeners.size());
@ -87,7 +83,6 @@ public class CacheData {
wrap.setLastCallMd5(md5);
listener.receiveConfigInfo(content);
};
try {
listener.getExecutor().execute(runnable);
} catch (Exception ex) {

@ -38,9 +38,6 @@ import static cn.hippo4j.common.constant.Constants.*;
/**
* Client worker.
*
* @author chen.ma
* @date 2021/6/20 18:34
*/
@Slf4j
public class ClientWorker {
@ -109,7 +106,6 @@ public class ClientWorker {
List<CacheData> cacheDataList = new ArrayList();
List<String> inInitializingCacheList = new ArrayList();
cacheMap.forEach((key, val) -> cacheDataList.add(val));
List<String> changedTpIds = checkUpdateDataIds(cacheDataList, inInitializingCacheList);
for (String groupKey : changedTpIds) {
String[] keys = groupKey.split(GROUP_KEY_DELIMITER_TRANSLATION);
@ -121,12 +117,10 @@ public class ClientWorker {
CacheData cacheData = cacheMap.get(tpId);
String poolContent = ContentUtil.getPoolContent(JSONUtil.parseObject(content, ThreadPoolParameterInfo.class));
cacheData.setContent(poolContent);
} catch (Exception ex) {
// ignore
log.error("Failed to get the latest thread pool configuration.", ex);
} catch (Exception ignored) {
log.error("Failed to get the latest thread pool configuration.", ignored);
}
}
for (CacheData cacheData : cacheDataList) {
if (!cacheData.isInitializing() || inInitializingCacheList
.contains(GroupKey.getKeyTenant(cacheData.tpId, cacheData.itemId, cacheData.tenantId))) {

@ -23,9 +23,6 @@ import org.springframework.boot.diagnostics.FailureAnalysis;
/**
* Config empty analyzer.
*
* @author chen.ma
* @date 2021/11/28 21:59
*/
public class ConfigEmptyAnalyzer extends AbstractFailureAnalyzer<ConfigEmptyException> {

@ -19,9 +19,6 @@ package cn.hippo4j.springboot.starter.core;
/**
* Config service.
*
* @author chen.ma
* @date 2021/6/21 21:49
*/
public interface ConfigService {

@ -17,7 +17,6 @@
package cn.hippo4j.springboot.starter.core;
import cn.hippo4j.adapter.base.ThreadPoolAdapter;
import cn.hippo4j.common.api.ClientCloseHookExecute;
import cn.hippo4j.common.config.ApplicationContextHolder;
import cn.hippo4j.common.constant.Constants;
@ -32,7 +31,6 @@ import cn.hutool.core.util.StrUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.DisposableBean;
import java.util.Map;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
@ -41,9 +39,6 @@ import static cn.hippo4j.common.constant.Constants.BASE_PATH;
/**
* Discovery client.
*
* @author chen.ma
* @date 2021/7/13 21:51
*/
@Slf4j
public class DiscoveryClient implements DisposableBean {

@ -21,9 +21,6 @@ import java.util.concurrent.Executor;
/**
* Listener.
*
* @author chen.ma
* @date 2021/6/22 20:20
*/
public interface Listener {

@ -45,9 +45,6 @@ import static cn.hippo4j.common.constant.ChangeThreadPoolConstants.CHANGE_THREAD
/**
* Thread pool dynamic refresh.
*
* @author chen.ma
* @date 2021/6/20 15:51
*/
@Slf4j
@AllArgsConstructor
@ -58,10 +55,8 @@ public class ServerThreadPoolDynamicRefresh implements ThreadPoolDynamicRefresh
@Override
public void dynamicRefresh(String content) {
ThreadPoolParameterInfo parameter = JSONUtil.parseObject(content, ThreadPoolParameterInfo.class);
String threadPoolId = parameter.getTpId();
ThreadPoolExecutor executor = GlobalThreadPoolManage.getExecutorService(threadPoolId).getExecutor();
refreshDynamicPool(parameter, executor);
}
@ -79,7 +74,6 @@ public class ServerThreadPoolDynamicRefresh implements ThreadPoolDynamicRefresh
int originalCapacity = executor.getQueue().remainingCapacity() + executor.getQueue().size();
long originalKeepAliveTime = executor.getKeepAliveTime(TimeUnit.SECONDS);
boolean originalAllowCoreThreadTimeOut = executor.allowsCoreThreadTimeOut();
Long originalExecuteTimeOut = null;
RejectedExecutionHandler rejectedExecutionHandler = executor.getRejectedExecutionHandler();
if (executor instanceof AbstractDynamicExecutorSupport) {
@ -99,7 +93,6 @@ public class ServerThreadPoolDynamicRefresh implements ThreadPoolDynamicRefresh
request.setBeforeRejectedName(originalRejected);
request.setBeforeExecuteTimeOut(originalExecuteTimeOut);
request.setThreadPoolId(threadPoolId);
changePoolInfo(executor, parameter);
ThreadPoolExecutor afterExecutor = GlobalThreadPoolManage.getExecutorService(threadPoolId).getExecutor();
request.setNowCorePoolSize(afterExecutor.getCorePoolSize());

@ -19,9 +19,6 @@ package cn.hippo4j.springboot.starter.core;
/**
* Shutdown execute exception.
*
* @author chen.ma
* @date 2021/12/9 21:48
*/
public class ShutdownExecuteException extends Exception {

@ -26,9 +26,6 @@ import java.util.Arrays;
/**
* Thread-pool config service.
*
* @author chen.ma
* @date 2021/6/21 21:50
*/
public class ThreadPoolConfigService implements ConfigService, ApplicationListener<ApplicationCompleteEvent> {

@ -23,9 +23,6 @@ import java.util.concurrent.Executor;
/**
* Thread-pool operation.
*
* @author chen.ma
* @date 2021/6/22 20:25
*/
public class ThreadPoolOperation {

@ -19,9 +19,6 @@ package cn.hippo4j.springboot.starter.core;
/**
* ThreadPool subscribe callback.
*
* @author chen.ma
* @date 2021/6/22 20:26
*/
public interface ThreadPoolSubscribeCallback {

@ -21,9 +21,6 @@ import org.springframework.context.ApplicationEvent;
/**
* Execute after the spring application context is successfully started.
*
* @author chen.ma
* @date 2021/12/25 21:19
*/
public class ApplicationCompleteEvent extends ApplicationEvent {

@ -25,9 +25,6 @@ import javax.annotation.Resource;
/**
* Application content post processor.
*
* @author chen.ma
* @date 2021/12/25 20:21
*/
public class ApplicationContentPostProcessor implements ApplicationListener<ApplicationReadyEvent> {

@ -1,56 +0,0 @@
/*
* 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.springboot.starter.event;
import cn.hippo4j.common.function.NoArgsConsumer;
import cn.hippo4j.core.executor.support.QueueTypeEnum;
import cn.hippo4j.core.executor.support.ThreadPoolBuilder;
import lombok.extern.slf4j.Slf4j;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.RejectedExecutionException;
import java.util.concurrent.ThreadPoolExecutor;
import static cn.hippo4j.common.constant.Constants.AVAILABLE_PROCESSORS;
/**
* 线.
*
* @author chen.ma
* @date 2021/11/8 23:44
*/
@Slf4j
public class MonitorEventExecutor {
private static final ExecutorService EVENT_EXECUTOR = ThreadPoolBuilder.builder()
.threadFactory("client.monitor.event.executor")
.corePoolSize(AVAILABLE_PROCESSORS)
.maxPoolNum(AVAILABLE_PROCESSORS)
.workQueue(QueueTypeEnum.LINKED_BLOCKING_QUEUE)
.capacity(4096)
.rejected(new ThreadPoolExecutor.AbortPolicy())
.build();
public static void publishEvent(NoArgsConsumer consumer) {
try {
EVENT_EXECUTOR.execute(consumer::accept);
} catch (RejectedExecutionException ex) {
log.error("Monitoring thread pool run events exceeded load.");
}
}
}

@ -53,11 +53,8 @@ import static cn.hippo4j.core.executor.manage.GlobalThreadPoolManage.getThreadPo
/**
* Dynamic thread pool collection and reporting event executor.
* <p>
* {@link BlockingQueue} Act as a buffer container, enabling a production-consumption model.
*
* @author chen.ma
* @date 2021/12/6 20:23
* <p> {@link BlockingQueue} Act as a buffer container, enabling a production-consumption model.
*/
@Slf4j
@RequiredArgsConstructor

@ -21,9 +21,6 @@ import cn.hippo4j.common.monitor.Message;
/**
* Collect thread-pool data.
*
* @author chen.ma
* @date 2021/12/7 20:11
*/
public interface Collector {

@ -35,9 +35,6 @@ import static cn.hippo4j.core.toolkit.IdentifyUtil.getThreadPoolIdentify;
/**
* Thread pool runtime data collection.
*
* @author chen.ma
* @date 2021/12/16 19:46
*/
@AllArgsConstructor
public class RunTimeInfoCollector extends AbstractThreadPoolRuntime implements Collector {

@ -21,9 +21,6 @@ import cn.hippo4j.common.monitor.Message;
/**
* Message sender.
*
* @author chen.ma
* @date 2021/12/7 20:49
*/
public interface MessageSender {

@ -29,9 +29,6 @@ import static cn.hippo4j.common.constant.Constants.MONITOR_PATH;
/**
* Http sender.
*
* @author chen.ma
* @date 2021/12/7 20:53
*/
@Slf4j
@AllArgsConstructor

@ -33,13 +33,9 @@ import io.netty.handler.codec.serialization.ObjectDecoder;
import io.netty.handler.codec.serialization.ObjectEncoder;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
/**
* Netty ConnectSender
*
* @author lk
* @date 2022/06/18
* Netty connect sender.
*/
@Slf4j
@AllArgsConstructor
@ -66,7 +62,6 @@ public class NettyConnectSender implements MessageSender {
pipeline.addLast(new SenderHandler(messageWrapper));
}
});
bootstrap.connect(serverNettyAgent.getNettyServerAddress(), serverNettyAgent.getNettyServerPort()).sync();
} catch (Exception e) {
log.error("netty send error ", e);

@ -24,10 +24,7 @@ import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
/**
* SenderHandler
*
* @author lk
* @date 2022/06/18
* Sender handler.
*/
@Slf4j
@AllArgsConstructor
@ -37,7 +34,6 @@ public class SenderHandler extends SimpleChannelInboundHandler<MessageWrapper> {
@Override
protected void channelRead0(ChannelHandlerContext ctx, MessageWrapper msg) throws Exception {
}
@Override

@ -42,9 +42,6 @@ import static cn.hippo4j.common.constant.Constants.BASE_PATH;
/**
* Server notify config builder.
*
* @author chen.ma
* @date 2022/2/24 19:57
*/
@Slf4j
@AllArgsConstructor

@ -36,9 +36,6 @@ import static cn.hippo4j.common.constant.Constants.HEALTH_CHECK_INTERVAL;
/**
* Abstract health check.
*
* @author chen.ma
* @date 2021/12/8 20:19
*/
@Slf4j
public abstract class AbstractHealthCheck implements ServerHealthCheck, InitializingBean, ApplicationListener<ApplicationCompleteEvent> {

@ -23,9 +23,6 @@ import java.util.Map;
/**
* Http agent.
*
* @author chen.ma
* @date 2021/6/23 20:45
*/
public interface HttpAgent {

@ -28,9 +28,6 @@ import static cn.hippo4j.common.constant.Constants.UP;
/**
* Server health check.
*
* @author chen.ma
* @date 2021/12/8 20:16
*/
@Slf4j
@AllArgsConstructor
@ -49,7 +46,6 @@ public class HttpScheduledHealthCheck extends AbstractHealthCheck {
} catch (Throwable ex) {
log.error("Failed to periodically check the health status of the server.", ex.getMessage());
}
return healthStatus;
}
}

@ -19,9 +19,6 @@ package cn.hippo4j.springboot.starter.remote;
/**
* Server health check.
*
* @author chen.ma
* @date 2021/12/8 20:08
*/
public interface ServerHealthCheck {

@ -34,9 +34,6 @@ import java.util.concurrent.TimeUnit;
/**
* Server http agent.
*
* @author chen.ma
* @date 2021/6/23 20:50
*/
public class ServerHttpAgent implements HttpAgent {

@ -27,9 +27,6 @@ import java.util.*;
/**
* Server list manager.
*
* @author chen.ma
* @date 2021/6/23 20:42
*/
@Slf4j
public class ServerListManager {

@ -22,10 +22,7 @@ import io.netty.channel.EventLoopGroup;
import io.netty.channel.nio.NioEventLoopGroup;
/**
* Server Netty Agent
*
* @author lk
* @date 2022/6/18
* Server netty agent.
*/
public class ServerNettyAgent {

@ -33,9 +33,6 @@ import java.util.concurrent.TimeUnit;
/**
* Security proxy.
*
* @author chen.ma
* @date 2021/12/20 20:19
*/
@Slf4j
public class SecurityProxy {
@ -74,8 +71,7 @@ public class SecurityProxy {
return true;
}
}
} catch (Throwable ignore) {
// ignore
} catch (Throwable ignored) {
}
return false;
}

@ -23,9 +23,6 @@ import org.springframework.core.env.PropertyResolver;
/**
* Cloud common id util.
*
* @author chen.ma
* @date 2021/8/6 21:02
*/
public class CloudCommonIdUtil {
@ -51,8 +48,7 @@ public class CloudCommonIdUtil {
return combineParts(hostname, SEPARATOR, appName);
}
public static String combineParts(String firstPart, String separator,
String secondPart) {
public static String combineParts(String firstPart, String separator, String secondPart) {
String combined = null;
if (firstPart != null && secondPart != null) {
combined = firstPart + separator + secondPart;

@ -30,9 +30,6 @@ import java.util.concurrent.TimeUnit;
/**
* HttpClient util.
*
* @author chen.ma
* @date 2021/6/10 13:30
*/
@Slf4j
public class HttpClientUtil {

@ -25,9 +25,6 @@ import lombok.Setter;
/**
* Manager listener wrapper.
*
* @author chen.ma
* @date 2021/6/22 17:47
*/
@Getter
@Setter

Loading…
Cancel
Save