Java Code Examples for org.apache.solr.util.SolrPluginUtils#invokeSetters()

The following examples show how to use org.apache.solr.util.SolrPluginUtils#invokeSetters() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SolrMetricReporter.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
/**
 * Initializes a {@link SolrMetricReporter} with the plugin's configuration.
 *
 * @param pluginInfo the plugin's configuration
 */
@SuppressWarnings("unchecked")
public void init(PluginInfo pluginInfo) {
  if (pluginInfo != null) {
    this.pluginInfo = pluginInfo.copy();
    if (this.pluginInfo.initArgs != null) {
      SolrPluginUtils.invokeSetters(this, this.pluginInfo.initArgs);
    }
  }
  validate();
  if (!enabled) {
    log.info("Reporter disabled for registry {}", registryName);
    return;
  }
  log.debug("Initializing for registry {}", registryName);
  doInit();
}
 
Example 2
Source File: LTRScoringModel.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings({"rawtypes"})
public static LTRScoringModel getInstance(SolrResourceLoader solrResourceLoader,
    String className, String name, List<Feature> features,
    List<Normalizer> norms,
    String featureStoreName, List<Feature> allFeatures,
    Map<String,Object> params) throws ModelException {
  final LTRScoringModel model;
  try {
    // create an instance of the model
    model = solrResourceLoader.newInstance(
        className,
        LTRScoringModel.class,
        new String[0], // no sub packages
        new Class[] { String.class, List.class, List.class, String.class, List.class, Map.class },
        new Object[] { name, features, norms, featureStoreName, allFeatures, params });
    if (params != null) {
      SolrPluginUtils.invokeSetters(model, params.entrySet());
    }
  } catch (final Exception e) {
    throw new ModelException("Model type does not exist " + className, e);
  }
  model.validate();
  return model;
}
 
Example 3
Source File: MetricSuppliers.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
/**
 * Create a {@link Histogram} supplier.
 * @param info plugin configuration, or null for default
 * @return configured supplier instance, or default instance if configuration was invalid
 */
@SuppressWarnings({"unchecked"})
public static MetricRegistry.MetricSupplier<Histogram> histogramSupplier(SolrResourceLoader loader, PluginInfo info) {
  MetricRegistry.MetricSupplier<Histogram> supplier;
  if (info == null || info.className == null || info.className.isEmpty()) {
    supplier = new DefaultHistogramSupplier(loader);
  } else {
    try {
      supplier = loader.newInstance(info.className, MetricRegistry.MetricSupplier.class);
    } catch (Exception e) {
      log.warn("Error creating custom Histogram supplier (will use default): {}", info, e);
      supplier = new DefaultHistogramSupplier(loader);
    }
  }
  if (supplier instanceof PluginInfoInitialized) {
    ((PluginInfoInitialized)supplier).init(info);
  } else {
    SolrPluginUtils.invokeSetters(supplier, info.initArgs, true);
  }
  return supplier;
}
 
Example 4
Source File: MetricSuppliers.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
/**
 * Create a {@link Timer} supplier.
 * @param loader resource loader
 * @param info plugin configuration, or null for default
 * @return configured supplier instance, or default instance if configuration was invalid
 */
@SuppressWarnings({"unchecked"})
public static MetricRegistry.MetricSupplier<Timer> timerSupplier(SolrResourceLoader loader, PluginInfo info) {
  MetricRegistry.MetricSupplier<Timer> supplier;
  if (info == null || info.className == null || info.className.isEmpty()) {
    supplier = new DefaultTimerSupplier(loader);
  } else {
    try {
      supplier = loader.newInstance(info.className, MetricRegistry.MetricSupplier.class);
    } catch (Exception e) {
      log.warn("Error creating custom Timer supplier (will use default): {}", info, e);
      supplier = new DefaultTimerSupplier(loader);
    }
  }
  if (supplier instanceof PluginInfoInitialized) {
    ((PluginInfoInitialized)supplier).init(info);
  } else {
    SolrPluginUtils.invokeSetters(supplier, info.initArgs, true);
  }
  return supplier;
}
 
Example 5
Source File: MetricSuppliers.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
/**
 * Create a {@link Meter} supplier.
 * @param loader resource loader
 * @param info plugin configuration, or null for default
 * @return configured supplier instance, or default instance if configuration was invalid
 */
@SuppressWarnings({"unchecked"})
public static MetricRegistry.MetricSupplier<Meter> meterSupplier(SolrResourceLoader loader, PluginInfo info) {
  MetricRegistry.MetricSupplier<Meter> supplier;
  if (info == null || info.className == null || info.className.isEmpty()) {
    supplier = new DefaultMeterSupplier();
  } else {
    try {
      supplier = loader.newInstance(info.className, MetricRegistry.MetricSupplier.class);
    } catch (Exception e) {
      log.warn("Error creating custom Meter supplier (will use default): {}",info, e);
      supplier = new DefaultMeterSupplier();
    }
  }
  if (supplier instanceof PluginInfoInitialized) {
    ((PluginInfoInitialized)supplier).init(info);
  } else {
    SolrPluginUtils.invokeSetters(supplier, info.initArgs, true);
  }
  return supplier;
}
 
