class LogSearchConfigFactory {

  public static LogSearchConfigLogFeeder createLogSearchConfigLogFeeder(Map<String, String> properties, String clusterName,
      Class<? extends LogSearchConfigLogFeeder> defaultClass, boolean init) throws Exception {
    try {
      LogSearchConfigLogFeeder logSearchConfig = null;
      String configClassName = properties.get("logsearch.config.logfeeder.class");
      if (configClassName != null && !"".equals(configClassName.trim())) {
        Class<?> clazz = Class.forName(configClassName);
        if (LogSearchConfig.class.isAssignableFrom(clazz)) {
          logSearchConfig = (LogSearchConfigLogFeeder) clazz.newInstance();
        } else {
          throw new IllegalArgumentException("Class " + configClassName + " does not implement the interface " +
              LogSearchConfigLogFeeder.class.getName());
        }
      } else {
        logSearchConfig = defaultClass.newInstance();
      }
      if (init) {
        logSearchConfig.init(properties, clusterName == null ? "null" : clusterName.toLowerCase());
      }
      return logSearchConfig;
    } catch (Exception e) {
      LOG.error("Could not initialize logsearch config.", e);
      throw e;
    }
  }

}