Optimize class naming and code format.

pull/161/head
chen.ma 3 years ago
parent f4613c250c
commit e983389faf

@ -8,7 +8,7 @@ import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
/** /**
* 线 * Common ThreadPool.
* *
* @author chen.ma * @author chen.ma
* @date 2021/6/16 22:35 * @date 2021/6/16 22:35

@ -6,7 +6,7 @@ import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.boot.context.properties.ConfigurationProperties;
/** /**
* 线 * Bootstrap Properties.
* *
* @author chen.ma * @author chen.ma
* @date 2021/6/22 09:14 * @date 2021/6/22 09:14
@ -14,28 +14,29 @@ import org.springframework.boot.context.properties.ConfigurationProperties;
@Slf4j @Slf4j
@Getter @Getter
@Setter @Setter
@ConfigurationProperties(prefix = DynamicThreadPoolProperties.PREFIX) @ConfigurationProperties(prefix = BootstrapProperties.PREFIX)
public class DynamicThreadPoolProperties { public class BootstrapProperties {
public static final String PREFIX = "spring.dynamic.thread-pool"; public static final String PREFIX = "spring.dynamic.thread-pool";
/** /**
* * serverAddr
*/ */
private String serverAddr; private String serverAddr;
/** /**
* ID * namespace
*/ */
private String namespace; private String namespace;
/** /**
* ID * itemId
*/ */
private String itemId; private String itemId;
/** /**
* banner * Enable banner
*/ */
private boolean banner = true; private boolean banner = true;
} }

@ -3,14 +3,13 @@ package com.github.dynamic.threadpool.starter.config;
import com.github.dynamic.threadpool.common.config.ApplicationContextHolder; import com.github.dynamic.threadpool.common.config.ApplicationContextHolder;
import com.github.dynamic.threadpool.starter.controller.PoolRunStateController; import com.github.dynamic.threadpool.starter.controller.PoolRunStateController;
import com.github.dynamic.threadpool.starter.core.ConfigService; import com.github.dynamic.threadpool.starter.core.ConfigService;
import com.github.dynamic.threadpool.starter.core.ThreadPoolBeanPostProcessor; import com.github.dynamic.threadpool.starter.core.DynamicThreadPoolPostProcessor;
import com.github.dynamic.threadpool.starter.core.ThreadPoolConfigService; import com.github.dynamic.threadpool.starter.core.ThreadPoolConfigService;
import com.github.dynamic.threadpool.starter.core.ThreadPoolOperation; import com.github.dynamic.threadpool.starter.core.ThreadPoolOperation;
import com.github.dynamic.threadpool.starter.enable.DynamicThreadPoolMarkerConfiguration; import com.github.dynamic.threadpool.starter.enable.MarkerConfiguration;
import com.github.dynamic.threadpool.starter.handler.ThreadPoolBannerHandler; import com.github.dynamic.threadpool.starter.handler.DynamicThreadPoolBannerHandler;
import com.github.dynamic.threadpool.starter.remote.HttpAgent; import com.github.dynamic.threadpool.starter.remote.HttpAgent;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.autoconfigure.ImportAutoConfiguration; import org.springframework.boot.autoconfigure.ImportAutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.boot.context.properties.EnableConfigurationProperties;
@ -18,24 +17,23 @@ import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
/** /**
* 线 * DynamicTp Auto Configuration.
* *
* @author chen.ma * @author chen.ma
* @date 2021/6/22 09:20 * @date 2021/6/22 09:20
*/ */
@Slf4j
@Configuration @Configuration
@AllArgsConstructor @AllArgsConstructor
@ImportAutoConfiguration(HttpClientConfig.class) @EnableConfigurationProperties(BootstrapProperties.class)
@EnableConfigurationProperties(DynamicThreadPoolProperties.class) @ConditionalOnBean(MarkerConfiguration.Marker.class)
@ConditionalOnBean(DynamicThreadPoolMarkerConfiguration.Marker.class) @ImportAutoConfiguration({HttpClientConfig.class, DiscoveryConfig.class})
public class DynamicThreadPoolAutoConfiguration { public class DynamicThreadPoolAutoConfiguration {
private final DynamicThreadPoolProperties properties; private final BootstrapProperties properties;
@Bean @Bean
public ThreadPoolBannerHandler threadPoolBannerHandler() { public DynamicThreadPoolBannerHandler threadPoolBannerHandler() {
return new ThreadPoolBannerHandler(properties); return new DynamicThreadPoolBannerHandler(properties);
} }
@Bean @Bean
@ -56,8 +54,8 @@ public class DynamicThreadPoolAutoConfiguration {
@Bean @Bean
@SuppressWarnings("all") @SuppressWarnings("all")
public ThreadPoolBeanPostProcessor threadPoolBeanPostProcessor(HttpAgent httpAgent, ThreadPoolOperation threadPoolOperation) { public DynamicThreadPoolPostProcessor threadPoolBeanPostProcessor(HttpAgent httpAgent, ThreadPoolOperation threadPoolOperation) {
return new ThreadPoolBeanPostProcessor(properties, httpAgent, threadPoolOperation); return new DynamicThreadPoolPostProcessor(properties, httpAgent, threadPoolOperation);
} }
@Bean @Bean
@ -66,3 +64,5 @@ public class DynamicThreadPoolAutoConfiguration {
} }
} }

