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"; public static final String PREFIX = "spring.dynamic.thread-pool";
/** /**
* Username. * Username
*/ */
private String username; private String username;
/** /**
* Password. * Password
*/ */
private String password; private String password;
/** /**
* Server addr * Server address
*/ */
private String serverAddr; 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; import static cn.hippo4j.core.toolkit.IdentifyUtil.CLIENT_IDENTIFICATION_VALUE;
/** /**
* Dynamic threadPool discovery config. * Dynamic thread-pool discovery config.
*/ */
@AllArgsConstructor @AllArgsConstructor
public class DiscoveryConfiguration { 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.HttpAgent;
import cn.hippo4j.springboot.starter.remote.HttpScheduledHealthCheck; import cn.hippo4j.springboot.starter.remote.HttpScheduledHealthCheck;
import cn.hippo4j.springboot.starter.remote.ServerHealthCheck; 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.DynamicThreadPoolConfigService;
import cn.hippo4j.springboot.starter.support.DynamicThreadPoolPostProcessor; import cn.hippo4j.springboot.starter.support.DynamicThreadPoolPostProcessor;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
@ -75,8 +76,7 @@ import org.springframework.core.env.ConfigurableEnvironment;
@ConditionalOnBean(MarkerConfiguration.Marker.class) @ConditionalOnBean(MarkerConfiguration.Marker.class)
@EnableConfigurationProperties(BootstrapProperties.class) @EnableConfigurationProperties(BootstrapProperties.class)
@ConditionalOnProperty(prefix = BootstrapProperties.PREFIX, value = "enable", matchIfMissing = true, havingValue = "true") @ConditionalOnProperty(prefix = BootstrapProperties.PREFIX, value = "enable", matchIfMissing = true, havingValue = "true")
@ImportAutoConfiguration({WebAdapterConfiguration.class, HttpClientConfiguration.class, NettyClientConfiguration.class, DiscoveryConfiguration.class, MessageConfiguration.class, @ImportAutoConfiguration({WebAdapterConfiguration.class, NettyClientConfiguration.class, DiscoveryConfiguration.class, MessageConfiguration.class, UtilAutoConfiguration.class})
UtilAutoConfiguration.class})
public class DynamicThreadPoolAutoConfiguration { public class DynamicThreadPoolAutoConfiguration {
private final BootstrapProperties properties; private final BootstrapProperties properties;
@ -210,4 +210,9 @@ public class DynamicThreadPoolAutoConfiguration {
public ThreadPoolNotifyAlarmHandler threadPoolNotifyAlarmHandler(Hippo4jSendMessageService hippo4jSendMessageService) { public ThreadPoolNotifyAlarmHandler threadPoolNotifyAlarmHandler(Hippo4jSendMessageService hippo4jSendMessageService) {
return new ThreadPoolNotifyAlarmHandler(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; public final String threadPoolId;
@Setter
private int taskId;
@Setter @Setter
private volatile boolean isInitializing = true; private volatile boolean isInitializing = true;
private volatile long localConfigLastModified;
private final CopyOnWriteArrayList<ManagerListenerWrapper> listeners; private final CopyOnWriteArrayList<ManagerListenerWrapper> listeners;
public CacheData(String tenantId, String itemId, String threadPoolId) { public CacheData(String tenantId, String itemId, String threadPoolId) {

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

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

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

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

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

Loading…
Cancel
Save