Class ParamEngineConfigBuilder

java.lang.Object
io.higson.runtime.engine.config.ParamEngineConfigBuilder

public final class ParamEngineConfigBuilder extends Object

ParamEngine configuration builder. Call build() to create immutable configuration object that should be used to construct new ParamEngine instance using ParamEngineFactory.

Remember, that instead of registering components by hand you can use annotation scanning configured via withAnnotationScanEnabled(String...) to discover classes.
Author:
Adam Dubiel
  • Method Details

    • paramEngineConfig

      public static ParamEngineConfigBuilder paramEngineConfig()
      Start building configuration.
      Returns:
      param config builder
    • build

      public ParamEngineConfig build()
      Finalizes configuration building and returns immutable config object.
      Returns:
      instance of param engine config
    • withAnnotationScanDisabled

      public ParamEngineConfigBuilder withAnnotationScanDisabled()
      Disable annotation scanning, this will return bare ParamEngine without any default components.
      Returns:
      the same instance of builder
    • withPackagesToScan

      public ParamEngineConfigBuilder withPackagesToScan(String... packagesToScan)
      Add packages (including all descendants) that will be scanned in search of SmartParam annotations. By default SmartParam only scans default package (org.smartparam.engine) which provides a base set of capabilities. It is also possible to disable annotation scanning by using withAnnotationScanDisabled().
      Parameters:
      packagesToScan - packages to add
      Returns:
      the same instance of builder
    • withPackagesToScan

      public ParamEngineConfigBuilder withPackagesToScan(PackageList packagesToScan)
      Add packages that will be scanned in search of SmartParam annotations. By default SmartParam only scans default package (org.smartparam.engine) which provides a base set of capabilities. It is also possible to disable annotation scanning by using withAnnotationScanDisabled().
      Parameters:
      packagesToScan - packages to add
      Returns:
      the same instance of builder
    • withComponent

      public ParamEngineConfigBuilder withComponent(Object component)
      Replace default ParamEngine components with custom one. This method should be used when you want to go deeper and replace one of ParamEngine core interfaces. If so, register object instance that implements interface of component you want to replace. For details on what are interfaces and classes, please take a look at source code of ParamEngineConfig.injectDefaults(java.util.List).
      Parameters:
      component - component to add
      Returns:
      the same instance of builder
    • registerModule

      public ParamEngineConfigBuilder registerModule(ParamEngineModule module)
      Add a self-registering module that encapsulates all self configuration.
      Parameters:
      module - object of ParamEngineModule interface.
      Returns:
      the same instance of builder
    • withParameterRepositories

      public ParamEngineConfigBuilder withParameterRepositories(ParamRepository... repositories)
      Register parameter repositories. There has to be at least one registered. Order of registration matters, as it determines order of querying. First repository that contains parameter wins.
      Parameters:
      repositories - object of ParamRepository interface.
      Returns:
      the same instance of builder
    • withFunctionRepository

      public ParamEngineConfigBuilder withFunctionRepository(String functionType, int order, FunctionRepository repository)
      Register FunctionRepository with given order (default repository has priority 100). Order might matter if you plan on overwriting functions from one repository with function with the other. Highest order goes last.
      Parameters:
      functionType - function type
      order - order number
      repository - object of FunctionRepository interface
      Returns:
      the same instance of builder
    • withFunctionInvoker

      public ParamEngineConfigBuilder withFunctionInvoker(String functionType, FunctionInvoker invoker)
      Register FunctionInvoker.
      Parameters:
      functionType - function type
      invoker - object of FunctionInvoker interface
      Returns:
      the same instance of builder
    • withFunctionInvoker

      public ParamEngineConfigBuilder withFunctionInvoker(String functionType, FunctionInvoker invoker, boolean supported)
      Register FunctionInvoker if supported is true.
      Parameters:
      functionType - function type
      invoker - object of FunctionInvoker interface
      supported - control flag
      Returns:
      the same instance of builder
    • withFunctionInvocationInterceptor

      public ParamEngineConfigBuilder withFunctionInvocationInterceptor(FunctionInvocationInterceptor functionInvocationInterceptor)
      Parameters:
      functionInvocationInterceptor - key for type
      Returns:
      the same instance of builder
    • withFunctionInvocationInterceptors

      public ParamEngineConfigBuilder withFunctionInvocationInterceptors(List<FunctionInvocationInterceptor> functionInvocationInterceptors)
      Parameters:
      functionInvocationInterceptors - key for type
      Returns:
      the same instance of builder
    • withProperties

      public ParamEngineConfigBuilder withProperties(Properties properties)
    • withIdleChecker

      public ParamEngineConfigBuilder withIdleChecker(IdleChecker idleChecker)
    • withType

      public <T extends ValueHolder> ParamEngineConfigBuilder withType(String code, Type<T> type)
      Register Type under code.
      Type Parameters:
      T - generic that extends ValueHolder
      Parameters:
      code - key for type
      type - object of Type interface
      Returns:
      the same instance of builder
    • withMatcher

      public ParamEngineConfigBuilder withMatcher(String code, Matcher matcher)
      Register Matcher under code.
      Parameters:
      code - key for matcher
      matcher - object of Matcher interface
      Returns:
      the same instance of builder
    • withFunctionCache

      public ParamEngineConfigBuilder withFunctionCache(FunctionCache functionCache)
      Register custom FunctionCache.
      Parameters:
      functionCache - object of FunctionCache interface
      Returns:
      the same instance of builder
    • withParameterCache

      public ParamEngineConfigBuilder withParameterCache(PreparedParamCache parameterCache)
      Register custom PreparedParamCache.
      Parameters:
      parameterCache - object of PreparedParamCache interface
      Returns:
      the same instance of builder
    • withInitializationRunner

      public ParamEngineConfigBuilder withInitializationRunner(ComponentInitializerRunner runner)
      Register custom implementation of initialization runner. This goes deep into ParamEngine construction process, so watch out.
      Parameters:
      runner - object of ComponentInitializerRunner interface
      Returns:
      the same instance of builder
    • withComponentInitializers

      public ParamEngineConfigBuilder withComponentInitializers(ComponentInitializer... initializers)
      Register additional ComponentInitializer. These are useful if custom component needs custom initialization (and PostConstructInitializer is not enough.
      Parameters:
      initializers - object of ComponentInitializer interface
      Returns:
      the same instance of builder
    • withOutputLevelArraySeparator

      public ParamEngineConfigBuilder withOutputLevelArraySeparator(OutputLevelArraySeparator arraySeparator)
      specify output level array separator that will be used while extracting parameter output values.
      Parameters:
      arraySeparator - output level array separator that will be used in Higson Engine
      Returns:
      the same instance of builder
      See Also: