Search in sources :

Example 1 with DtpProperties

use of com.dtp.common.config.DtpProperties in project dynamic-tp by lyh200.

the class AbstractRefresher method doRefresh.

private void doRefresh(Map<Object, Object> properties) {
    ConfigurationPropertySource sources = new MapConfigurationPropertySource(properties);
    Binder binder = new Binder(sources);
    DtpProperties bindDtpProperties = binder.bind(DynamicTpConst.MAIN_PROPERTIES_PREFIX, Bindable.ofInstance(dtpProperties)).get();
    DtpRegistry.refresh(bindDtpProperties);
    publishEvent();
}
Also used : Binder(org.springframework.boot.context.properties.bind.Binder) ConfigurationPropertySource(org.springframework.boot.context.properties.source.ConfigurationPropertySource) MapConfigurationPropertySource(org.springframework.boot.context.properties.source.MapConfigurationPropertySource) DtpProperties(com.dtp.common.config.DtpProperties) MapConfigurationPropertySource(org.springframework.boot.context.properties.source.MapConfigurationPropertySource)

Example 2 with DtpProperties

use of com.dtp.common.config.DtpProperties in project dynamic-tp by lyh200.

the class AbstractWebServerTpHandler method onApplicationEvent.

@Override
public void onApplicationEvent(ServletWebServerInitializedEvent event) {
    try {
        DtpProperties dtpProperties = ApplicationContextHolder.getBean(DtpProperties.class);
        updateWebServerTp(dtpProperties);
    } catch (Exception e) {
        log.error("Init web server thread pool failed.", e);
    }
}
Also used : DtpProperties(com.dtp.common.config.DtpProperties)

Example 3 with DtpProperties

use of com.dtp.common.config.DtpProperties in project dynamic-tp by dromara.

the class ZkConfigEnvironmentProcessor method postProcessEnvironment.

@Override
public void postProcessEnvironment(ConfigurableEnvironment environment, SpringApplication application) {
    DtpProperties dtpProperties = new DtpProperties();
    PropertiesBinder.bindDtpProperties(environment, dtpProperties);
    Map<Object, Object> properties = CuratorUtil.genPropertiesMap(dtpProperties);
    if (!checkPropertyExist(environment)) {
        createZkPropertySource(environment, properties);
    }
}
Also used : DtpProperties(com.dtp.common.config.DtpProperties)

Example 4 with DtpProperties

use of com.dtp.common.config.DtpProperties in project dynamic-tp by dromara.

the class ZookeeperRefresher method afterPropertiesSet.

@Override
public void afterPropertiesSet() {
    final ConnectionStateListener connectionStateListener = (client, newState) -> {
        if (newState == ConnectionState.RECONNECTED) {
            loadAndRefresh();
        }
    };
    final CuratorListener curatorListener = (client, curatorEvent) -> {
        final WatchedEvent watchedEvent = curatorEvent.getWatchedEvent();
        if (null != watchedEvent) {
            switch(watchedEvent.getType()) {
                case NodeChildrenChanged:
                case NodeDataChanged:
                    loadAndRefresh();
                    break;
                default:
                    break;
            }
        }
    };
    CuratorFramework curatorFramework = CuratorUtil.getCuratorFramework(dtpProperties);
    String nodePath = CuratorUtil.nodePath(dtpProperties);
    curatorFramework.getConnectionStateListenable().addListener(connectionStateListener);
    curatorFramework.getCuratorListenable().addListener(curatorListener);
    log.info("DynamicTp refresher, add listener success, nodePath: {}", nodePath);
}
Also used : ZK_PROPERTY_SOURCE_NAME(com.dtp.starter.zookeeper.autoconfigure.ZkConfigEnvironmentProcessor.ZK_PROPERTY_SOURCE_NAME) CuratorListener(org.apache.curator.framework.api.CuratorListener) Resource(javax.annotation.Resource) ConnectionStateListener(org.apache.curator.framework.state.ConnectionStateListener) AbstractRefresher(com.dtp.core.refresh.AbstractRefresher) WatchedEvent(org.apache.zookeeper.WatchedEvent) InitializingBean(org.springframework.beans.factory.InitializingBean) ConnectionState(org.apache.curator.framework.state.ConnectionState) Slf4j(lombok.extern.slf4j.Slf4j) CuratorUtil(com.dtp.starter.zookeeper.util.CuratorUtil) CuratorFramework(org.apache.curator.framework.CuratorFramework) ConfigurableEnvironment(org.springframework.core.env.ConfigurableEnvironment) EnvironmentAware(org.springframework.context.EnvironmentAware) Environment(org.springframework.core.env.Environment) DtpProperties(com.dtp.common.config.DtpProperties) WatchedEvent(org.apache.zookeeper.WatchedEvent) CuratorFramework(org.apache.curator.framework.CuratorFramework) CuratorListener(org.apache.curator.framework.api.CuratorListener) ConnectionStateListener(org.apache.curator.framework.state.ConnectionStateListener)

Example 5 with DtpProperties

use of com.dtp.common.config.DtpProperties in project dynamic-tp by dromara.

the class AbstractDtpHandler method onApplicationEvent.

@Override
public void onApplicationEvent(ApplicationStartedEvent event) {
    try {
        DtpProperties dtpProperties = ApplicationContextHolder.getBean(DtpProperties.class);
        updateTp(dtpProperties);
    } catch (Exception e) {
        log.error("Init third party thread pool failed.", e);
    }
}
Also used : DtpProperties(com.dtp.common.config.DtpProperties)

Aggregations

DtpProperties (com.dtp.common.config.DtpProperties)11 NotifyItem (com.dtp.common.dto.NotifyItem)2 DtpContext (com.dtp.core.context.DtpContext)2 Slf4j (lombok.extern.slf4j.Slf4j)2 lombok.val (lombok.val)2 CuratorFramework (org.apache.curator.framework.CuratorFramework)2 ConnectionState (org.apache.curator.framework.state.ConnectionState)2 ConnectionStateListener (org.apache.curator.framework.state.ConnectionStateListener)2 WebServerTpHandler (com.dtp.adapter.web.handler.WebServerTpHandler)1 AlarmInfo (com.dtp.common.dto.AlarmInfo)1 ThreadPoolStats (com.dtp.common.dto.ThreadPoolStats)1 JSON (com.dtp.common.em.ConfigFileTypeEnum.JSON)1 PROPERTIES (com.dtp.common.em.ConfigFileTypeEnum.PROPERTIES)1 ConfigHandler (com.dtp.core.handler.ConfigHandler)1 AbstractRefresher (com.dtp.core.refresh.AbstractRefresher)1 ZK_PROPERTY_SOURCE_NAME (com.dtp.starter.zookeeper.autoconfigure.ZkConfigEnvironmentProcessor.ZK_PROPERTY_SOURCE_NAME)1 CuratorUtil (com.dtp.starter.zookeeper.util.CuratorUtil)1 Maps (com.google.common.collect.Maps)1 StandardCharsets (java.nio.charset.StandardCharsets)1 Collections (java.util.Collections)1