Package org.apache.solr.core
Class SolrResourceLoader
java.lang.Object
org.apache.solr.core.SolrResourceLoader
- All Implemented Interfaces:
Closeable,AutoCloseable,org.apache.lucene.util.ResourceLoader,org.apache.solr.common.cloud.SolrClassLoader,SolrCoreAware
- Direct Known Subclasses:
ZkSolrResourceLoader
public class SolrResourceLoader
extends Object
implements org.apache.lucene.util.ResourceLoader, Closeable, org.apache.solr.common.cloud.SolrClassLoader, SolrCoreAware
- Since:
- solr 1.3
-
Nested Class Summary
Nested Classes -
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionSolrResourceLoader(String name, List<Path> classpath, Path instanceDir, ClassLoader parent) Creates a loader.SolrResourceLoader(Path instanceDir) Creates a loader.SolrResourceLoader(Path instanceDir, ClassLoader parent) This loader will delegate to Solr's classloader when possible, otherwise it will attempt to resolve resources using any jar files found in the "lib/" directory in the specified instance directory. -
Method Summary
Modifier and TypeMethodDescription<T> booleanaddToCoreAware(T obj) the inform() callback should be invoked on the listener.<T> voidaddToInfoBeans(T obj) <T> booleanaddToResourceLoaderAware(T obj) static Class<?> assertAwareCompatibility(Class<?> aware, Object obj) Utility function to throw an exception if the class is invalidvoidclose()<T> Class<? extends T> <T> Class<? extends T> This method loads a class either with its FQN or a short-name (solr.class-simplename or class-simplename).<T> Class<? extends T> findClass(PluginInfo info, Class<T> type, boolean registerCoreReloadListener) Load a class using an appropriateSolrResourceLoaderdepending of the package on that classEXPERTgetFilteredURLs(Path libDir, String regex) Utility method to get the URLs of all paths under a given directory that match a regexThe instance path for this resource loader, as passed in from the constructor.Accesses a resource by name and returns the (non comment) lines containing data.Accesses a resource by name and returns the (non comment) lines containing data using the given character encoding.org.apache.solr.common.cloud.SolrClassLoaderUtility method to get the URLs of all paths under a given directorygetURLs(Path libDir, DirectoryStream.Filter<Path> filter) Utility method to get the URLs of all paths under a given directory that match a filtervoidinform(Map<String, SolrInfoBean> infoRegistry) Register anySolrInfoBeansvoidinform(org.apache.lucene.util.ResourceLoader loader) Tell allResourceLoaderAwareinstances about the loadervoidTell allSolrCoreAwareinstances about the SolrCorestatic voidinformAware(org.apache.lucene.util.ResourceLoader loader, org.apache.lucene.util.ResourceLoaderAware aware) Set the currentResourceLoaderAwareobject in thread local so that appropriate classloader can be used for package loaded classes<T> TnewInstance(String name, Class<T> expectedType) <T> TnewInstance(String cname, Class<T> expectedType, String... subpackages) <T> TnewInstance(String cName, Class<T> expectedType, String[] subPackages, Class<?>[] params, Object[] args) <T> TnewInstance(PluginInfo info, Class<T> type, boolean registerCoreReloadListener) Create an instance of a class using an appropriateSolrResourceLoaderdepending on the package of that classopenResource(String resource) Opens any resource by its name.static voidpersistConfLocally(SolrResourceLoader loader, String resourceName, byte[] content) resourceLocation(String resource) Report the location of a resource found by the resource loaderprotected final voidsetCoreContainer(CoreContainer coreContainer) protected final voidsetSolrConfig(SolrConfig config) protected final voidsetSolrCore(SolrCore core)
-
Field Details
-
SOLR_RESOURCELOADING_RESTRICTED_ENABLED_PARAM
- See Also:
-
classLoader
-
-
Constructor Details
-
SolrResourceLoader
Creates a loader. Note: we do NOT callreloadLuceneSPI(). -
SolrResourceLoader
Creates a loader.- Parameters:
instanceDir- - base directory for this resource loader, must not be null
-
SolrResourceLoader
This loader will delegate to Solr's classloader when possible, otherwise it will attempt to resolve resources using any jar files found in the "lib/" directory in the specified instance directory.
-
-
Method Details
-
getManagedResourceRegistry
-
getSchemaLoader
public org.apache.solr.common.cloud.SolrClassLoader getSchemaLoader() -
getURLs
public static List<URL> getURLs(Path libDir, DirectoryStream.Filter<Path> filter) throws IOException Utility method to get the URLs of all paths under a given directory that match a filter- Parameters:
libDir- the root directoryfilter- the filter- Returns:
- all matching URLs
- Throws:
IOException- on error
-
getURLs
Utility method to get the URLs of all paths under a given directory- Parameters:
libDir- the root directory- Returns:
- all subdirectories as URLs
- Throws:
IOException- on error
-
getFilteredURLs
Utility method to get the URLs of all paths under a given directory that match a regex- Parameters:
libDir- the root directoryregex- the regex as a String- Returns:
- all matching URLs
- Throws:
IOException- on error
-
getConfigPath
-
getClassLoader
EXPERTThe underlying class loader. Most applications will not need to use this.
- Returns:
- The
ClassLoader
-
openResource
Opens any resource by its name. By default, this will look in multiple locations to load the resource: $configDir/$resource (if resource is not absolute) $CWD/$resource otherwise, it will look for it in any jar accessible through the class loader. Override this method to customize loading resources.- Specified by:
openResourcein interfaceorg.apache.lucene.util.ResourceLoader- Returns:
- the stream for the named resource
- Throws:
IOException
-
resourceLocation
Report the location of a resource found by the resource loader -
getLines
Accesses a resource by name and returns the (non comment) lines containing data.A comment line is any line that starts with the character "#"
- Returns:
- a list of non-blank non-comment lines with whitespace trimmed from front and back.
- Throws:
IOException- If there is a low-level I/O error.
-
getLines
Accesses a resource by name and returns the (non comment) lines containing data using the given character encoding.A comment line is any line that starts with the character "#"
- Parameters:
resource- the file to be read- Returns:
- a list of non-blank non-comment lines with whitespace trimmed
- Throws:
IOException- If there is a low-level I/O error.
-
getLines
- Throws:
IOException
-
findClass
- Specified by:
findClassin interfaceorg.apache.lucene.util.ResourceLoader- Specified by:
findClassin interfaceorg.apache.solr.common.cloud.SolrClassLoader
-
findClass
This method loads a class either with its FQN or a short-name (solr.class-simplename or class-simplename). It tries to load the class with the name that is given first and if it fails, it tries all the known solr packages. This method caches the FQN of a short-name in a static map in-order to make subsequent lookups for the same class faster. The caching is done only if the class is loaded by the webapp classloader and it is loaded using a shortname.- Parameters:
cname- The name or the short name of the class.subpackages- the packages to be tried if the cname starts with solr.- Returns:
- the loaded class. An exception is thrown if it fails
-
newInstance
- Specified by:
newInstancein interfaceorg.apache.lucene.util.ResourceLoader
-
newInstance
- Specified by:
newInstancein interfaceorg.apache.solr.common.cloud.SolrClassLoader
-
newInstance
public <T> T newInstance(String cName, Class<T> expectedType, String[] subPackages, Class<?>[] params, Object[] args) - Specified by:
newInstancein interfaceorg.apache.solr.common.cloud.SolrClassLoader
-
addToInfoBeans
public <T> void addToInfoBeans(T obj) -
addToResourceLoaderAware
public <T> boolean addToResourceLoaderAware(T obj) -
addToCoreAware
public <T> boolean addToCoreAware(T obj) the inform() callback should be invoked on the listener. If this is 'live', the callback is not called so currently this returns 'false' -
setSolrConfig
-
setCoreContainer
-
setSolrCore
-
inform
Tell allSolrCoreAwareinstances about the SolrCore- Specified by:
informin interfaceSolrCoreAware
-
inform
Tell allResourceLoaderAwareinstances about the loader- Throws:
IOException
-
informAware
public static void informAware(org.apache.lucene.util.ResourceLoader loader, org.apache.lucene.util.ResourceLoaderAware aware) throws IOException Set the currentResourceLoaderAwareobject in thread local so that appropriate classloader can be used for package loaded classes- Throws:
IOException
-
inform
Register anySolrInfoBeans- Parameters:
infoRegistry- The Info Registry
-
getInstancePath
The instance path for this resource loader, as passed in from the constructor. It's absolute when this is for Solr Home or a Solr Core instance dir. -
assertAwareCompatibility
Utility function to throw an exception if the class is invalid -
getCoreContainer
-
getSolrConfig
-
close
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Throws:
IOException
-
getInfoMBeans
-
findClass
public <T> Class<? extends T> findClass(PluginInfo info, Class<T> type, boolean registerCoreReloadListener) Load a class using an appropriateSolrResourceLoaderdepending of the package on that class- Parameters:
registerCoreReloadListener- register a listener for the package and reload the core if the package is changed. Use this sparingly. This will result in core reloads across all the cores in all collections using this configset
-
newInstance
Create an instance of a class using an appropriateSolrResourceLoaderdepending on the package of that class- Parameters:
registerCoreReloadListener- register a listener for the package and reload the core if the package is changed. Use this sparingly. This will result in core reloads across all the cores in all collections using this configset
-
persistConfLocally
public static void persistConfLocally(SolrResourceLoader loader, String resourceName, byte[] content)
-