org.apache.solr.util.plugin.PluginInfoInitialized Java Examples
The following examples show how to use
org.apache.solr.util.plugin.PluginInfoInitialized.
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: MetricSuppliers.java From lucene-solr with Apache License 2.0 | 6 votes |
/** * 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 #2
Source File: MetricSuppliers.java From lucene-solr with Apache License 2.0 | 6 votes |
/** * 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 #3
Source File: MetricSuppliers.java From lucene-solr with Apache License 2.0 | 6 votes |
/** * 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 #4
Source File: MetricSuppliers.java From lucene-solr with Apache License 2.0 | 6 votes |
/** * 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 #5
Source File: ShardHandlerFactory.java From lucene-solr with Apache License 2.0 | 6 votes |
/** * Create a new ShardHandlerFactory instance * @param info a PluginInfo object defining which type to create. If null, * the default {@link HttpShardHandlerFactory} will be used * @param loader a SolrResourceLoader used to find the ShardHandlerFactory classes * @return a new, initialized ShardHandlerFactory instance */ public static ShardHandlerFactory newInstance(PluginInfo info, SolrResourceLoader loader) { if (info == null) info = DEFAULT_SHARDHANDLER_INFO; try { ShardHandlerFactory shf = loader.findClass(info.className, ShardHandlerFactory.class).getConstructor().newInstance(); if (PluginInfoInitialized.class.isAssignableFrom(shf.getClass())) PluginInfoInitialized.class.cast(shf).init(info); return shf; } catch (Exception e) { throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, String.format(Locale.ROOT, "Error instantiating shardHandlerFactory class [%s]: %s", info.className, e.getMessage()), e); } }
Example #6
Source File: TransientSolrCoreCacheFactory.java From lucene-solr with Apache License 2.0 | 6 votes |
/** * Create a new TransientSolrCoreCacheFactory instance * * @param loader a SolrResourceLoader used to find the TransientSolrCacheFactory classes * @param coreContainer CoreContainer that encloses all the Solr cores. * @return a new, initialized TransientSolrCoreCache instance */ public static TransientSolrCoreCacheFactory newInstance(SolrResourceLoader loader, CoreContainer coreContainer) { PluginInfo info = coreContainer.getConfig().getTransientCachePluginInfo(); if (info == null) { // definition not in our solr.xml file, use default info = DEFAULT_TRANSIENT_SOLR_CACHE_INFO; } try { // According to the docs, this returns a TransientSolrCoreCacheFactory with the default c'tor TransientSolrCoreCacheFactory tccf = loader.findClass(info.className, TransientSolrCoreCacheFactory.class).getConstructor().newInstance(); // OK, now we call it's init method. if (PluginInfoInitialized.class.isAssignableFrom(tccf.getClass())) PluginInfoInitialized.class.cast(tccf).init(info); tccf.setCoreContainer(coreContainer); return tccf; } catch (Exception e) { // Many things could cuse this, bad solrconfig, mis-typed class name, whatever. However, this should not // keep the enclosing coreContainer from instantiating, so log an error and continue. log.error(String.format(Locale.ROOT, "Error instantiating TransientSolrCoreCacheFactory class [%s]: %s", info.className, e.getMessage())); return null; } }
Example #7
Source File: PluginBag.java From lucene-solr with Apache License 2.0 | 6 votes |
public static void initInstance(Object inst, PluginInfo info) { if (inst instanceof PluginInfoInitialized) { ((PluginInfoInitialized) inst).init(info); } else if (inst instanceof NamedListInitializedPlugin) { ((NamedListInitializedPlugin) inst).init(info.initArgs); } else if (inst instanceof SolrRequestHandler) { ((SolrRequestHandler) inst).init(info.initArgs); } if (inst instanceof SearchComponent) { ((SearchComponent) inst).setName(info.name); } if (inst instanceof RequestHandlerBase) { ((RequestHandlerBase) inst).setPluginInfo(info); } }
Example #8
Source File: SolrCore.java From lucene-solr with Apache License 2.0 | 5 votes |
public <T extends Object> T createInitInstance(PluginInfo info, Class<T> cast, String msg, String defClassName) { if (info == null) return null; T o = createInstance(info.className == null ? defClassName : info.className, cast, msg, this, getResourceLoader(info.pkgName)); if (o instanceof PluginInfoInitialized) { ((PluginInfoInitialized) o).init(info); } else if (o instanceof NamedListInitializedPlugin) { ((NamedListInitializedPlugin) o).init(info.initArgs); } if (o instanceof SearchComponent) { ((SearchComponent) o).setName(info.name); } return o; }
Example #9
Source File: MetricSuppliers.java From lucene-solr with Apache License 2.0 | 4 votes |
@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); } } }