Example 6
Source File: MetricSuppliers.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
/**
 * Create a {@link Counter} supplier.
 * @param loader resource loader
 * @param info plugin configuration, or null for default
 * @return configured supplier instance, or default instance if configuration was invalid
 */
@SuppressWarnings({"unchecked"})
public static MetricRegistry.MetricSupplier<Counter> counterSupplier(SolrResourceLoader loader, PluginInfo info) {
  if (info == null || info.className == null || info.className.trim().isEmpty()) {
    return new DefaultCounterSupplier();
  }

  MetricRegistry.MetricSupplier<Counter> supplier;
  try {
    supplier = loader.newInstance(info.className, MetricRegistry.MetricSupplier.class);
  } catch (Exception e) {
    log.warn("Error creating custom Counter supplier (will use default): {}", info, e);
    supplier = new DefaultCounterSupplier();
  }
  if (supplier instanceof PluginInfoInitialized) {
    ((PluginInfoInitialized)supplier).init(info);
  } else {
    SolrPluginUtils.invokeSetters(supplier, info.initArgs, true);
  }
  return supplier;
}
 
Example 7
Source File: TestNeuralNetworkModel.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@Override
@SuppressWarnings({"unchecked"})
protected Layer createLayer(Object o) {
  final DefaultLayer layer = new DefaultLayer();
  if (o != null) {
    SolrPluginUtils.invokeSetters(layer, ((Map<String,Object>) o).entrySet());
  }
  return layer;
}
 
Example 8
Source File: RecoveryStrategy.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings({"unchecked"})
public RecoveryStrategy create(CoreContainer cc, CoreDescriptor cd,
    RecoveryStrategy.RecoveryListener recoveryListener) {
  final RecoveryStrategy recoveryStrategy = newRecoveryStrategy(cc, cd, recoveryListener);
  SolrPluginUtils.invokeSetters(recoveryStrategy, args);
  return recoveryStrategy;
}
 
Example 9
Source File: SolrIndexConfig.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings({"unchecked"})
private MergeScheduler buildMergeScheduler(SolrResourceLoader resourceLoader) {
  String msClassName = mergeSchedulerInfo == null ? SolrIndexConfig.DEFAULT_MERGE_SCHEDULER_CLASSNAME : mergeSchedulerInfo.className;
  MergeScheduler scheduler = resourceLoader.newInstance(msClassName, MergeScheduler.class);

  if (mergeSchedulerInfo != null) {
    // LUCENE-5080: these two setters are removed, so we have to invoke setMaxMergesAndThreads
    // if someone has them configured.
    if (scheduler instanceof ConcurrentMergeScheduler) {
      @SuppressWarnings({"rawtypes"})
      NamedList args = mergeSchedulerInfo.initArgs.clone();
      Integer maxMergeCount = (Integer) args.remove("maxMergeCount");
      if (maxMergeCount == null) {
        maxMergeCount = ((ConcurrentMergeScheduler) scheduler).getMaxMergeCount();
      }
      Integer maxThreadCount = (Integer) args.remove("maxThreadCount");
      if (maxThreadCount == null) {
        maxThreadCount = ((ConcurrentMergeScheduler) scheduler).getMaxThreadCount();
      }
      ((ConcurrentMergeScheduler)scheduler).setMaxMergesAndThreads(maxMergeCount, maxThreadCount);
      Boolean ioThrottle = (Boolean) args.remove("ioThrottle");
      if (ioThrottle != null && !ioThrottle) { //by-default 'enabled'
          ((ConcurrentMergeScheduler) scheduler).disableAutoIOThrottle();
      }
      SolrPluginUtils.invokeSetters(scheduler, args);
    } else {
      SolrPluginUtils.invokeSetters(scheduler, mergeSchedulerInfo.initArgs);
    }
  }

  return scheduler;
}
 
Example 10
Source File: Feature.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings({"rawtypes"})
public static Feature getInstance(SolrResourceLoader solrResourceLoader,
    String className, String name, Map<String,Object> params) {
  final Feature f = solrResourceLoader.newInstance(
      className,
      Feature.class,
      new String[0], // no sub packages
      new Class[] { String.class, Map.class },
      new Object[] { name, params });
  if (params != null) {
    SolrPluginUtils.invokeSetters(f, params.entrySet());
  }
  f.validate();
  return f;
}
 
Example 11
Source File: LTRThreadModule.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@Override
@SuppressWarnings({"unchecked"})
public void init(@SuppressWarnings({"rawtypes"})NamedList args) {
  if (args != null) {
    SolrPluginUtils.invokeSetters(this, args);
  }
  validate();
  if  (this.totalPoolThreads > 1 ){
    ltrSemaphore = new Semaphore(totalPoolThreads);
  } else {
    ltrSemaphore = null;
  }
}
 
