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 Modifier and Type Class Description static class
SolrResourceLoader.SolrFileInputStream
-
Field Summary
Fields Modifier and Type Field Description protected URLClassLoader
classLoader
static String
SOLR_ALLOW_UNSAFE_RESOURCELOADING_PARAM
-
Constructor Summary
Constructors Constructor Description SolrResourceLoader(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
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description <T> boolean
addToCoreAware(T obj)
the inform() callback should be invoked on the listener.<T> void
addToInfoBeans(T obj)
<T> boolean
addToResourceLoaderAware(T obj)
static Class<?>
assertAwareCompatibility(Class<?> aware, Object obj)
Utility function to throw an exception if the class is invalidvoid
close()
<T> Class<? extends T>
findClass(String cname, Class<T> expectedType)
<T> Class<? extends T>
findClass(String cname, Class<T> expectedType, String... subpackages)
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 appropriateSolrResourceLoader
depending of the package on that classClassLoader
getClassLoader()
EXPERTString
getConfigDir()
Deprecated.usegetConfigPath()
Path
getConfigPath()
CoreContainer
getCoreContainer()
static List<URL>
getFilteredURLs(Path libDir, String regex)
Utility method to get the URLs of all paths under a given directory that match a regexList<SolrInfoBean>
getInfoMBeans()
Path
getInstancePath()
The instance path for this resource loader, as passed in from the constructor.List<String>
getLines(String resource)
Accesses a resource by name and returns the (non comment) lines containing data.List<String>
getLines(String resource, String encoding)
Accesses a resource by name and returns the (non comment) lines containing data using the given character encoding.List<String>
getLines(String resource, Charset charset)
RestManager.Registry
getManagedResourceRegistry()
org.apache.solr.common.cloud.SolrClassLoader
getSchemaLoader()
SolrConfig
getSolrConfig()
static List<URL>
getURLs(Path libDir)
Utility method to get the URLs of all paths under a given directorystatic List<URL>
getURLs(Path libDir, DirectoryStream.Filter<Path> filter)
Utility method to get the URLs of all paths under a given directory that match a filtervoid
inform(Map<String,SolrInfoBean> infoRegistry)
Register anySolrInfoBean
svoid
inform(org.apache.lucene.util.ResourceLoader loader)
Tell allResourceLoaderAware
instances about the loadervoid
inform(SolrCore core)
Tell allSolrCoreAware
instances about the SolrCorestatic void
informAware(org.apache.lucene.util.ResourceLoader loader, org.apache.lucene.util.ResourceLoaderAware aware)
Set the currentResourceLoaderAware
object in thread local so that appropriate classloader can be used for package loaded classes<T> T
newInstance(String name, Class<T> expectedType)
<T> T
newInstance(String cname, Class<T> expectedType, String... subpackages)
<T> T
newInstance(String cName, Class<T> expectedType, String[] subPackages, Class<?>[] params, Object[] args)
<T> T
newInstance(PluginInfo info, Class<T> type, boolean registerCoreReloadListener)
Create an instance of a class using an appropriateSolrResourceLoader
depending on the package of that classInputStream
openResource(String resource)
Opens any resource by its name.static void
persistConfLocally(SolrResourceLoader loader, String resourceName, byte[] content)
String
resourceLocation(String resource)
Report the location of a resource found by the resource loader
-
-
-
Field Detail
-
SOLR_ALLOW_UNSAFE_RESOURCELOADING_PARAM
public static final String SOLR_ALLOW_UNSAFE_RESOURCELOADING_PARAM
- See Also:
- Constant Field Values
-
classLoader
protected URLClassLoader classLoader
-
-
Constructor Detail
-
SolrResourceLoader
public SolrResourceLoader(String name, List<Path> classpath, Path instanceDir, ClassLoader parent)
Creates a loader. Note: we do NOT callreloadLuceneSPI()
.
-
SolrResourceLoader
public SolrResourceLoader(Path instanceDir)
Creates a loader.- Parameters:
instanceDir
- - base directory for this resource loader, must not be null
-
SolrResourceLoader
public 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 Detail
-
getManagedResourceRegistry
public RestManager.Registry 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
public static List<URL> getURLs(Path libDir) throws IOException
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
public static List<URL> getFilteredURLs(Path libDir, String regex) throws IOException
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
public Path getConfigPath()
-
getConfigDir
@Deprecated(since="9.0.0") public String getConfigDir()
Deprecated.usegetConfigPath()
-
getClassLoader
public ClassLoader getClassLoader()
EXPERTThe underlying class loader. Most applications will not need to use this.
- Returns:
- The
ClassLoader
-
openResource
public InputStream openResource(String resource) throws IOException
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:
openResource
in interfaceorg.apache.lucene.util.ResourceLoader
- Returns:
- the stream for the named resource
- Throws:
IOException
-
resourceLocation
public String resourceLocation(String resource)
Report the location of a resource found by the resource loader
-
getLines
public List<String> getLines(String resource) throws IOException
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
public List<String> getLines(String resource, String encoding) throws IOException
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
public List<String> getLines(String resource, Charset charset) throws IOException
- Throws:
IOException
-
findClass
public <T> Class<? extends T> findClass(String cname, Class<T> expectedType)
- Specified by:
findClass
in interfaceorg.apache.lucene.util.ResourceLoader
- Specified by:
findClass
in interfaceorg.apache.solr.common.cloud.SolrClassLoader
-
findClass
public <T> Class<? extends T> findClass(String cname, Class<T> expectedType, String... subpackages)
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
public <T> T newInstance(String name, Class<T> expectedType)
- Specified by:
newInstance
in interfaceorg.apache.lucene.util.ResourceLoader
-
newInstance
public <T> T newInstance(String cname, Class<T> expectedType, String... subpackages)
- Specified by:
newInstance
in interfaceorg.apache.solr.common.cloud.SolrClassLoader
-
newInstance
public <T> T newInstance(String cName, Class<T> expectedType, String[] subPackages, Class<?>[] params, Object[] args)
- Specified by:
newInstance
in 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'
-
inform
public void inform(SolrCore core)
Tell allSolrCoreAware
instances about the SolrCore- Specified by:
inform
in interfaceSolrCoreAware
-
inform
public void inform(org.apache.lucene.util.ResourceLoader loader) throws IOException
Tell allResourceLoaderAware
instances 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 currentResourceLoaderAware
object in thread local so that appropriate classloader can be used for package loaded classes- Throws:
IOException
-
inform
public void inform(Map<String,SolrInfoBean> infoRegistry)
Register anySolrInfoBean
s- Parameters:
infoRegistry
- The Info Registry
-
getInstancePath
public Path 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
public static Class<?> assertAwareCompatibility(Class<?> aware, Object obj)
Utility function to throw an exception if the class is invalid
-
getCoreContainer
public CoreContainer getCoreContainer()
-
getSolrConfig
public SolrConfig getSolrConfig()
-
close
public void close() throws IOException
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Throws:
IOException
-
getInfoMBeans
public List<SolrInfoBean> getInfoMBeans()
-
findClass
public <T> Class<? extends T> findClass(PluginInfo info, Class<T> type, boolean registerCoreReloadListener)
Load a class using an appropriateSolrResourceLoader
depending 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
public <T> T newInstance(PluginInfo info, Class<T> type, boolean registerCoreReloadListener)
Create an instance of a class using an appropriateSolrResourceLoader
depending 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)
-
-