创建引擎

@param config 模板配置
@return {@link org.rythmengine.RythmEngine}
326055
private static org.rythmengine.RythmEngine createEngine(TemplateConfig config) {
		if (null == config) {
			config = new TemplateConfig();
		}
		
		final Properties props = new Properties();
		final String path = config.getPath();
		if (null != path) {
			props.put("home.template", path);
		}

		final org.rythmengine.RythmEngine engine = new org.rythmengine.RythmEngine(props);
		return engine;
	}
801426
public static ScopeFormats fromConfig(Configuration config) {
		String jmFormat = config.getString(MetricOptions.SCOPE_NAMING_JM);
		String jmJobFormat = config.getString(MetricOptions.SCOPE_NAMING_JM_JOB);
		String tmFormat = config.getString(MetricOptions.SCOPE_NAMING_TM);
		String tmJobFormat = config.getString(MetricOptions.SCOPE_NAMING_TM_JOB);
		String taskFormat = config.getString(MetricOptions.SCOPE_NAMING_TASK);
		String operatorFormat = config.getString(MetricOptions.SCOPE_NAMING_OPERATOR);

		return new ScopeFormats(jmFormat, jmJobFormat, tmFormat, tmJobFormat, taskFormat, operatorFormat);
	}
232681
@Nonnull
    public Configuration filter(Configuration config) {
        final Map<String, Object> values = Maps.newHashMap();

        for (final ConfigurationField field : fields.values()) {
            final String name = field.getName();
            final String type = field.getFieldType();
            switch (type) {
                case BooleanField.FIELD_TYPE:
                    if (config.booleanIsSet(name)) {
                        values.put(name, config.getBoolean(name));
                    }
                    break;
                case NumberField.FIELD_TYPE:
                    if (config.intIsSet(name)) {
                        values.put(name, config.getInt(name));
                    }
                    break;
                case TextField.FIELD_TYPE:
                case DropdownField.FIELD_TYPE:
                    if (config.stringIsSet(name)) {
                        values.put(name, config.getString(name));
                    }
                    break;
                default:
                    throw new IllegalStateException("Unknown field type " + type + " for configuration field \"" + name + "\". This is a bug.");
            }
        }
        return new Configuration(values);
    }
468642
public static synchronized Properties getConfig() {
        if (config == null) {
            try {
                String rpcConfig = "config/rpc-config.properties";
                InputStream ins = SofaConfigs.class.getClassLoader().getResourceAsStream(rpcConfig);
                if (ins == null) {
                    ins = Thread.currentThread().getContextClassLoader()
                        .getResourceAsStream(rpcConfig);
                }

                config = new Properties();
                config.load(ins);
            } catch (Exception e) {
                config = new Properties();
                if (LOGGER.isDebugEnabled()) {
                    LOGGER.debug(LogCodes.getLog(LogCodes.ERROR_RPC_CONFIG_LOAD));
                }
            }
        }

        return config;
    }
110859
private static org.apache.velocity.app.VelocityEngine createEngine(TemplateConfig config) {
		if (null == config) {
			config = new TemplateConfig();
		}

		final org.apache.velocity.app.VelocityEngine ve = new org.apache.velocity.app.VelocityEngine();
		// 编码
		final String charsetStr = config.getCharset().toString();
		ve.setProperty(Velocity.INPUT_ENCODING, charsetStr);
		// ve.setProperty(Velocity.OUTPUT_ENCODING, charsetStr);
		ve.setProperty(Velocity.FILE_RESOURCE_LOADER_CACHE, true); // 使用缓存

		// loader
		switch (config.getResourceMode()) {
		case CLASSPATH:
			ve.setProperty("file.resource.loader.class", "org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader");
			break;
		case FILE:
			// path
			final String path = config.getPath();
			if (null != path) {
				ve.setProperty(Velocity.FILE_RESOURCE_LOADER_PATH, path);
			}
			break;
		case WEB_ROOT:
			ve.setProperty(Velocity.RESOURCE_LOADER, "webapp");
			ve.setProperty("webapp.resource.loader.class", "org.apache.velocity.tools.view.servlet.WebappLoader");
			ve.setProperty("webapp.resource.loader.path", StrUtil.nullToDefault(config.getPath(), StrUtil.SLASH));
			break;
		case STRING:
			ve.setProperty(Velocity.RESOURCE_LOADER, "str");
			ve.setProperty("str.resource.loader.class", SimpleStringResourceLoader.class.getName());
			break;
		default:
			break;
		}

		ve.init();
		return ve;
	}
