Exemplo n.º 1
0
 public LocalFileConfigRepository(string namespaceName, ConfigRepository upstream)
 {
     m_namespace  = namespaceName;
     m_configUtil = ComponentLocator.Lookup <ConfigUtil>();
     this.PrepareConfigCacheDir();
     this.SetUpstreamRepository(upstream);
     this.TrySync();
 }
Exemplo n.º 2
0
 public RemoteConfigRepository(string namespaceName)
 {
     m_namespace      = namespaceName;
     m_configCache    = new ThreadSafe.AtomicReference <ApolloConfig>(null);
     m_configUtil     = ComponentLocator.Lookup <ConfigUtil>();
     m_httpUtil       = ComponentLocator.Lookup <HttpUtil>();
     m_serviceLocator = ComponentLocator.Lookup <ConfigServiceLocator>();
     m_remoteConfigLongPollService = ComponentLocator.Lookup <RemoteConfigLongPollService>();
     m_longPollServiceDto          = new ThreadSafe.AtomicReference <ServiceDTO>(null);
     this.TrySync();
     this.SchedulePeriodicRefresh();
     this.ScheduleLongPollingRefresh();
 }
Exemplo n.º 3
0
 static ConfigService()
 {
     try
     {
         ComponentsConfigurator.DefineComponents();
         s_configManager = ComponentLocator.Lookup <ConfigManager>();
     }
     catch (Exception ex)
     {
         ApolloConfigException exception = new ApolloConfigException("Init ConfigService failed", ex);
         logger.Error(exception);
         throw exception;
     }
 }
Exemplo n.º 4
0
        static ConfigService()
        {
            try
            {
                ApolloConfigSection = ApolloConfigSettingHelper.GetApolloConfigSettings();

                ComponentsConfigurator.DefineComponents();
                s_configManager = ComponentLocator.Lookup <IConfigManager>();

                // 初始化 namespace
                var namespaceSection = (ApolloConfigNameSpacesSection)ConfigurationManager.GetSection(ApolloConfigNameSpacesSection.CONFIG_SECTION_NAME);
                if (namespaceSection != null && namespaceSection.Namespaces != null && namespaceSection.Namespaces.Count > 0)
                {
                    foreach (var namespaceEle in namespaceSection.Namespaces)
                    {
                        if (namespaceEle is NamespaceElement namespaceElement && !string.IsNullOrWhiteSpace(namespaceElement.Value) && !ConfigNamespaces.Contains(namespaceElement.Value.Trim()))
                        {
                            ConfigNamespaces.Add(namespaceElement.Value.Trim());
                        }
                    }
                }
                if (ConfigNamespaces == null || ConfigNamespaces.Count == 0)
                {
                    ConfigNamespaces.Add(ConfigConsts.NAMESPACE_APPLICATION);
                }

                foreach (var namesp in ConfigNamespaces)
                {
                    var config = GetConfig(namesp);
                    s_configManager.Configs.TryAdd(namesp, config);
                }
            }
            catch (Exception ex)
            {
                ApolloConfigException exception = new ApolloConfigException("Init ConfigService failed", ex);
                logger.Error(exception);
                throw exception;
            }
        }
Exemplo n.º 5
0
        public ConfigFactory GetFactory(String namespaceName)
        {
            // step 1: check hacked factory
            ConfigFactory factory = m_registry.GetFactory(namespaceName);

            if (factory != null)
            {
                return(factory);
            }

            // step 2: check cache
            m_factories.TryGetValue(namespaceName, out factory);

            if (factory != null)
            {
                return(factory);
            }

            // step 3: check declared config factory
            try
            {
                factory = ComponentLocator.Lookup <ConfigFactory>(namespaceName);
            }
            catch (Exception)
            {
                // ignore it
            }

            // step 4: check default config factory
            if (factory == null)
            {
                factory = ComponentLocator.Lookup <ConfigFactory>();
            }

            m_factories[namespaceName] = factory;

            // factory should not be null
            return(factory);
        }