@ -4,7 +4,6 @@ import com.github.dynamic.threadpool.starter.remote.HttpAgent;
import com.github.dynamic.threadpool.starter.remote.ServerHttpAgent; import com.github.dynamic.threadpool.starter.remote.ServerHttpAgent;
import com.github.dynamic.threadpool.starter.toolkit.HttpClientUtil; import com.github.dynamic.threadpool.starter.toolkit.HttpClientUtil;
import lombok.SneakyThrows; import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import okhttp3.OkHttpClient; import okhttp3.OkHttpClient;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
@ -20,14 +19,8 @@ import java.util.concurrent.TimeUnit;
* @author chen.ma * @author chen.ma
* @date 2021/6/10 13:28 * @date 2021/6/10 13:28
*/ */
@Slf4j
public class HttpClientConfig { public class HttpClientConfig {
/**
* OkHttpClient Bean
*
* @return
*/
@Bean @Bean
public OkHttpClient okHttpClient() { public OkHttpClient okHttpClient() {
OkHttpClient.Builder build = new OkHttpClient.Builder(); OkHttpClient.Builder build = new OkHttpClient.Builder();
@ -44,15 +37,10 @@ public class HttpClientConfig {
} }
@Bean @Bean
public HttpAgent httpAgent(DynamicThreadPoolProperties properties, HttpClientUtil httpClientUtil) { public HttpAgent httpAgent(BootstrapProperties properties, HttpClientUtil httpClientUtil) {
return new ServerHttpAgent(properties, httpClientUtil); return new ServerHttpAgent(properties, httpClientUtil);
} }
/**
* Https
*
* @param builder
*/
@SneakyThrows @SneakyThrows
private void supportHttps(OkHttpClient.Builder builder) { private void supportHttps(OkHttpClient.Builder builder) {
final TrustManager[] trustAllCerts = new TrustManager[]{new X509TrustManager() { final TrustManager[] trustAllCerts = new TrustManager[]{new X509TrustManager() {

@ -22,4 +22,5 @@ public class PoolRunStateController {
PoolRunStateInfo poolRunState = ThreadPoolRunStateHandler.getPoolRunState(tpId); PoolRunStateInfo poolRunState = ThreadPoolRunStateHandler.getPoolRunState(tpId);
return Results.success(poolRunState); return Results.success(poolRunState);
} }
} }

@ -91,4 +91,5 @@ public class CacheData {
public void setTaskId(Integer taskId) { public void setTaskId(Integer taskId) {
this.taskId = taskId; this.taskId = taskId;
} }
} }

@ -25,7 +25,7 @@ import static com.github.dynamic.threadpool.common.constant.Constants.LINE_SEPAR
import static com.github.dynamic.threadpool.common.constant.Constants.WORD_SEPARATOR; import static com.github.dynamic.threadpool.common.constant.Constants.WORD_SEPARATOR;
/** /**
* * Client Worker.
* *
* @author chen.ma * @author chen.ma
* @date 2021/6/20 18:34 * @date 2021/6/20 18:34
@ -76,9 +76,6 @@ public class ClientWorker {
}, 1L, 10L, TimeUnit.MILLISECONDS); }, 1L, 10L, TimeUnit.MILLISECONDS);
} }
/**
*
*/
public void checkConfigInfo() { public void checkConfigInfo() {
int listenerSize = cacheMap.size(); int listenerSize = cacheMap.size();
double perTaskConfigSize = 3000D; double perTaskConfigSize = 3000D;
@ -92,9 +89,6 @@ public class ClientWorker {
} }
} }
/**
*
*/
class LongPollingRunnable implements Runnable { class LongPollingRunnable implements Runnable {
@SneakyThrows @SneakyThrows
@ -151,12 +145,6 @@ public class ClientWorker {
} }
} }
/**
*
*
* @param cacheDataList
* @return
*/
private List<String> checkUpdateDataIds(List<CacheData> cacheDataList) { private List<String> checkUpdateDataIds(List<CacheData> cacheDataList) {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
for (CacheData cacheData : cacheDataList) { for (CacheData cacheData : cacheDataList) {
@ -169,12 +157,6 @@ public class ClientWorker {
return checkUpdateTpIds(sb.toString()); return checkUpdateTpIds(sb.toString());
} }
/**
* 线 ID
*
* @param probeUpdateString
* @return
*/
public List<String> checkUpdateTpIds(String probeUpdateString) { public List<String> checkUpdateTpIds(String probeUpdateString) {
Map<String, String> params = new HashMap(2); Map<String, String> params = new HashMap(2);
params.put(Constants.PROBE_MODIFY_REQUEST, probeUpdateString); params.put(Constants.PROBE_MODIFY_REQUEST, probeUpdateString);
@ -204,15 +186,6 @@ public class ClientWorker {
return Collections.emptyList(); return Collections.emptyList();
} }
/**
*
*
* @param namespace
* @param itemId
* @param tpId
* @param readTimeout
* @return
*/
public String getServerConfig(String namespace, String itemId, String tpId, long readTimeout) { public String getServerConfig(String namespace, String itemId, String tpId, long readTimeout) {
Map<String, String> params = new HashMap(3); Map<String, String> params = new HashMap(3);
params.put("namespace", namespace); params.put("namespace", namespace);
@ -229,12 +202,6 @@ public class ClientWorker {
return Constants.NULL; return Constants.NULL;
} }
/**
* Http
*
* @param response
* @return
*/
public List<String> parseUpdateDataIdResponse(String response) { public List<String> parseUpdateDataIdResponse(String response) {
if (StringUtils.isEmpty(response)) { if (StringUtils.isEmpty(response)) {
return Collections.emptyList(); return Collections.emptyList();
@ -268,14 +235,6 @@ public class ClientWorker {
return updateList; return updateList;
} }
/**
* CacheData Listener
*
* @param namespace
* @param itemId
* @param tpId
* @param listeners
*/
public void addTenantListeners(String namespace, String itemId, String tpId, List<? extends Listener> listeners) { public void addTenantListeners(String namespace, String itemId, String tpId, List<? extends Listener> listeners) {
CacheData cacheData = addCacheDataIfAbsent(namespace, itemId, tpId); CacheData cacheData = addCacheDataIfAbsent(namespace, itemId, tpId);
for (Listener listener : listeners) { for (Listener listener : listeners) {
@ -283,14 +242,6 @@ public class ClientWorker {
} }
} }
/**
* CacheData
*
* @param namespace
* @param itemId
* @param tpId
* @return
*/
public CacheData addCacheDataIfAbsent(String namespace, String itemId, String tpId) { public CacheData addCacheDataIfAbsent(String namespace, String itemId, String tpId) {
CacheData cacheData = cacheMap.get(tpId); CacheData cacheData = cacheMap.get(tpId);
if (cacheData != null) { if (cacheData != null) {
@ -325,4 +276,5 @@ public class ClientWorker {
private void setHealthServer(boolean isHealthServer) { private void setHealthServer(boolean isHealthServer) {
this.isHealthServer = isHealthServer; this.isHealthServer = isHealthServer;
} }
} }

@ -1,7 +1,7 @@
package com.github.dynamic.threadpool.starter.core; package com.github.dynamic.threadpool.starter.core;
/** /**
* ConfigAdapter. * Config Adapter.
* *
* @author chen.ma * @author chen.ma
* @date 2021/6/22 21:29 * @date 2021/6/22 21:29
@ -9,11 +9,12 @@ package com.github.dynamic.threadpool.starter.core;
public class ConfigAdapter { public class ConfigAdapter {
/** /**
* 线 * callback Config.
* *
* @param config * @param config
*/ */
public void callbackConfig(String config) { public void callbackConfig(String config) {
ThreadPoolDynamicRefresh.refreshDynamicPool(config); ThreadPoolDynamicRefresh.refreshDynamicPool(config);
} }
} }

@ -1,7 +1,7 @@
package com.github.dynamic.threadpool.starter.core; package com.github.dynamic.threadpool.starter.core;
/** /**
* * Config Service.
* *
* @author chen.ma * @author chen.ma
* @date 2021/6/21 21:49 * @date 2021/6/21 21:49
@ -24,4 +24,5 @@ public interface ConfigService {
* @return * @return
*/ */
String getServerStatus(); String getServerStatus();
} }

@ -6,5 +6,5 @@ package com.github.dynamic.threadpool.starter.core;
* @author chen.ma * @author chen.ma
* @date 2021/7/13 21:50 * @date 2021/7/13 21:50
*/ */
public interface DynamicTpClient { public interface DynamicThreadPoolClient {
} }

@ -5,7 +5,7 @@ import com.github.dynamic.threadpool.common.constant.Constants;
import com.github.dynamic.threadpool.common.model.PoolParameterInfo; import com.github.dynamic.threadpool.common.model.PoolParameterInfo;
import com.github.dynamic.threadpool.common.web.base.Result; import com.github.dynamic.threadpool.common.web.base.Result;
import com.github.dynamic.threadpool.starter.common.CommonThreadPool; import com.github.dynamic.threadpool.starter.common.CommonThreadPool;
import com.github.dynamic.threadpool.starter.config.DynamicThreadPoolProperties; import com.github.dynamic.threadpool.starter.config.BootstrapProperties;
import com.github.dynamic.threadpool.starter.remote.HttpAgent; import com.github.dynamic.threadpool.starter.remote.HttpAgent;
import com.github.dynamic.threadpool.starter.toolkit.thread.QueueTypeEnum; import com.github.dynamic.threadpool.starter.toolkit.thread.QueueTypeEnum;
import com.github.dynamic.threadpool.starter.toolkit.thread.RejectedTypeEnum; import com.github.dynamic.threadpool.starter.toolkit.thread.RejectedTypeEnum;
@ -23,21 +23,21 @@ import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
/** /**
* 线 * Dynamic ThreadPool Post Processor.
* *
* @author chen.ma * @author chen.ma
* @date 2021/8/2 20:40 * @date 2021/8/2 20:40
*/ */
@Slf4j @Slf4j
public final class ThreadPoolBeanPostProcessor implements BeanPostProcessor { public final class DynamicThreadPoolPostProcessor implements BeanPostProcessor {
private final DynamicThreadPoolProperties properties; private final BootstrapProperties properties;
private final ThreadPoolOperation threadPoolOperation; private final ThreadPoolOperation threadPoolOperation;
private final HttpAgent httpAgent; private final HttpAgent httpAgent;
public ThreadPoolBeanPostProcessor(DynamicThreadPoolProperties properties, HttpAgent httpAgent, public DynamicThreadPoolPostProcessor(BootstrapProperties properties, HttpAgent httpAgent,
ThreadPoolOperation threadPoolOperation) { ThreadPoolOperation threadPoolOperation) {
this.properties = properties; this.properties = properties;
this.httpAgent = httpAgent; this.httpAgent = httpAgent;

@ -7,7 +7,7 @@ import java.util.Map;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
/** /**
* 线 * Global ThreadPool Manage.
* *
* @author chen.ma * @author chen.ma
* @date 2021/6/20 15:57 * @date 2021/6/20 15:57
@ -38,4 +38,5 @@ public class GlobalThreadPoolManage {
public static void registerPoolParameter(String tpId, PoolParameter poolParameter) { public static void registerPoolParameter(String tpId, PoolParameter poolParameter) {
POOL_PARAMETER.put(tpId, poolParameter); POOL_PARAMETER.put(tpId, poolParameter);
} }
} }

@ -1,12 +1,25 @@
package com.github.dynamic.threadpool.starter.core; package com.github.dynamic.threadpool.starter.core;
import lombok.Getter;
import lombok.Setter;
/** /**
* Instance Info. * Instance Info.
* *
* @author chen.ma * @author chen.ma
* @date 2021/7/13 22:10 * @date 2021/7/13 22:10
*/ */
public class InstanceInfo { @Getter
@Setter
public class InstanceInfo implements InstanceConfig {
private static final String UNKNOWN = "unknown";
private String appName = UNKNOWN;
private String hostName;
private String instanceId;
private String appName;
} }

@ -3,7 +3,7 @@ package com.github.dynamic.threadpool.starter.core;
import java.util.concurrent.Executor; import java.util.concurrent.Executor;
/** /**
* * Listener.
* *
* @author chen.ma * @author chen.ma
* @date 2021/6/22 20:20 * @date 2021/6/22 20:20
@ -23,4 +23,5 @@ public interface Listener {
* @param configInfo * @param configInfo
*/ */
void receiveConfigInfo(String configInfo); void receiveConfigInfo(String configInfo);
} }

@ -5,7 +5,7 @@ import com.github.dynamic.threadpool.starter.remote.HttpAgent;
import java.util.Arrays; import java.util.Arrays;
/** /**
* 线 * ThreadPool Config Service.
* *
* @author chen.ma * @author chen.ma
* @date 2021/6/21 21:50 * @date 2021/6/21 21:50
@ -34,4 +34,5 @@ public class ThreadPoolConfigService implements ConfigService {
return "DOWN"; return "DOWN";
} }
} }
} }

@ -12,7 +12,7 @@ import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
/** /**
* 线 * ThreadPool Dynamic Refresh.
* *
* @author chen.ma * @author chen.ma
* @date 2021/6/20 15:51 * @date 2021/6/20 15:51

@ -1,11 +1,11 @@
package com.github.dynamic.threadpool.starter.core; package com.github.dynamic.threadpool.starter.core;
import com.github.dynamic.threadpool.starter.config.DynamicThreadPoolProperties; import com.github.dynamic.threadpool.starter.config.BootstrapProperties;
import java.util.concurrent.Executor; import java.util.concurrent.Executor;
/** /**
* ThreadPoolOperation. * ThreadPool Operation.
* *
* @author chen.ma * @author chen.ma
* @date 2021/6/22 20:25 * @date 2021/6/22 20:25
@ -14,9 +14,9 @@ public class ThreadPoolOperation {
private final ConfigService configService; private final ConfigService configService;
private final DynamicThreadPoolProperties properties; private final BootstrapProperties properties;
public ThreadPoolOperation(DynamicThreadPoolProperties properties, ConfigService configService) { public ThreadPoolOperation(BootstrapProperties properties, ConfigService configService) {
this.properties = properties; this.properties = properties;
this.configService = configService; this.configService = configService;
} }
@ -38,4 +38,5 @@ public class ThreadPoolOperation {
return configListener; return configListener;
} }
} }

@ -1,7 +1,7 @@
package com.github.dynamic.threadpool.starter.core; package com.github.dynamic.threadpool.starter.core;
/** /**
* ThreadPoolSubscribeCallback. * ThreadPool Subscribe Callback.
* *
* @author chen.ma * @author chen.ma
* @date 2021/6/22 20:26 * @date 2021/6/22 20:26
@ -14,4 +14,5 @@ public interface ThreadPoolSubscribeCallback {
* @param config * @param config
*/ */
void callback(String config); void callback(String config);
} }

@ -13,7 +13,7 @@ import java.lang.annotation.*;
@Target(ElementType.TYPE) @Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME) @Retention(RetentionPolicy.RUNTIME)
@Documented @Documented
@Import(DynamicThreadPoolMarkerConfiguration.class) @Import(MarkerConfiguration.class)
public @interface EnableDynamicThreadPool { public @interface EnableDynamicThreadPool {
} }

@ -10,7 +10,7 @@ import org.springframework.context.annotation.Configuration;
* @date 2021/7/8 23:30 * @date 2021/7/8 23:30
*/ */
@Configuration(proxyBeanMethods = false) @Configuration(proxyBeanMethods = false)
public class DynamicThreadPoolMarkerConfiguration { public class MarkerConfiguration {
@Bean @Bean
public Marker dynamicThreadPoolMarkerBean() { public Marker dynamicThreadPoolMarkerBean() {
@ -20,4 +20,5 @@ public class DynamicThreadPoolMarkerConfiguration {
public class Marker { public class Marker {
} }
} }

@ -1,6 +1,6 @@
package com.github.dynamic.threadpool.starter.handler; package com.github.dynamic.threadpool.starter.handler;
import com.github.dynamic.threadpool.starter.config.DynamicThreadPoolProperties; import com.github.dynamic.threadpool.starter.config.BootstrapProperties;
import lombok.NonNull; import lombok.NonNull;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
@ -17,10 +17,10 @@ import org.springframework.boot.ansi.AnsiStyle;
*/ */
@Slf4j @Slf4j
@RequiredArgsConstructor @RequiredArgsConstructor
public class ThreadPoolBannerHandler implements InitializingBean { public class DynamicThreadPoolBannerHandler implements InitializingBean {
@NonNull @NonNull
private final DynamicThreadPoolProperties properties; private final BootstrapProperties properties;
private final String DYNAMIC_THREAD_POOL = " :: Dynamic ThreadPool :: "; private final String DYNAMIC_THREAD_POOL = " :: Dynamic ThreadPool :: ";
@ -53,7 +53,7 @@ public class ThreadPoolBannerHandler implements InitializingBean {
} }
public static String getVersion() { public static String getVersion() {
final Package pkg = ThreadPoolBannerHandler.class.getPackage(); final Package pkg = DynamicThreadPoolBannerHandler.class.getPackage();
return pkg != null ? pkg.getImplementationVersion() : ""; return pkg != null ? pkg.getImplementationVersion() : "";
} }

@ -87,4 +87,5 @@ public class ThreadPoolRunStateHandler {
private static String divide(int num1, int num2) { private static String divide(int num1, int num2) {
return ((int) (Double.parseDouble(num1 + "") / Double.parseDouble(num2 + "") * 100)) + "%"; return ((int) (Double.parseDouble(num1 + "") / Double.parseDouble(num2 + "") * 100)) + "%";
} }
} }

@ -75,4 +75,5 @@ public interface HttpAgent {
*/ */
Result httpDeleteByConfig(String path, Map<String, String> headers, Map<String, String> paramValues, Result httpDeleteByConfig(String path, Map<String, String> headers, Map<String, String> paramValues,
long readTimeoutMs); long readTimeoutMs);
} }

@ -1,7 +1,7 @@
package com.github.dynamic.threadpool.starter.remote; package com.github.dynamic.threadpool.starter.remote;
import com.github.dynamic.threadpool.common.web.base.Result; import com.github.dynamic.threadpool.common.web.base.Result;
import com.github.dynamic.threadpool.starter.config.DynamicThreadPoolProperties; import com.github.dynamic.threadpool.starter.config.BootstrapProperties;
import com.github.dynamic.threadpool.starter.toolkit.HttpClientUtil; import com.github.dynamic.threadpool.starter.toolkit.HttpClientUtil;
import java.util.Map; import java.util.Map;
@ -14,13 +14,13 @@ import java.util.Map;
*/ */
public class ServerHttpAgent implements HttpAgent { public class ServerHttpAgent implements HttpAgent {
private final DynamicThreadPoolProperties dynamicThreadPoolProperties; private final BootstrapProperties dynamicThreadPoolProperties;
private final ServerListManager serverListManager; private final ServerListManager serverListManager;
private final HttpClientUtil httpClientUtil; private final HttpClientUtil httpClientUtil;
public ServerHttpAgent(DynamicThreadPoolProperties properties, HttpClientUtil httpClientUtil) { public ServerHttpAgent(BootstrapProperties properties, HttpClientUtil httpClientUtil) {
this.dynamicThreadPoolProperties = properties; this.dynamicThreadPoolProperties = properties;
this.httpClientUtil = httpClientUtil; this.httpClientUtil = httpClientUtil;
this.serverListManager = new ServerListManager(dynamicThreadPoolProperties); this.serverListManager = new ServerListManager(dynamicThreadPoolProperties);

@ -1,6 +1,6 @@
package com.github.dynamic.threadpool.starter.remote; package com.github.dynamic.threadpool.starter.remote;
import com.github.dynamic.threadpool.starter.config.DynamicThreadPoolProperties; import com.github.dynamic.threadpool.starter.config.BootstrapProperties;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.util.StringUtils; import org.springframework.util.StringUtils;
@ -27,9 +27,9 @@ public class ServerListManager {
private Iterator<String> iterator; private Iterator<String> iterator;
private final DynamicThreadPoolProperties properties; private final BootstrapProperties properties;
public ServerListManager(DynamicThreadPoolProperties dynamicThreadPoolProperties) { public ServerListManager(BootstrapProperties dynamicThreadPoolProperties) {
this.properties = dynamicThreadPoolProperties; this.properties = dynamicThreadPoolProperties;
serverAddrsStr = properties.getServerAddr(); serverAddrsStr = properties.getServerAddr();
@ -122,5 +122,4 @@ public class ServerListManager {
} }
} }
} }

@ -3,7 +3,7 @@ package com.github.dynamic.threadpool.starter.spi;
import java.util.concurrent.BlockingQueue; import java.util.concurrent.BlockingQueue;
/** /**
* * Custom BlockingQueue.
* *
* @author chen.ma * @author chen.ma
* @date 2021/7/11 00:51 * @date 2021/7/11 00:51
@ -11,14 +11,14 @@ import java.util.concurrent.BlockingQueue;
public interface CustomBlockingQueue { public interface CustomBlockingQueue {
/** /**
* * Gets the custom blocking queue type.
* *
* @return * @return
*/ */
Integer getType(); Integer getType();
/** /**
* * Get custom blocking queue.
* *
* @return * @return
*/ */

@ -3,7 +3,7 @@ package com.github.dynamic.threadpool.starter.spi;
import java.util.concurrent.RejectedExecutionHandler; import java.util.concurrent.RejectedExecutionHandler;
/** /**
* * Custom RejectedExecution Handler.
* *
* @author chen.ma * @author chen.ma
* @date 2021/7/10 23:51 * @date 2021/7/10 23:51
@ -11,14 +11,14 @@ import java.util.concurrent.RejectedExecutionHandler;
public interface CustomRejectedExecutionHandler { public interface CustomRejectedExecutionHandler {
/** /**
* * Get custom reject policy type.
* *
* @return * @return
*/ */
Integer getType(); Integer getType();
/** /**
* * Get custom reject policy.
* *
* @return * @return
*/ */

@ -43,4 +43,5 @@ public class DynamicTpServiceLoader {
throw new ServiceLoaderInstantiationException(clazz, ex); throw new ServiceLoaderInstantiationException(clazz, ex);
} }
} }
} }

@ -38,4 +38,5 @@ public class ArrayUtil {
} }
return array.clone(); return array.clone();
} }
} }

@ -11,7 +11,7 @@ import java.util.Map;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
/** /**
* Http * HttpClient Util.
* *
* @author chen.ma * @author chen.ma
* @date 2021/6/10 13:30 * @date 2021/6/10 13:30

@ -9,7 +9,7 @@ import java.util.concurrent.*;
import java.util.concurrent.locks.AbstractQueuedSynchronizer; import java.util.concurrent.locks.AbstractQueuedSynchronizer;
/** /**
* 线 * Abstract Build ThreadPool Template.
* *
* @author chen.ma * @author chen.ma
* @date 2021/7/5 21:45 * @date 2021/7/5 21:45
@ -157,4 +157,5 @@ public class AbstractBuildThreadPoolTemplate {
.build(); .build();
} }
} }
} }

@ -3,7 +3,7 @@ package com.github.dynamic.threadpool.starter.toolkit.thread;
import java.io.Serializable; import java.io.Serializable;
/** /**
* * Builder pattern interface definition.
* *
* @author chen.ma * @author chen.ma
* @date 2021/7/5 21:39 * @date 2021/7/5 21:39

@ -9,9 +9,7 @@ import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicInteger;
/** /**
* 线, Dubbo 线 EagerThreadPoolExecutor * Fast ThreadPool Executor.
* <p>
* {@link TaskQueue}
* *
* @author chen.ma * @author chen.ma
* @date 2021/7/5 21:00 * @date 2021/7/5 21:00

@ -9,7 +9,7 @@ import java.util.Optional;
import java.util.concurrent.*; import java.util.concurrent.*;
/** /**
* * Queue Type Enum.
* *
* @author chen.ma * @author chen.ma
* @date 2021/6/25 12:30 * @date 2021/6/25 12:30
@ -89,4 +89,5 @@ public enum QueueTypeEnum {
return blockingQueue; return blockingQueue;
} }
} }

@ -6,7 +6,7 @@ import java.util.concurrent.BlockingQueue;
import java.util.concurrent.RejectedExecutionHandler; import java.util.concurrent.RejectedExecutionHandler;
/** /**
* 线 * Rejected Policies.
* *
* @author chen.ma * @author chen.ma
* @date 2021/7/5 21:23 * @date 2021/7/5 21:23
@ -53,4 +53,5 @@ public class RejectedPolicies {
} }
}; };
} }
} }

@ -11,7 +11,7 @@ import java.util.concurrent.ThreadPoolExecutor;
import java.util.stream.Stream; import java.util.stream.Stream;
/** /**
* * Reject policy type Enum.
* *
* @author chen.ma * @author chen.ma
* @date 2021/7/10 23:16 * @date 2021/7/10 23:16

@ -6,7 +6,7 @@ import lombok.extern.slf4j.Slf4j;
import java.util.concurrent.LinkedBlockingQueue; import java.util.concurrent.LinkedBlockingQueue;
/** /**
* * Resizable Capacity LinkedBlockIngQueue.
* *
* @author chen.ma * @author chen.ma
* @date 2021/6/20 14:24 * @date 2021/6/20 14:24
@ -24,9 +24,10 @@ public class ResizableCapacityLinkedBlockIngQueue<E> extends LinkedBlockingQueue
ReflectUtil.setFieldValue(this, "capacity", capacity); ReflectUtil.setFieldValue(this, "capacity", capacity);
} catch (Exception ex) { } catch (Exception ex) {
// ignore // ignore
log.error("动态修改阻塞队列大小失败.", ex); log.error("Dynamic modification of blocking queue size failed.", ex);
successFlag = false; successFlag = false;
} }
return successFlag; return successFlag;
} }
} }

@ -5,9 +5,7 @@ import java.util.concurrent.RejectedExecutionException;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
/** /**
* , Dubbo TaskQueue * Task Queue.
* <p>
* {@link FastThreadPoolExecutor} 使
* *
* @author chen.ma * @author chen.ma
* @date 2021/7/5 21:00 * @date 2021/7/5 21:00
@ -45,7 +43,7 @@ public class TaskQueue<R extends Runnable> extends LinkedBlockingQueue<Runnable>
public boolean retryOffer(Runnable o, long timeout, TimeUnit unit) throws InterruptedException { public boolean retryOffer(Runnable o, long timeout, TimeUnit unit) throws InterruptedException {
if (executor.isShutdown()) { if (executor.isShutdown()) {
throw new RejectedExecutionException("执行器已关闭!"); throw new RejectedExecutionException("Actuator closed!");
} }
return super.offer(o, timeout, unit); return super.offer(o, timeout, unit);
} }

@ -5,7 +5,7 @@ import java.util.concurrent.ThreadFactory;
import java.util.concurrent.atomic.AtomicLong; import java.util.concurrent.atomic.AtomicLong;
/** /**
* ThreadFactory * ThreadFactory Builder.
* *
* @author chen.ma * @author chen.ma
* @date 2021/7/5 21:53 * @date 2021/7/5 21:53
@ -152,4 +152,5 @@ public class ThreadFactoryBuilder implements Builder<ThreadFactory> {
return thread; return thread;
}; };
} }
} }

@ -7,7 +7,7 @@ import java.math.BigDecimal;
import java.util.concurrent.*; import java.util.concurrent.*;
/** /**
* 线 * ThreadPool Builder.
* *
* @author chen.ma * @author chen.ma
* @date 2021/6/28 17:29 * @date 2021/6/28 17:29
@ -243,4 +243,5 @@ public class ThreadPoolBuilder implements Builder<ThreadPoolExecutor> {
return initParam; return initParam;
} }
} }

@ -5,7 +5,7 @@ import com.github.dynamic.threadpool.starter.toolkit.ArrayUtil;
import java.util.concurrent.*; import java.util.concurrent.*;
/** /**
* 线 * ThreadPool Executor Template.
* *
* @author chen.ma * @author chen.ma
* @date 2021/7/5 21:59 * @date 2021/7/5 21:59
@ -62,4 +62,5 @@ public class ThreadPoolExecutorTemplate extends ThreadPoolExecutor {
} }
}; };
} }
} }

@ -8,7 +8,7 @@ import java.util.concurrent.Future;
import java.util.concurrent.ThreadPoolExecutor; import java.util.concurrent.ThreadPoolExecutor;
/** /**
* 线 * Dynamic ThreadPool Wrap.
* *
* @author chen.ma * @author chen.ma
* @date 2021/6/20 16:55 * @date 2021/6/20 16:55

@ -5,7 +5,7 @@ import lombok.Getter;
import lombok.Setter; import lombok.Setter;
/** /**
* * Manager Listener Wrap.
* *
* @author chen.ma * @author chen.ma
* @date 2021/6/22 17:47 * @date 2021/6/22 17:47
@ -14,12 +14,13 @@ import lombok.Setter;
@Setter @Setter
public class ManagerListenerWrap { public class ManagerListenerWrap {
final Listener listener; private String lastCallMd5;
String lastCallMd5; final Listener listener;
public ManagerListenerWrap(String md5, Listener listener) { public ManagerListenerWrap(String md5, Listener listener) {
this.lastCallMd5 = md5; this.lastCallMd5 = md5;
this.listener = listener; this.listener = listener;
} }
} }

Loading…
Cancel
Save