672716
public static RocksDBNativeMetricOptions fromConfig(Configuration config) {
		RocksDBNativeMetricOptions options = new RocksDBNativeMetricOptions();
		if (config.getBoolean(MONITOR_NUM_IMMUTABLE_MEM_TABLES)) {
			options.enableNumImmutableMemTable();
		}

		if (config.getBoolean(MONITOR_MEM_TABLE_FLUSH_PENDING)) {
			options.enableMemTableFlushPending();
		}

		if (config.getBoolean(TRACK_COMPACTION_PENDING)) {
			options.enableCompactionPending();
		}

		if (config.getBoolean(MONITOR_BACKGROUND_ERRORS)) {
			options.enableBackgroundErrors();
		}

		if (config.getBoolean(MONITOR_CUR_SIZE_ACTIVE_MEM_TABLE)) {
			options.enableCurSizeActiveMemTable();
		}

		if (config.getBoolean(MONITOR_CUR_SIZE_ALL_MEM_TABLE)) {
			options.enableCurSizeAllMemTables();
		}

		if (config.getBoolean(MONITOR_SIZE_ALL_MEM_TABLES)) {
			options.enableSizeAllMemTables();
		}

		if (config.getBoolean(MONITOR_NUM_ENTRIES_ACTIVE_MEM_TABLE)) {
			options.enableNumEntriesActiveMemTable();
		}

		if (config.getBoolean(MONITOR_NUM_ENTRIES_IMM_MEM_TABLES)) {
			options.enableNumEntriesImmMemTables();
		}

		if (config.getBoolean(MONITOR_NUM_DELETES_ACTIVE_MEM_TABLE)) {
			options.enableNumDeletesActiveMemTable();
		}

		if (config.getBoolean(MONITOR_NUM_DELETES_IMM_MEM_TABLE)) {
			options.enableNumDeletesImmMemTables();
		}

		if (config.getBoolean(ESTIMATE_NUM_KEYS)) {
			options.enableEstimateNumKeys();
		}

		if (config.getBoolean(ESTIMATE_TABLE_READERS_MEM)) {
			options.enableEstimateTableReadersMem();
		}

		if (config.getBoolean(MONITOR_NUM_SNAPSHOTS)) {
			options.enableNumSnapshots();
		}

		if (config.getBoolean(MONITOR_NUM_LIVE_VERSIONS)) {
			options.enableNumLiveVersions();
		}

		if (config.getBoolean(ESTIMATE_LIVE_DATA_SIZE)) {
			options.enableEstimateLiveDataSize();
		}

		if (config.getBoolean(MONITOR_TOTAL_SST_FILES_SIZE)) {
			options.enableTotalSstFilesSize();
		}

		if (config.getBoolean(ESTIMATE_PENDING_COMPACTION_BYTES)) {
			options.enableEstimatePendingCompactionBytes();
		}

		if (config.getBoolean(MONITOR_NUM_RUNNING_COMPACTIONS)) {
			options.enableNumRunningCompactions();
		}

		if (config.getBoolean(MONITOR_NUM_RUNNING_FLUSHES)) {
			options.enableNumRunningFlushes();
		}

		if (config.getBoolean(MONITOR_ACTUAL_DELAYED_WRITE_RATE)) {
			options.enableActualDelayedWriteRate();
		}

		return options;
	}
818352
private String getConfigUrlHtml(Config config) {

        return "<br/>点击<a href='http://" + applicationPropertyConfig.getDomain() + "/modifyFile.html?configId=" +
                config.getId() + "'> 这里 </a> 进入查看<br/>";
    }
929669
public static void reconfigure(InputStream config) {
        if (CONTEXT == null) {
            log.warn("当前日志上下文不是logback，不能使用该配置器重新配置");
            return;
        }
        reconfigure(config, CONTEXT);
    }
1285054
private static GroupTemplate createEngine(TemplateConfig config) {
		if (null == config) {
			config = new TemplateConfig();
		}

		switch (config.getResourceMode()) {
		case CLASSPATH:
			return createGroupTemplate(new ClasspathResourceLoader(config.getPath(), config.getCharsetStr()));
		case FILE:
			return createGroupTemplate(new FileResourceLoader(config.getPath(), config.getCharsetStr()));
		case WEB_ROOT:
			return createGroupTemplate(new WebAppResourceLoader(config.getPath(), config.getCharsetStr()));
		case STRING:
			return createGroupTemplate(new StringTemplateResourceLoader());
		case COMPOSITE:
			//TODO 需要定义复合资源加载器
			return createGroupTemplate(new CompositeResourceLoader());
		default:
			return new GroupTemplate();
		}
	}
