Class DefaultModulesLoader

  • All Implemented Interfaces:
    ModulesLoader

    public class DefaultModulesLoader
    extends LoggingObject
    implements ModulesLoader
    Default implementation of ModulesLoader.

    REST modules and non-REST modules are handled in different ways. Non-REST modules are loaded via an instance of AssetFileLoader, which most likely loads modules via port 8000, directly into the desired modules database.

    REST modules however have to be loaded via the REST server that they're targeted for. This class also loads them by default via multiple threads to increase performance, as it can take a couple seconds to load each set of search options, service, and transform.

    To handle errors while loading REST modules in parallel, an implementation of LoadModulesFailureListener can be added to this class (ideally would have just been a Consumer that receives a Throwable). By default, an instance of SimpleLoadModulesFailureListener is added. Also by default, any Throwable caught by this class will be rethrown after all REST modules have been loaded. This behavior can be disabled by setting rethrowRestModulesFailure to false, in which case the failures are just logged.

    • Constructor Detail

      • DefaultModulesLoader

        public DefaultModulesLoader​(AssetFileLoader assetFileLoader)
        Use this when you need to load REST modules and asset modules as well (non-REST modules).
        Parameters:
        assetFileLoader -
      • DefaultModulesLoader

        public DefaultModulesLoader()
        Use this when you don't need to load asset modules - i.e. only need to load REST modules.
    • Method Detail

      • initializeDefaultTaskExecutor

        public void initializeDefaultTaskExecutor()
      • loadModules

        public java.util.Set<org.springframework.core.io.Resource> loadModules​(com.marklogic.client.DatabaseClient client,
                                                                               ModulesFinder modulesFinder,
                                                                               java.lang.String... paths)
        Load modules from the given base directory, selecting modules via the given ModulesFinder, and loading them via the given DatabaseClient. Note that asset modules will not be loaded by the DatabaseClient that's passed in here, because the /v1/ext endpoint is too slow when there are e.g. hundreds of modules or more - asset modules are instead loaded via AssetFileLoader.
        Specified by:
        loadModules in interface ModulesLoader
        paths - the DatabaseClient to use for loading REST extensions
        Returns:
        the set of resources containing all modules written
      • loadModules

        public java.util.Set<org.springframework.core.io.Resource> loadModules​(java.lang.String baseDir,
                                                                               ModulesFinder modulesFinder,
                                                                               com.marklogic.client.DatabaseClient client)
        Just delegates to the loadModules method that takes an array of paths.
        Specified by:
        loadModules in interface ModulesLoader
        Parameters:
        baseDir -
        modulesFinder -
        client -
        Returns:
        the set of resources capturing each module that was written
      • loadModules

        protected java.util.Set<org.springframework.core.io.Resource> loadModules​(Modules modules)
      • rethrowRestModulesFailureIfOneExists

        protected void rethrowRestModulesFailureIfOneExists()
      • waitForTaskExecutorToFinish

        public void waitForTaskExecutorToFinish()
        If an AsyncTaskExecutor is used for loading options/services/transforms, we need to wait for the tasks to complete before we e.g. release the DatabaseClient.
      • loadProperties

        protected void loadProperties​(Modules modules,
                                      java.util.Set<org.springframework.core.io.Resource> loadedModules)
        Only supports a JSON file.
        Parameters:
        modules -
        loadedModules -
      • applyJsonProperties

        protected void applyJsonProperties​(com.marklogic.client.admin.ServerConfigurationManager mgr,
                                           org.springframework.core.io.Resource r,
                                           java.io.File file)
      • applyXmlProperties

        protected void applyXmlProperties​(com.marklogic.client.admin.ServerConfigurationManager mgr,
                                          org.springframework.core.io.Resource r,
                                          java.io.File file)
        Parameters:
        mgr -
        r -
        file -
      • getFileFromResource

        protected java.io.File getFileFromResource​(org.springframework.core.io.Resource r)
      • loadAssets

        protected void loadAssets​(Modules modules,
                                  java.util.Set<org.springframework.core.io.Resource> loadedModules)
        Parameters:
        modules -
        loadedModules -
      • applyIncludeFilenamePattern

        protected void applyIncludeFilenamePattern()
      • loadQueryOptions

        protected void loadQueryOptions​(Modules modules,
                                        java.util.Set<org.springframework.core.io.Resource> loadedModules)
        Parameters:
        modules -
        loadedModules -
      • loadTransforms

        protected void loadTransforms​(Modules modules,
                                      java.util.Set<org.springframework.core.io.Resource> loadedModules)
        Parameters:
        modules -
        loadedModules -
      • loadResources

        protected void loadResources​(Modules modules,
                                     java.util.Set<org.springframework.core.io.Resource> loadedModules)
        Parameters:
        modules -
        loadedModules -
      • loadNamespaces

        protected void loadNamespaces​(Modules modules,
                                      java.util.Set<org.springframework.core.io.Resource> loadedModules)
        Parameters:
        modules -
        loadedModules -
      • installService

        public org.springframework.core.io.Resource installService​(org.springframework.core.io.Resource r,
                                                                   com.marklogic.client.admin.ExtensionMetadata metadata,
                                                                   com.marklogic.client.admin.ResourceExtensionsManager.MethodParameters... methodParams)
        Parameters:
        r -
        metadata -
        methodParams -
        Returns:
        the resource is one was installed, else null
      • installTransform

        public org.springframework.core.io.Resource installTransform​(org.springframework.core.io.Resource r,
                                                                     com.marklogic.client.admin.ExtensionMetadata metadata)
        Parameters:
        r -
        metadata -
        Returns:
        the resource is one was installed, else null
      • installQueryOptions

        public org.springframework.core.io.Resource installQueryOptions​(org.springframework.core.io.Resource r)
        Parameters:
        r -
        Returns:
        the resource is one was installed, else null
      • readAndReplaceTokens

        protected java.lang.String readAndReplaceTokens​(org.springframework.core.io.Resource r)
        Handles reading in the content of a Resource, and then replacing tokens in it if a tokenReplacer has been set.
      • executeTask

        protected void executeTask​(java.lang.Runnable r)
        Protected in case a subclass wants to execute the Runnable in a different way - e.g. capturing the Future that could be returned.
        Parameters:
        r -
      • installNamespace

        public org.springframework.core.io.Resource installNamespace​(org.springframework.core.io.Resource r)
        Parameters:
        r -
        Returns:
        the resource if one is installed, else null
      • getExtensionNameFromFile

        protected java.lang.String getExtensionNameFromFile​(org.springframework.core.io.Resource r)
        Parameters:
        r -
        Returns:
        the extension name if one exists; if not, then the filename
      • ignoreResource

        protected boolean ignoreResource​(org.springframework.core.io.Resource r)
        If includeFilenamePattern is not null, then it is matched against the absolute path of the File that is resolved from the given resource. If the pattern doesn't match the absolute path, then true is returned. If a File cannot be resolved, then false is returned.
        Parameters:
        r -
        Returns:
        true if resource should be ignored
      • setDatabaseClient

        public void setDatabaseClient​(com.marklogic.client.DatabaseClient client)
      • setExtensionMetadataProvider

        public void setExtensionMetadataProvider​(ExtensionMetadataProvider extensionMetadataProvider)
      • setModulesManager

        public void setModulesManager​(ModulesManager modulesManager)
      • isCatchExceptions

        public boolean isCatchExceptions()
      • setCatchExceptions

        public void setCatchExceptions​(boolean catchExceptions)
      • setStaticChecker

        public void setStaticChecker​(StaticChecker staticChecker)
      • setTaskExecutor

        public void setTaskExecutor​(org.springframework.core.task.TaskExecutor taskExecutor)
      • setTaskThreadCount

        public void setTaskThreadCount​(int taskThreadCount)
      • setShutdownTaskExecutorAfterLoadingModules

        public void setShutdownTaskExecutorAfterLoadingModules​(boolean shutdownTaskExecutorAfterLoadingModules)
      • setAssetFileLoader

        public void setAssetFileLoader​(AssetFileLoader assetFileLoader)
      • getDatabaseClientInfo

        protected java.lang.String getDatabaseClientInfo​(com.marklogic.client.DatabaseClient client)
        Parameters:
        client -
        Returns:
        a string that is useful for logging information about the DatabaseClient connection before a call is made to load a REST extension.
      • setTokenReplacer

        public void setTokenReplacer​(TokenReplacer tokenReplacer)
      • setIncludeFilenamePattern

        public void setIncludeFilenamePattern​(java.util.regex.Pattern includeFilenamePattern)
      • setRethrowRestModulesFailure

        public void setRethrowRestModulesFailure​(boolean rethrowRestModulesFailure)