org.apache.solr.core

## Class SolrResourceLoader

- java.lang.Object
- - org.apache.solr.core.SolrResourceLoader

- All Implemented Interfaces:
    Closeable, AutoCloseable, ResourceLoader
  Direct Known Subclasses:
    ZkSolrResourceLoader

      public class SolrResourceLoader
      extends Object
      implements ResourceLoader, Closeable

  Since:
    solr 1.3

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `protected URLClassLoader` | `classLoader`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `SolrResourceLoader()`
    `SolrResourceLoader(Path instanceDir)`
    `SolrResourceLoader(Path instanceDir, ClassLoader parent)` This loader will delegate to the context classloader when possible, otherwise it will attempt to resolve resources using any jar files found in the "lib/" directory in the specified instance directory.
    `SolrResourceLoader(Path instanceDir, ClassLoader parent, Properties coreProperties)` This loader will delegate to the context 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
    Modifier and Type | Method and Description
    --- | ---
    `void` | `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).
    `ClassLoader` | `getClassLoader()` EXPERT
    `String` | `getConfigDir()`
    `Properties` | `getCoreProperties()`
    `String` | `getDataDir()`
    `static List<URL>` | `getFilteredURLs(Path libDir, String regex)` Utility method to get the URLs of all paths under a given directory that match a regex
    `List<SolrInfoMBean>` | `getInfoMBeans()`
    `Path` | `getInstancePath()`
    `List<String>` | `getLines(String resource)` Accesses a resource by name and returns the (non comment) lines containing data.
    `List<String>` | `getLines(String resource, Charset charset)`
    `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.
    `RestManager.Registry` | `getManagedResourceRegistry()`
    `static List<URL>` | `getURLs(Path libDir)` Utility method to get the URLs of all paths under a given directory
    `static 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 filter
    `void` | `inform(Map<String,SolrInfoMBean> infoRegistry)` Register any `SolrInfoMBean`s
    `void` | `inform(ResourceLoader loader)` Tell all `ResourceLoaderAware` instances about the loader
    `void` | `inform(SolrCore core)` Tell all `SolrCoreAware` instances about the SolrCore
    `String[]` | `listConfigDir()`
    `static Path` | `locateSolrHome()` Finds the solrhome based on looking up the value in one of three places: JNDI: via java:comp/env/solr/home The system property solr.solr.home Look in the current working directory for a solr/ directory The return value is normalized.
    `CoreAdminHandler` | `newAdminHandlerInstance(CoreContainer coreContainer, String cname, String... subpackages)`
    `<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)`
    `static String` | `normalizeDir(String path)` Ensures a directory name always ends with a '/'.
    `InputStream` | `openConfig(String name)` Opens a config resource by its name.
    `InputStream` | `openResource(String resource)` Opens any resource by its name.
    `InputStream` | `openSchema(String name)` Opens a schema 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

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### classLoader

          protected URLClassLoader classLoader

  - ### Constructor Detail

    - #### SolrResourceLoader

          public SolrResourceLoader()

    - #### SolrResourceLoader

          public SolrResourceLoader(Path instanceDir,
                                    ClassLoader parent)

      This loader will delegate to the context classloader when possible, otherwise it will attempt to resolve resources using any jar files found in the "lib/" directory in the specified instance directory. If the instance directory is not specified (=null), SolrResourceLoader#locateInstanceDir will provide one.

    - #### SolrResourceLoader

          public SolrResourceLoader(Path instanceDir)

    - #### SolrResourceLoader

          public SolrResourceLoader(Path instanceDir,
                                    ClassLoader parent,
                                    Properties coreProperties)

      This loader will delegate to the context classloader when possible, otherwise it will attempt to resolve resources using any jar files found in the "lib/" directory in the specified instance directory.

      Parameters:
        `instanceDir` - - base directory for this resource loader, if null locateSolrHome() will be used.
      See Also:
        `locateSolrHome()`

  - ### Method Detail

    - #### getManagedResourceRegistry

          public RestManager.Registry getManagedResourceRegistry()

    - #### 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 directory
        `filter` - 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 directory
        `regex` - the regex as a String
      Returns:
        all matching URLs
      Throws:
        `IOException` - on error

    - #### normalizeDir

          public static String normalizeDir(String path)

      Ensures a directory name always ends with a '/'.

    - #### listConfigDir

          public String[] listConfigDir()

    - #### getConfigDir

          public String getConfigDir()

    - #### getDataDir

          public String getDataDir()

    - #### getCoreProperties

          public Properties getCoreProperties()

    - #### getClassLoader

          public ClassLoader getClassLoader()

      EXPERT

      The underlying class loader. Most applications will not need to use this.

      Returns:
        The `ClassLoader`

    - #### openSchema

          public InputStream openSchema(String name)
                                 throws IOException

      Opens a schema resource by its name. Override this method to customize loading schema resources.
      Returns:
        the stream for the named schema
      Throws:
        `IOException`

    - #### openConfig

          public InputStream openConfig(String name)
                                 throws IOException

      Opens a config resource by its name. Override this method to customize loading config resources.
      Returns:
        the stream for the named configuration
      Throws:
        `IOException`

    - #### 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 interface `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 interface `ResourceLoader`

    - #### 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 interface `ResourceLoader`

    - #### newInstance

          public <T> T newInstance(String cname,
                                   Class<T> expectedType,
                                   String... subpackages)

    - #### newAdminHandlerInstance

          public CoreAdminHandler newAdminHandlerInstance(CoreContainer coreContainer,
                                                          String cname,
                                                          String... subpackages)

    - #### newInstance

          public <T> T newInstance(String cName,
                                   Class<T> expectedType,
                                   String[] subPackages,
                                   Class[] params,
                                   Object[] args)

    - #### inform

          public void inform(SolrCore core)

      Tell all `SolrCoreAware` instances about the SolrCore

    - #### inform

          public void inform(ResourceLoader loader)
                      throws IOException

      Tell all `ResourceLoaderAware` instances about the loader
      Throws:
        `IOException`

    - #### inform

          public void inform(Map<String,SolrInfoMBean> infoRegistry)

      Register any `SolrInfoMBean`s
      Parameters:
        `infoRegistry` - The Info Registry

    - #### locateSolrHome

          public static Path locateSolrHome()

      Finds the solrhome based on looking up the value in one of three places:
      1. JNDI: via java:comp/env/solr/home
      2. The system property solr.solr.home
      3. Look in the current working directory for a solr/ directory
      The return value is normalized. Normalization essentially means it ends in a trailing slash.
      Returns:
        A normalized solrhome
      See Also:
        `normalizeDir(String)`

    - #### getInstancePath

          public Path getInstancePath()

      Returns:
        the instance path for this resource loader

    - #### close

          public void close()
                     throws IOException

      Specified by:
        `close` in interface `Closeable`
      Specified by:
        `close` in interface `AutoCloseable`
      Throws:
        `IOException`

    - #### getInfoMBeans

          public List<SolrInfoMBean> getInfoMBeans()

    - #### persistConfLocally

          public static void persistConfLocally(SolrResourceLoader loader,
                                                String resourceName,
                                                byte[] content)

Copyright © 2000-2016 Apache Software Foundation. All Rights Reserved.