949646
@Override
	public void applyConfig(final ConfigSettings config)
	{

		Object o = config
				.getConfigParameter(ConfigurationKeys.LOGGING_PATH_DIFFTOOL);
		if (o != null) {
			this.diffToolField.setText((String) o);
		}
		else {
			this.diffToolField.setText("");
		}

		o = config
				.getConfigParameter(ConfigurationKeys.LOGGING_LOGLEVEL_DIFFTOOL);
		if (o != null) {
			this.diffToolLogLevelComboBox.setSelectedItem(o);
		}

	}
131910
public Config getTweakedConfig(Config config, String dbModuleName)
    {
        return Config.getOverriddenConfig(config,
                new MapConfiguration(getConfigurationTweak(dbModuleName)));
    }
8597
protected void subscribeConfig(final AbstractInterfaceConfig config, ConfigListener listener) {
        try {
            if (configObserver == null) { // 初始化
                configObserver = new ZookeeperConfigObserver();
            }
            configObserver.addConfigListener(config, listener);
            final String configPath = buildConfigPath(rootPath, config);
            // 监听配置节点下 子节点增加、子节点删除、子节点Data修改事件
            PathChildrenCache pathChildrenCache = new PathChildrenCache(zkClient, configPath, true);
            pathChildrenCache.getListenable().addListener(new PathChildrenCacheListener() {
                @Override
                public void childEvent(CuratorFramework client1, PathChildrenCacheEvent event) throws Exception {
                    if (LOGGER.isDebugEnabled(config.getAppName())) {
                        LOGGER.debug("Receive zookeeper event: " + "type=[" + event.getType() + "]");
                    }
                    switch (event.getType()) {
                        case CHILD_ADDED: //新增接口级配置
                            configObserver.addConfig(config, configPath, event.getData());
                            break;
                        case CHILD_REMOVED: //删除接口级配置
                            configObserver.removeConfig(config, configPath, event.getData());
                            break;
                        case CHILD_UPDATED:// 更新接口级配置
                            configObserver.updateConfig(config, configPath, event.getData());
                            break;
                        default:
                            break;
                    }
                }
            });
            pathChildrenCache.start(PathChildrenCache.StartMode.BUILD_INITIAL_CACHE);
            INTERFACE_CONFIG_CACHE.put(configPath, pathChildrenCache);
            configObserver.updateConfigAll(config, configPath, pathChildrenCache.getCurrentData());
        } catch (Exception e) {
            throw new SofaRpcRuntimeException("Failed to subscribe provider config from zookeeperRegistry!", e);
        }
    }
608959
public static Period getPeriod(Config config, String path) {
        try {
            return config.getPeriod(path);
        } catch (ConfigException.Missing | ConfigException.WrongType | ConfigException.BadValue e) {
            if (e instanceof ConfigException.WrongType || e instanceof ConfigException.BadValue) {
                LOGGER.warn(e.getMessage(), e);
            }
            return null;
        }
    }
1058513
public static ZabMessage.ClusterConfiguration
  buildConfig(ClusterConfiguration config) {
    ZabMessage.Zxid version = toProtoZxid(config.getVersion());
    return ZabMessage.ClusterConfiguration.newBuilder()
                                          .setVersion(version)
                                          .addAllServers(config.getPeers())
                                          .build();
  }
4280
public static org.apache.hadoop.mapred.JobConf asJobConf(Configuration cfg) {
        return cfg instanceof org.apache.hadoop.mapred.JobConf
            ? (org.apache.hadoop.mapred.JobConf) cfg
            : new org.apache.hadoop.mapred.JobConf(cfg);
    }
1003630
public static Xml exports(ProducibleConfig config)
    {
        Check.notNull(config);

        final Xml node = new Xml(NODE_PRODUCIBLE);
        node.writeInteger(ATT_STEPS, config.getSteps());

        return node;
    }
481150
public final BeanConfig getConfig() {
    if (null == config) {
      config = new BeanConfig(getClass().getName());
      doBinding();
    }
    return config;
  }