代码优化.

pull/146/head
chen.ma 3 years ago
parent 7cf7baaa9f
commit 72c3623ced

@ -73,19 +73,6 @@
<optional>true</optional> <optional>true</optional>
</dependency> </dependency>
<dependency>
<groupId>com.guicedee.services</groupId>
<artifactId>commons-lang3</artifactId>
<version>1.2.1.1-jre17</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>16.0.1</version>
</dependency>
<dependency> <dependency>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId> <artifactId>spring-boot-configuration-processor</artifactId>

@ -32,11 +32,12 @@ public class CoreNotifyConfigBuilder implements NotifyConfigBuilder {
Map<String, List<NotifyConfigDTO>> resultMap = Maps.newHashMap(); Map<String, List<NotifyConfigDTO>> resultMap = Maps.newHashMap();
List<ExecutorProperties> executors = bootstrapCoreProperties.getExecutors(); List<ExecutorProperties> executors = bootstrapCoreProperties.getExecutors();
if (null !=executors) { if (null != executors) {
for (ExecutorProperties executor : executors) { for (ExecutorProperties executor : executors) {
resultMap.putAll(buildSingleNotifyConfig(executor)); resultMap.putAll(buildSingleNotifyConfig(executor));
} }
} }
return resultMap; return resultMap;
} }

@ -92,7 +92,6 @@ public abstract class AbstractCoreThreadPoolDynamicRefresh implements ThreadPool
threadPoolNotifyAlarm.setReceives(executorProperties.getNotify().getReceives()); threadPoolNotifyAlarm.setReceives(executorProperties.getNotify().getReceives());
GlobalNotifyAlarmManage.put(executorProperties.getThreadPoolId(), threadPoolNotifyAlarm); GlobalNotifyAlarmManage.put(executorProperties.getThreadPoolId(), threadPoolNotifyAlarm);
}); });
} }
/** /**

@ -4,8 +4,6 @@ import cn.hippo4j.core.executor.ThreadPoolNotifyAlarmHandler;
import cn.hippo4j.core.starter.config.BootstrapCoreProperties; import cn.hippo4j.core.starter.config.BootstrapCoreProperties;
import com.google.common.base.Charsets; import com.google.common.base.Charsets;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.tuple.ImmutablePair;
import org.apache.commons.lang3.tuple.Pair;
import org.apache.curator.framework.CuratorFramework; import org.apache.curator.framework.CuratorFramework;
import org.apache.curator.framework.CuratorFrameworkFactory; import org.apache.curator.framework.CuratorFrameworkFactory;
import org.apache.curator.framework.api.CuratorListener; import org.apache.curator.framework.api.CuratorListener;
@ -45,7 +43,8 @@ public class ZookeeperRefresherHandler extends AbstractCoreThreadPoolDynamicRefr
loadNode(nodePath); loadNode(nodePath);
} else if (newState == ConnectionState.RECONNECTED) { } else if (newState == ConnectionState.RECONNECTED) {
loadNode(nodePath); loadNode(nodePath);
}}; }
};
final CuratorListener curatorListener = (client, curatorEvent) -> { final CuratorListener curatorListener = (client, curatorEvent) -> {
final WatchedEvent watchedEvent = curatorEvent.getWatchedEvent(); final WatchedEvent watchedEvent = curatorEvent.getWatchedEvent();
@ -58,7 +57,9 @@ public class ZookeeperRefresherHandler extends AbstractCoreThreadPoolDynamicRefr
default: default:
break; break;
} }
}}; }
};
curatorFramework.getConnectionStateListenable().addListener(connectionStateListener); curatorFramework.getConnectionStateListenable().addListener(connectionStateListener);
curatorFramework.getCuratorListenable().addListener(curatorListener); curatorFramework.getCuratorListenable().addListener(curatorListener);
curatorFramework.start(); curatorFramework.start();
@ -66,6 +67,7 @@ public class ZookeeperRefresherHandler extends AbstractCoreThreadPoolDynamicRefr
/** /**
* load config info and refresh. * load config info and refresh.
*
* @param nodePath zk config node path. * @param nodePath zk config node path.
*/ */
public void loadNode(String nodePath) { public void loadNode(String nodePath) {
@ -83,13 +85,15 @@ public class ZookeeperRefresherHandler extends AbstractCoreThreadPoolDynamicRefr
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
final Pair<String, String> keyValue = new ImmutablePair<>(nodeName, value);
content.append(keyValue.getKey()).append("=").append(keyValue.getValue()).append("\n"); content.append(nodeName).append("=").append(value).append("\n");
}); });
dynamicRefresh(content.toString()); dynamicRefresh(content.toString());
registerNotifyAlarmManage(); registerNotifyAlarmManage();
} catch (Exception e) { } catch (Exception e) {
log.error("load zk node error, nodePath is {}", nodePath, e); log.error("load zk node error, nodePath is {}", nodePath, e);
} }
} }
} }

@ -152,6 +152,7 @@ public final class DynamicThreadPoolPostProcessor implements BeanPostProcessor {
dynamicThreadPoolWrap.setExecutor(newDynamicPoolExecutor); dynamicThreadPoolWrap.setExecutor(newDynamicPoolExecutor);
} }
GlobalThreadPoolManage.registerPool(dynamicThreadPoolWrap.getTpId(), dynamicThreadPoolWrap); GlobalThreadPoolManage.registerPool(dynamicThreadPoolWrap.getTpId(), dynamicThreadPoolWrap);
GlobalCoreThreadPoolManage.register( GlobalCoreThreadPoolManage.register(
threadPoolId, threadPoolId,

Loading…
Cancel
Save