Code optimization (#847)

pull/848/head
马称 2 years ago committed by GitHub
parent 16542c8bc8
commit 4366f9fad1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -35,17 +35,17 @@ public class BootstrapProperties implements BootstrapPropertiesInterface {
public static final String PREFIX = "spring.dynamic.thread-pool";
/**
* Username.
* Username
*/
private String username;
/**
* Password.
* Password
*/
private String password;
/**
* Server addr
* Server address
*/
private String serverAddr;

@ -38,7 +38,7 @@ import static cn.hippo4j.common.constant.Constants.IDENTIFY_SLICER_SYMBOL;
import static cn.hippo4j.core.toolkit.IdentifyUtil.CLIENT_IDENTIFICATION_VALUE;
/**
* Dynamic threadPool discovery config.
* Dynamic thread-pool discovery config.
*/
@AllArgsConstructor
public class DiscoveryConfiguration {

@ -53,6 +53,7 @@ import cn.hippo4j.springboot.starter.notify.ServerNotifyConfigBuilder;
import cn.hippo4j.springboot.starter.remote.HttpAgent;
import cn.hippo4j.springboot.starter.remote.HttpScheduledHealthCheck;
import cn.hippo4j.springboot.starter.remote.ServerHealthCheck;
import cn.hippo4j.springboot.starter.remote.ServerHttpAgent;
import cn.hippo4j.springboot.starter.support.DynamicThreadPoolConfigService;
import cn.hippo4j.springboot.starter.support.DynamicThreadPoolPostProcessor;
import lombok.AllArgsConstructor;
@ -75,8 +76,7 @@ import org.springframework.core.env.ConfigurableEnvironment;
@ConditionalOnBean(MarkerConfiguration.Marker.class)
@EnableConfigurationProperties(BootstrapProperties.class)
@ConditionalOnProperty(prefix = BootstrapProperties.PREFIX, value = "enable", matchIfMissing = true, havingValue = "true")
@ImportAutoConfiguration({WebAdapterConfiguration.class, HttpClientConfiguration.class, NettyClientConfiguration.class, DiscoveryConfiguration.class, MessageConfiguration.class,
UtilAutoConfiguration.class})
@ImportAutoConfiguration({WebAdapterConfiguration.class, NettyClientConfiguration.class, DiscoveryConfiguration.class, MessageConfiguration.class, UtilAutoConfiguration.class})
public class DynamicThreadPoolAutoConfiguration {
private final BootstrapProperties properties;
@ -210,4 +210,9 @@ public class DynamicThreadPoolAutoConfiguration {
public ThreadPoolNotifyAlarmHandler threadPoolNotifyAlarmHandler(Hippo4jSendMessageService hippo4jSendMessageService) {
return new ThreadPoolNotifyAlarmHandler(hippo4jSendMessageService);
}
@Bean
public HttpAgent httpAgent(BootstrapProperties properties) {
return new ServerHttpAgent(properties);
}
}

@ -1,34 +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;
import cn.hippo4j.springboot.starter.remote.HttpAgent;
import cn.hippo4j.springboot.starter.remote.ServerHttpAgent;
import org.springframework.context.annotation.Bean;
/**
* Http client config.
*/
public class HttpClientConfiguration {
@Bean
@SuppressWarnings("all")
public HttpAgent httpAgent(BootstrapProperties properties) {
return new ServerHttpAgent(properties);
}
}

@ -45,14 +45,9 @@ public class CacheData {
public final String threadPoolId;
@Setter
private int taskId;
@Setter
private volatile boolean isInitializing = true;
private volatile long localConfigLastModified;
private final CopyOnWriteArrayList<ManagerListenerWrapper> listeners;
public CacheData(String tenantId, String itemId, String threadPoolId) {

@ -245,8 +245,6 @@ public class ClientWorker {
} catch (Exception ex) {
log.error("Cache Data Error. Service Unavailable: {}", ex.getMessage());
}
int taskId = cacheMap.size() / CONFIG_LONG_POLL_TIMEOUT;
cacheData.setTaskId(taskId);
lastCacheData = cacheData;
}
return lastCacheData;

@ -27,14 +27,14 @@ public interface Listener {
/**
* Get executor.
*
* @return
* @return executor
*/
Executor getExecutor();
/**
* Receive config info.
*
* @param configInfo
* @param configInfo config info
*/
void receiveConfigInfo(String configInfo);
}

@ -25,7 +25,7 @@ public interface ThreadPoolSubscribeCallback {
/**
* Callback.
*
* @param config
* @param config config info
*/
void callback(String config);
}

@ -27,7 +27,7 @@ public interface Collector {
/**
* Collect message.
*
* @return
* @return message
*/
Message collectMessage();
}

@ -80,7 +80,6 @@ public class ServerNotifyConfigBuilder implements NotifyConfigBuilder {
String resultDataStr = JSONUtil.toJSONString(result.getData());
List<ThreadPoolNotifyDTO> resultData = JSONUtil.parseArray(resultDataStr, ThreadPoolNotifyDTO.class);
resultData.forEach(each -> resultMap.put(each.getNotifyKey(), each.getNotifyList()));
resultMap.forEach((key, val) -> val.stream().filter(each -> Objects.equals("ALARM", each.getType()))
.forEach(each -> alarmControlHandler.initCacheAndLock(each.getTpId(), each.getPlatform(), each.getInterval())));
}

Loading…
Cancel
Save