/** * Install the system wide configuration with the ConfigurationManager. This will also install * the configuration with the {@link DynamicPropertyFactory} by calling {@link DynamicPropertyFactory#initWithConfigurationSource(AbstractConfiguration)}. * This call can be made only once, otherwise IllegalStateException will be thrown. */ public static synchronized void install(AbstractConfiguration config) throws IllegalStateException { if (!customConfigurationInstalled) { setDirect(config); if (DynamicPropertyFactory.getBackingConfigurationSource() != config) { DynamicPropertyFactory.initWithConfigurationSource(config); } } else { throw new IllegalStateException("A non-default configuration is already installed"); } }
/** * Install the system wide configuration with the ConfigurationManager. This will also install * the configuration with the {@link DynamicPropertyFactory} by calling {@link DynamicPropertyFactory#initWithConfigurationSource(AbstractConfiguration)}. * This call can be made only once, otherwise IllegalStateException will be thrown. */ public static synchronized void install(AbstractConfiguration config) throws IllegalStateException { if (!customConfigurationInstalled) { setDirect(config); if (DynamicPropertyFactory.getBackingConfigurationSource() != config) { DynamicPropertyFactory.initWithConfigurationSource(config); } } else { throw new IllegalStateException("A non-default configuration is already installed"); } }
/** * Initialize the factory with an AbstractConfiguration. * <p/> * The initialization will register a ConfigurationListener with the configuration so that {@link DynamicProperty} * will receives a callback and refresh its value when a property is changed in the configuration. * <p/> * If the factory is already initialized with a default configuration source (see {@link #getInstance()}), it will re-register * itself with the new configuration source passed to this method. Otherwise, this method will throw IllegalArgumentException * if it has been initialized with a different and non-default configuration source. This method should be only called once. * * @param config Configuration to be attached with DynamicProperty * @return the instance of DynamicPropertyFactory * @throws IllegalArgumentException if the factory has already been initialized with a non-default configuration source */ public static DynamicPropertyFactory initWithConfigurationSource(AbstractConfiguration config) { synchronized (ConfigurationManager.class) { if (config == null) { throw new NullPointerException("config is null"); } if (ConfigurationManager.isConfigurationInstalled() && config != ConfigurationManager.instance) { throw new IllegalStateException("ConfigurationManager is already initialized with configuration " + ConfigurationManager.getConfigInstance()); } if (config instanceof DynamicPropertySupport) { return initWithConfigurationSource((DynamicPropertySupport) config); } return initWithConfigurationSource(new ConfigurationBackedDynamicPropertySupportImpl(config)); } }
/** * Initialize the factory with an AbstractConfiguration. * <p/> * The initialization will register a ConfigurationListener with the configuration so that {@link DynamicProperty} * will receives a callback and refresh its value when a property is changed in the configuration. * <p/> * If the factory is already initialized with a default configuration source (see {@link #getInstance()}), it will re-register * itself with the new configuration source passed to this method. Otherwise, this method will throw IllegalArgumentException * if it has been initialized with a different and non-default configuration source. This method should be only called once. * * @param config Configuration to be attached with DynamicProperty * @return the instance of DynamicPropertyFactory * @throws IllegalArgumentException if the factory has already been initialized with a non-default configuration source */ public static DynamicPropertyFactory initWithConfigurationSource(AbstractConfiguration config) { synchronized (ConfigurationManager.class) { if (config == null) { throw new NullPointerException("config is null"); } if (ConfigurationManager.isConfigurationInstalled() && config != ConfigurationManager.instance) { throw new IllegalStateException("ConfigurationManager is already initialized with configuration " + ConfigurationManager.getConfigInstance()); } if (config instanceof DynamicPropertySupport) { return initWithConfigurationSource((DynamicPropertySupport) config); } return initWithConfigurationSource(new ConfigurationBackedDynamicPropertySupportImpl(config)); } }
AbstractConfiguration configFromManager = ConfigurationManager.getConfigInstance(); if (configFromManager != null) { initWithConfigurationSource(configFromManager); initializedWithDefaultConfig = !ConfigurationManager.isConfigurationInstalled(); logger.info("DynamicPropertyFactory is initialized with configuration sources: " + configFromManager);
AbstractConfiguration configFromManager = ConfigurationManager.getConfigInstance(); if (configFromManager != null) { initWithConfigurationSource(configFromManager); initializedWithDefaultConfig = !ConfigurationManager.isConfigurationInstalled(); logger.info("DynamicPropertyFactory is initialized with configuration sources: " + configFromManager);
@Inject public synchronized static void initialize(DeploymentContext context, AbstractConfigurationBridge config) { reset(); delegate = config; AbstractConfiguration actualConfig = ConfigurationManager.getConfigInstance(); if (!actualConfig.equals(INSTANCE)) { UnsupportedOperationException cause = new UnsupportedOperationException("**** Remove static reference to ConfigurationManager or FastProperty in this call stack ****"); cause.setStackTrace(ConfigurationManager.getStaticInitializationSource()); throw new IllegalStateException("Not using expected bridge!!! " + actualConfig.getClass() + " instead of " + StaticAbstractConfiguration.class, cause); } DynamicPropertyFactory.initWithConfigurationSource((AbstractConfiguration)INSTANCE); // Bridge change notification from the new delegate to any listeners registered on // this static class. Notifications will be removed if the StaticAbstractConfiguration // is reset and will reattached to a new bridge should initialize be called again. config.addConfigurationListener(INSTANCE.forwardingConfigurationListener); config.addConfigurationListener(INSTANCE.forwardingPropertyListener); }
@PostConstruct public void init() { if (init) { return; } if (GLOBAL_DEFAULT == null) { throw new IllegalStateException("setGlobalDefaults() must be set before init() is called"); } baseConfig = new ConcurrentCompositeConfiguration(); baseConfig.addConfiguration(new MapConfiguration(getOverride())); baseConfig.addConfiguration(new MapConfiguration(GLOBAL_DEFAULT)); DynamicPropertyFactory.initWithConfigurationSource(baseConfig); init = true; }
DynamicPropertyFactory.initWithConfigurationSource(myConfiguration);
DynamicPropertyFactory.initWithConfigurationSource(myConfiguration);
public void setAppContext(AppContext appContext) { this.appContext = appContext; if (!conf.has("eureka.port")) { conf.put("eureka.port", ""+appContext.getServerPort("jetty.port")); } if (!conf.has("eureka.name")) { conf.put("eureka.name", appContext.getConf().check("nutz.application.name")); } DynamicPropertyFactory.initWithConfigurationSource(new XConfigure()); }