Example 12
Source File: NeuralNetworkModel.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings({"unchecked"})
protected Layer createLayer(Object o) {
  final DefaultLayer layer = new DefaultLayer();
  if (o != null) {
    SolrPluginUtils.invokeSetters(layer, ((Map<String,Object>) o).entrySet());
  }
  return layer;
}
 
Example 13
Source File: MultipleAdditiveTreesModel.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
private RegressionTreeNode createRegressionTreeNode(Map<String,Object> map) {
  final RegressionTreeNode rtn = new RegressionTreeNode();
  if (map != null) {
    SolrPluginUtils.invokeSetters(rtn, map.entrySet());
  }
  return rtn;
}
 
Example 14
Source File: MultipleAdditiveTreesModel.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
private RegressionTree createRegressionTree(Map<String,Object> map) {
  final RegressionTree rt = new RegressionTree();
  if (map != null) {
    SolrPluginUtils.invokeSetters(rt, map.entrySet());
  }
  return rt;
}
 
Example 15
Source File: LTRQParserPlugin.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@Override
@SuppressWarnings({"unchecked"})
public void init(@SuppressWarnings("rawtypes") NamedList args) {
  super.init(args);
  threadManager = LTRThreadModule.getInstance(args);
  SolrPluginUtils.invokeSetters(this, args);
}
 
Example 16
Source File: LTRFeatureLoggerTransformerFactory.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@Override
@SuppressWarnings({"unchecked"})
public void init(@SuppressWarnings("rawtypes") NamedList args) {
  super.init(args);
  threadManager = LTRThreadModule.getInstance(args);
  SolrPluginUtils.invokeSetters(this, args);
}
 
Example 17
Source File: Normalizer.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
public static Normalizer getInstance(SolrResourceLoader solrResourceLoader,
    String className, Map<String,Object> params) {
  final Normalizer f = solrResourceLoader.newInstance(className, Normalizer.class);
  if (params != null) {
    SolrPluginUtils.invokeSetters(f, params.entrySet());
  }
  f.validate();
  return f;
}
 
Example 18
Source File: MetricSuppliers.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings({"unchecked"})
private static final Reservoir getReservoir(SolrResourceLoader loader, PluginInfo info) {
  if (info == null) {
    return new ExponentiallyDecayingReservoir();
  }
  Clock clk = getClock(info, CLOCK);
  String clazz = ExponentiallyDecayingReservoir.class.getName();
  int size = -1;
  double alpha = -1;
  long window = -1;
  if (info.initArgs != null) {
    if (info.initArgs.get(RESERVOIR) != null) {
      String val = String.valueOf(info.initArgs.get(RESERVOIR)).trim();
      if (!val.isEmpty()) {
        clazz = val;
      }
    }
    Number n = (Number)info.initArgs.get(RESERVOIR_SIZE);
    if (n != null) {
      size = n.intValue();
    }
    n = (Number)info.initArgs.get(RESERVOIR_EDR_ALPHA);
    if (n != null) {
      alpha = n.doubleValue();
    }
    n = (Number)info.initArgs.get(RESERVOIR_WINDOW);
    if (n != null) {
      window = n.longValue();
    }
  }
  if (size <= 0) {
    size = DEFAULT_SIZE;
  }
  if (alpha <= 0) {
    alpha = DEFAULT_ALPHA;
  }
  // special case for core implementations
  if (clazz.equals(EDR_CLAZZ)) {
    return new ExponentiallyDecayingReservoir(size, alpha, clk);
  } else if (clazz.equals(UNI_CLAZZ)) {
    return new UniformReservoir(size);
  } else if (clazz.equals(STW_CLAZZ)) {
    if (window <= 0) {
      window = DEFAULT_WINDOW; // 5 minutes, comparable to EDR
    }
    return new SlidingTimeWindowReservoir(window, TimeUnit.SECONDS);
  } else if (clazz.equals(SW_CLAZZ)) {
    return new SlidingWindowReservoir(size);
  } else { // custom reservoir
    Reservoir reservoir;
    try {
      reservoir = loader.newInstance(clazz, Reservoir.class);
      if (reservoir instanceof PluginInfoInitialized) {
        ((PluginInfoInitialized)reservoir).init(info);
      } else {
        SolrPluginUtils.invokeSetters(reservoir, info.initArgs, true);
      }
      return reservoir;
    } catch (Exception e) {
      log.warn("Error initializing custom Reservoir implementation (will use default): {}", info, e);
      return new ExponentiallyDecayingReservoir(size, alpha, clk);
    }
  }
}
 
Example 19
Source File: MergePolicyFactoryArgs.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
public void invokeSetters(MergePolicy policy) {
  SolrPluginUtils.invokeSetters(policy, args.entrySet());
}