/** * Tell all {@link ResourceLoaderAware} instances about the loader */ public void inform( ResourceLoader loader ) throws IOException { // make a copy to avoid potential deadlock of a callback adding to the list ResourceLoaderAware[] arr; while (waitingForResources.size() > 0) { synchronized (waitingForResources) { arr = waitingForResources.toArray(new ResourceLoaderAware[waitingForResources.size()]); waitingForResources.clear(); } for( ResourceLoaderAware aware : arr) { aware.inform(loader); } } }
public static <T> T createFactory(final String className, final Map<String, String> baseArgs, final ResourceLoader loader) { if (VERBOSE) { System.out.println("Create " + className + " with " + baseArgs); // NOSONAR } try { @SuppressWarnings("unchecked") final Class<? extends T> clazz = (Class<? extends T>) Class .forName(className); final Constructor<? extends T> constructor = clazz .getConstructor(Map.class); final T factory = constructor .newInstance(new HashMap<String, String>(baseArgs)); if (loader != null && factory instanceof ResourceLoaderAware) { ((ResourceLoaderAware) factory).inform(loader); } return factory; } catch (final Exception e) { throw new IllegalArgumentException( "Invalid parameters to create TokenizerFactory.", e); } }
public <T> T newInstance(String cname, Class<T> expectedType, String ... subpackages) { Class<? extends T> clazz = findClass(cname, expectedType, subpackages); if( clazz == null ) { throw new SolrException( SolrException.ErrorCode.SERVER_ERROR, "Can not find class: "+cname + " in " + classLoader); } T obj = null; try { obj = clazz.newInstance(); } catch (Exception e) { throw new SolrException( SolrException.ErrorCode.SERVER_ERROR, "Error instantiating class: '" + clazz.getName()+"'", e); } if (!live) { if( obj instanceof SolrCoreAware ) { assertAwareCompatibility( SolrCoreAware.class, obj ); waitingForCore.add( (SolrCoreAware)obj ); } if (org.apache.solr.util.plugin.ResourceLoaderAware.class.isInstance(obj)) { log.warn("Class [{}] uses org.apache.solr.util.plugin.ResourceLoaderAware " + "which is deprecated. Change to org.apache.lucene.analysis.util.ResourceLoaderAware.", cname); } if( obj instanceof ResourceLoaderAware ) { assertAwareCompatibility( ResourceLoaderAware.class, obj ); waitingForResources.add( (ResourceLoaderAware)obj ); } if (obj instanceof SolrInfoMBean){ //TODO: Assert here? infoMBeans.add((SolrInfoMBean) obj); } } return obj; }
public CoreAdminHandler newAdminHandlerInstance(final CoreContainer coreContainer, String cname, String ... subpackages) { Class<? extends CoreAdminHandler> clazz = findClass(cname, CoreAdminHandler.class, subpackages); if( clazz == null ) { throw new SolrException( SolrException.ErrorCode.SERVER_ERROR, "Can not find class: "+cname + " in " + classLoader); } CoreAdminHandler obj = null; try { Constructor<? extends CoreAdminHandler> ctor = clazz.getConstructor(CoreContainer.class); obj = ctor.newInstance(coreContainer); } catch (Exception e) { throw new SolrException( SolrException.ErrorCode.SERVER_ERROR, "Error instantiating class: '" + clazz.getName()+"'", e); } if (!live) { //TODO: Does SolrCoreAware make sense here since in a multi-core context // which core are we talking about ? if (org.apache.solr.util.plugin.ResourceLoaderAware.class.isInstance(obj)) { log.warn("Class [{}] uses org.apache.solr.util.plugin.ResourceLoaderAware " + "which is deprecated. Change to org.apache.lucene.analysis.util.ResourceLoaderAware.", cname); } if( obj instanceof ResourceLoaderAware ) { assertAwareCompatibility( ResourceLoaderAware.class, obj ); waitingForResources.add( (ResourceLoaderAware)obj ); } } return obj; }
public <T> T newInstance(String cName, Class<T> expectedType, String [] subPackages, Class[] params, Object[] args){ Class<? extends T> clazz = findClass(cName, expectedType, subPackages); if( clazz == null ) { throw new SolrException( SolrException.ErrorCode.SERVER_ERROR, "Can not find class: "+cName + " in " + classLoader); } T obj = null; try { Constructor<? extends T> constructor = clazz.getConstructor(params); obj = constructor.newInstance(args); } catch (Exception e) { throw new SolrException( SolrException.ErrorCode.SERVER_ERROR, "Error instantiating class: '" + clazz.getName()+"'", e); } if (!live) { if( obj instanceof SolrCoreAware ) { assertAwareCompatibility( SolrCoreAware.class, obj ); waitingForCore.add( (SolrCoreAware)obj ); } if (org.apache.solr.util.plugin.ResourceLoaderAware.class.isInstance(obj)) { log.warn("Class [{}] uses org.apache.solr.util.plugin.ResourceLoaderAware " + "which is deprecated. Change to org.apache.lucene.analysis.util.ResourceLoaderAware.", cName); } if( obj instanceof ResourceLoaderAware ) { assertAwareCompatibility( ResourceLoaderAware.class, obj ); waitingForResources.add( (ResourceLoaderAware)obj ); } if (obj instanceof SolrInfoMBean){ //TODO: Assert here? infoMBeans.add((SolrInfoMBean) obj); } } return obj; }
@Override public void inform(final ResourceLoader loader) throws IOException { this.loader = loader; final Map<String, String> monitorArgs = MonitoringUtil .createMonitorArgs(baseArgs); baseClass = MonitoringUtil.initBaseArgs(baseArgs, luceneMatchVersion.toString()); baseTokenFilterFactory = MonitoringUtil.createFactory(baseClass, baseArgs, loader); factoryTimestamp = System.currentTimeMillis(); monitoringTask = MonitoringUtil.createMonitoringTask(monitorArgs, loader, new MonitoringTask.Callback() { @Override public void process() { baseTokenFilterFactory = MonitoringUtil.createFactory( baseClass, baseArgs, loader); factoryTimestamp = System.currentTimeMillis(); } }); if (baseTokenFilterFactory instanceof ResourceLoaderAware) { ((ResourceLoaderAware) baseTokenFilterFactory).inform(loader); } }
@Override public void inform(final ResourceLoader loader) throws IOException { this.loader = loader; final Map<String, String> monitorArgs = MonitoringUtil .createMonitorArgs(baseArgs); baseClass = MonitoringUtil.initBaseArgs(baseArgs, luceneMatchVersion.toString()); baseTokenizerFactory = MonitoringUtil.createFactory(baseClass, baseArgs, loader); factoryTimestamp = System.currentTimeMillis(); monitoringFileTask = MonitoringUtil.createMonitoringTask(monitorArgs, loader, new MonitoringTask.Callback() { @Override public void process() { baseTokenizerFactory = MonitoringUtil.createFactory( baseClass, baseArgs, loader); factoryTimestamp = System.currentTimeMillis(); } }); if (baseTokenizerFactory instanceof ResourceLoaderAware) { ((ResourceLoaderAware) baseTokenizerFactory).inform(loader); } }
@Override public void inform(ResourceLoader loader) throws IOException { ((ResourceLoaderAware) delegator).inform(loader); }