forked from opengoofy/hippo4j
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
294f8fd
commit 5e00d45
Showing
3 changed files
with
59 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
...-boot-starter/src/main/java/cn/hippo4j/core/starter/refresher/ApolloRefresherHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package cn.hippo4j.core.starter.refresher; | ||
|
||
import cn.hippo4j.core.executor.ThreadPoolNotifyAlarmHandler; | ||
import cn.hippo4j.core.starter.config.BootstrapCoreProperties; | ||
import com.ctrip.framework.apollo.Config; | ||
import com.ctrip.framework.apollo.ConfigChangeListener; | ||
import com.ctrip.framework.apollo.ConfigFile; | ||
import com.ctrip.framework.apollo.ConfigService; | ||
import com.ctrip.framework.apollo.core.enums.ConfigFileFormat; | ||
import com.ctrip.framework.apollo.model.ConfigChangeEvent; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.beans.factory.InitializingBean; | ||
import org.springframework.beans.factory.annotation.Value; | ||
|
||
/** | ||
* @author : wh | ||
* @date : 2022/2/28 21:32 | ||
* @description: | ||
*/ | ||
@Slf4j | ||
public class ApolloRefresherHandler extends AbstractCoreThreadPoolDynamicRefresh implements ConfigChangeListener, InitializingBean { | ||
|
||
private static final String APOLLO_PROPERTY = "${apollo.bootstrap.namespaces:application}"; | ||
|
||
@Value(APOLLO_PROPERTY) | ||
private String namespace; | ||
|
||
|
||
public ApolloRefresherHandler(ThreadPoolNotifyAlarmHandler threadPoolNotifyAlarmHandler, ConfigParserHandler configParserHandler, BootstrapCoreProperties bootstrapCoreProperties) { | ||
super(threadPoolNotifyAlarmHandler, configParserHandler, bootstrapCoreProperties); | ||
} | ||
|
||
@Override | ||
public void onChange(ConfigChangeEvent configChangeEvent) { | ||
ConfigFile configFile = ConfigService.getConfigFile(namespace, | ||
ConfigFileFormat.fromString(bootstrapCoreProperties.getConfigFileType())); | ||
String configInfo = configFile.getContent(); | ||
dynamicRefresh(configInfo); | ||
} | ||
|
||
@Override | ||
public void afterPropertiesSet() { | ||
String[] apolloNamespaces = this.namespace.split(","); | ||
this.namespace = apolloNamespaces[0]; | ||
Config config = ConfigService.getConfig(namespace); | ||
config.addChangeListener(this); | ||
log.info("dynamic-thread-pool refresher, add apollo listener success, namespace: {}", namespace); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters