Skip to content

class ConfigurationManager

cangjie
public class ConfigurationManager<T> <: IConfigurationManager<T> where T <: Object

功能:提供带缓存与刷新能力的配置管理器实现。

父类型:

成员概览

成员功能
init(String, IDocumentRetriever, IConfigurationRetriever<T>, Duration, Duration)创建配置管理器。
let DefaultRefreshInterval表示手动刷新请求的默认最小间隔。
let DefaultAutomaticRefreshInterval表示自动后台刷新的默认间隔。
func getConfiguration()获取当前有效配置。
func requestRefresh()请求刷新当前配置缓存。

init(String, IDocumentRetriever, IConfigurationRetriever<T>, Duration, Duration)

cangjie
public init(address: String, documentRetriever: IDocumentRetriever,
configurationRetriever: IConfigurationRetriever<T>, refreshInterval!: Duration = DefaultRefreshInterval,
automaticRefreshInterval!: Duration = DefaultAutomaticRefreshInterval)

功能:创建配置管理器。

参数:

  • address: String - 配置文档地址。
  • documentRetriever: IDocumentRetriever - 用于读取配置文档的检索器。
  • configurationRetriever: IConfigurationRetriever<T> - 用于解析配置对象的检索器。
  • refreshInterval: Duration - 手动刷新请求的最小间隔。
  • automaticRefreshInterval: Duration - 自动后台刷新的间隔。

异常:

  • IllegalArgumentException - 当配置地址为空时抛出。

let DefaultRefreshInterval

cangjie
public static let DefaultRefreshInterval = Duration.minute * 5

功能:表示手动刷新请求的默认最小间隔。

let DefaultAutomaticRefreshInterval

cangjie
public static let DefaultAutomaticRefreshInterval = Duration.hour * 12

功能:表示自动后台刷新的默认间隔。

func getConfiguration()

cangjie
public func getConfiguration(): T

功能:获取当前有效配置。

返回值:

  • T - 返回当前配置对象。

异常:

  • Exception - 当首次加载配置失败时抛出。

func requestRefresh()

cangjie
public func requestRefresh(): Unit

功能:请求刷新当前配置缓存。

返回值:

  • Unit