Class HigsonEngineFactory
HigsonEngineImpl using create(), that is used in many places during application runtime. Using this factory,
developers might have impact on some behaviour of the runtime. It will be described below.
The most important aspect of configuration is to setup dataSource, so this is main action for developer to take.
More configuration options are available via flags and setter's. During engine creation, multiple things happens:
1. Watchers are created by default, since autoStartWatchers is set to true
2. Database access points (DAO's) and providers for core elements like functions, parameters, domain are created.
3. Interceptors/listeners might be injected to the engine.
4. Functions invokers supported by higson are created.
There is also possibility for using higson engine in developer mode. By enabling developer mode setDeveloperMode(boolean) to true,
and setting userName setUsername(String), runtime will be aware of user perspective(higson session) automatically. For example, if user is
making some changes in parameters/function/domain via Higson Studio connected to the same dataSource as runtime, but doesn't want to public the session
(so other
users can't see it) and his runtime environment will be aware of this change. If developer mode is set to [@code false}, then user in higson studio has
to manually publish his session, so any changes done to parameters, functions or domain will be available via higson runtime.
Sample basic configuration:
DataSource ds = ... //
HigsonEngineFactory factory = new HigsonEngineFactory(ds);
factory.create();
Sample configuration with developer mode ON for username "jason":
DataSource ds = ... //
HigsonEngineFactory factory = new HigsonEngineFactory(ds);
factory.setDeveloperMode(true);
factory.setUsername("jason");
factory.create();
-
Constructor Summary
ConstructorsConstructorDescriptionHigsonEngineFactory(HigsonDataSource higsonDataSource) HigsonEngineFactory(DataSource dataSource) HigsonEngineFactory(DataSource dataSource, ConnectionInterceptor connectionInterceptor) -
Method Summary
Modifier and TypeMethodDescriptionvoidaddExternalDataSource(String code, DataSource dataSource) Add external dataSource under given code, so higson will recognize it, when fetching for parameters that have defined this external source.voidaddExternalDataSources(Map<String, DataSource> dataSourceMap) Same assetExternalDataSources(Map)and it will iterate over given map and calladdExternalDataSource(String, DataSource)voidaddFunctionInvocationInterceptor(FunctionInvocationInterceptor functionInvocationInterceptor) Add user defined function invocation interceptor.voidaddRegionForParametersPrefetch(String profileCode, String regionCode) Allows specifying region code within profile, which is used to fetch parameters early on system startup.voidattachLogListener(LogListener logListener) create()Creates HigsonEngine instance based on given configuration.createVersionWatcher(WatcherConfig config) voiddestroy()This method stops all threads created by higson-runtime.Deprecated, for removal: This API element is subject to removal in a future version.Deprecated, for removal: This API element is subject to removal in a future version.UsewatchersConfigandgetParamWatcherConfig()insteadDeprecated, for removal: This API element is subject to removal in a future version.UsewatchersConfigandgetRefreshWatcherConfig()insteadintDeprecated, for removal: This API element is subject to removal in a future version.UsewatchersConfigandgetWatcherPauseSeconds()fromscheduleRuntimeWatcherConfigintDeprecated, for removal: This API element is subject to removal in a future version.UsewatchersConfigandgetErrorPauseSeconds()of selected watcherintDeprecated, for removal: This API element is subject to removal in a future version.UsewatchersConfigandgetWatcherPauseSecondsof selected watcherintDeprecated, for removal: This API element is subject to removal in a future version.UsewatchersConfigandgetStartDelaySeconds()of selected watcherbooleanChecks if developerMode is ON or OFF.voidredefineDomainCache(DomainCache newMpDomainCache, MpDomainCacheProvider newDomainCacheProvider, DomainCacheManager newDomainCacheManager) Setup custom domain cache, provider and manager for it.voidsetAttributeInterceptor(AttributeInterceptor attributeInterceptor) Setup attribute interceptor for attribute value provider.voidsetAutoStartWatchers(boolean autoStartWatchers) Control flag for starting watchers during engine build.voidsetCustomPlugins(Map<String, Object> customPlugins) This method allows developers to inject custom plugins or even override behaviour of higson plugins.final voidsetDataSource(HigsonDataSource dataSource) This method setup dataSource used by higson-runtime with all required elements, like: main access points to parameters, functions, external sources, domain, etc.final voidsetDataSource(DataSource dataSource) voidsetDeveloperMode(boolean developerMode) Setup higson engine with developer mode.voidsetDomainWatcherInvalidateCacheTime(int domainWatcherInvalidateCacheTime, TemporalUnit unit) Deprecated, for removal: This API element is subject to removal in a future version.usewatchersConfigand setinvalidateondomainWatcherConfigvoidsetEnableDomainCache(boolean enableDomainCache) Deprecated, for removal: This API element is subject to removal in a future version.voidSame asaddExternalDataSources(Map)and it will iterate over given map and calladdExternalDataSource(String, DataSource)voidsetExternalModulesForPython(List<String> modules) voidSet time-to-live (TTL) for function log level cached entries.voidsetFunctionsToPrefetch(List<String> functionsToPrefetch) Allows to setup a list of functions codes to be fetched early on system startup.voidsetHigsonDataSource(HigsonDataSource higsonDataSource) voidsetIdleChecker(IdleChecker idleChecker) voidsetLevelCreatorInterceptor(FunctionInvokerInterceptor levelCreatorInterceptor) Setup level creator interceptor.voidsetMaxConcurrentLoads(int maxConcurrentLoads) Sets limited access to concurrent loads of parameters.voidsetMaxIdleTime(Duration maxIdleTime) voidsetParamsToPrefetch(List<String> paramsToPrefetch) Allows to setup a list of parameters codes to be fetched early on system startup.voidDeprecated, for removal: This API element is subject to removal in a future version.usewatchersConfigand setrefreshWatcherConfigvoidsetReloadPolicy(ReloadPolicy reloadPolicy) voidsetRhinoPlugins(Map<String, Object> rhinoPlugins) Deprecated.- This method will be removed in the future.voidsetScheduleWatcherPauseSeconds(int scheduleWatcherPauseSeconds) Deprecated, for removal: This API element is subject to removal in a future version.usewatchersConfigand setpause()ofscheduleRuntimeWatcherConfigvoidsetSessionProvider(MpUserSessionProvider sessionProvider) Sets session provider, which holds information about a user like userName.voidsetThrowOnNormalizeInputValueException(boolean throwOnNormalizeInputValueException) voidsetUsername(String username) Setup username for developer mode.voidsetValidateFunctionArgumentsDataTypes(boolean validateFunctionArgumentsDataTypes) Setup built-in argument data types validator for function invocation.voidsetValueNeverNull(boolean valueNeverNull) Flag responsible for managing global support of nullable parameters results by engine.voidsetWatcherErrorPauseSeconds(int watcherErrorPauseSeconds) Deprecated, for removal: This API element is subject to removal in a future version.usewatchersConfigand seterror()on any of selected watchersvoidsetWatcherEventListener(WatcherEventListener watcherEventListener) Setup watcher event listener for function and parameters runtime watchers.voidsetWatcherForceSyncSeconds(int seconds) Deprecated, for removal: This API element is subject to removal in a future version.usewatchersConfigand setforce()onparamWatcherConfigvoidsetWatcherPauseSeconds(int watcherPauseSeconds) Deprecated, for removal: This API element is subject to removal in a future version.usewatchersConfigand setpause()on any of selected watchersvoidsetWatcherStartDelaySeconds(int watcherStartDelaySeconds) Deprecated, for removal: This API element is subject to removal in a future version.usewatchersConfigand setdelayon any of selected watchersstartDomainWatcher(WatcherConfig watcherConf) Creates and starts domain runtime watcher, if flagenableDomainCacheistrue.startFunctionWatcher(WatcherConfig config) Creates, inject watcher event listener and starts functions runtime watcher.startParamWatcher(WatcherConfig config) Creates, inject watcher event listener and starts parameters runtime watcher.startRefreshWatcher(WatcherConfig config) Creates and starts refresh runtime watcher, that is responsible for evicting parameters from cache.Creates and starts schedule runtime watcher.startVersionWatcher(WatcherConfig config) Creates and starts version runtime watcher.
-
Constructor Details
-
HigsonEngineFactory
-
HigsonEngineFactory
-
HigsonEngineFactory
-
-
Method Details
-
setHigsonDataSource
-
setDataSource
-
setDataSource
This method setup dataSource used by higson-runtime with all required elements, like: main access points to parameters, functions, external sources, domain, etc. If developer didn't provided any connection interceptor, thenStdConnectionInterceptorwill be used.- Parameters:
dataSource- that will be used during runtime
-
setValueNeverNull
public void setValueNeverNull(boolean valueNeverNull) Flag responsible for managing global support of nullable parameters results by engine. If it is set to true (by default), then parameters will never returnnull, but instead they will return instance ofEmptyParamValue.- Parameters:
valueNeverNull- true of false to be set
-
setMaxConcurrentLoads
public void setMaxConcurrentLoads(int maxConcurrentLoads) Sets limited access to concurrent loads of parameters. Default value is 3. This helps to control usage of resources, since fetching parameters might be very stressful for the application.- Parameters:
maxConcurrentLoads- currentLoads maximal number of concurrent loads
-
setSessionProvider
Sets session provider, which holds information about a user like userName.- Parameters:
sessionProvider- instance ofMpUserSessionProvider
-
setAutoStartWatchers
public void setAutoStartWatchers(boolean autoStartWatchers) Control flag for starting watchers during engine build.trueby default.- Parameters:
autoStartWatchers- if true, during engine creation watchers will be created. If false, then nothing will happen.
-
setRhinoPlugins
Deprecated.- This method will be removed in the future. Please use accordingsetCustomPlugins(Map).- Parameters:
rhinoPlugins- Custom plugins, that will be added to the base of higson supported plugins.
-
setCustomPlugins
This method allows developers to inject custom plugins or even override behaviour of higson plugins. Plugins will be added, when methodcreate()is called. Higson supported plugins codes:- log
- date
- ctx
- domain
- util
- Parameters:
customPlugins- map, where key is plugin code, value is instance of the plugin
-
setParamsToPrefetch
Allows to setup a list of parameters codes to be fetched early on system startup.- Parameters:
paramsToPrefetch- list of parameters codes
-
setFunctionsToPrefetch
Allows to setup a list of functions codes to be fetched early on system startup.- Parameters:
functionsToPrefetch- list of functions codes
-
addRegionForParametersPrefetch
Allows specifying region code within profile, which is used to fetch parameters early on system startup. Bear in mind that adding too many profileCodes or regionCodes for given profileCode puts a lot of pressure on the database on system startup.- Parameters:
profileCode- profile coderegionCode- region code
-
create
Creates HigsonEngine instance based on given configuration. Here multiple whole structure of an engine is created. First the dialect for database is registered. After that, all providers and invokers for parameters, functions, etc. All supported types for HigsonContext are created here as well.ParamEngineConfigBuilderis used as well to buildParamEngineConfig.autoStartWatchersif it is set totrue(by default it is), then all watchers for higson main functionalities will be enabled.enableDomainCacheif it is set totrue(by default it is), then domain will be cached and maintained by higson-runtime.paramsToPrefetchandfunctionsToPrefetchgives a possibility to early fetch on startup list of given parameters or functions codes.- Returns:
- new higson engine
- Throws:
HigsonRuntimeException- if dataSource isnull
-
startParamWatcher
Creates, inject watcher event listener and starts parameters runtime watcher.- Parameters:
config- for watcher- Returns:
- instance of started runtime watcher
- See Also:
-
startFunctionWatcher
Creates, inject watcher event listener and starts functions runtime watcher.- Parameters:
config- for watcher- Returns:
- instance of started runtime watcher
- See Also:
-
startVersionWatcher
Creates and starts version runtime watcher.- Parameters:
config- for watcher- Returns:
- instance of started runtime watcher
- See Also:
-
createVersionWatcher
-
createUserRegionVersionWatcher
-
startScheduleWatcher
Creates and starts schedule runtime watcher. WatcherConfig is using property set via#scheduleWatcherPauseSeconds.- Returns:
- instance of started runtime watcher
- See Also:
-
startRefreshWatcher
Creates and starts refresh runtime watcher, that is responsible for evicting parameters from cache.- Parameters:
config- for watcher- Returns:
- instance of started runtime watcher
- See Also:
-
startDomainWatcher
Creates and starts domain runtime watcher, if flagenableDomainCacheistrue.- Parameters:
watcherConf- for watcher- Returns:
- instance of started runtime watcher
- See Also:
-
destroy
public void destroy()This method stops all threads created by higson-runtime. All threads have to be stopped so that the JVM process can exit. This is very important to call this method from client application, otherwise the JVM will not stop. Below is the recommended way to free resources:HigsonEngineFactory factory; HigsonEngine engine; [PostConstruct] public void init() { factory = new HigsonEngineFactory(dataSource); engine = factory.create(); } [PreDestroy] public void destroy() { factory.destroy(); } -
setLevelCreatorInterceptor
Setup level creator interceptor. Higson provides default implementation if not specified.- Parameters:
levelCreatorInterceptor- acts as function invoker interceptor
-
setEnableDomainCache
Deprecated, for removal: This API element is subject to removal in a future version. -
setAttributeInterceptor
Setup attribute interceptor for attribute value provider.- Parameters:
attributeInterceptor- custom interceptor for domain attributes- See Also:
-
setWatcherEventListener
Setup watcher event listener for function and parameters runtime watchers.- Parameters:
watcherEventListener- custom event listener
-
isDeveloperMode
public boolean isDeveloperMode()Checks if developerMode is ON or OFF.- Returns:
- true if ON, false otherwise
-
setDeveloperMode
public void setDeveloperMode(boolean developerMode) Setup higson engine with developer mode. It will change default behaviour of an engine. Default value is false.- Parameters:
developerMode- control flag
-
setUsername
Setup username for developer mode.- Parameters:
username- to be used
-
setValidateFunctionArgumentsDataTypes
public void setValidateFunctionArgumentsDataTypes(boolean validateFunctionArgumentsDataTypes) Setup built-in argument data types validator for function invocation. Default value is false.- Parameters:
validateFunctionArgumentsDataTypes- control flag
-
getPythonFunctionInvoker
-
addExternalDataSources
Same assetExternalDataSources(Map)and it will iterate over given map and calladdExternalDataSource(String, DataSource)- Parameters:
dataSourceMap- of datasource and theirs codes
-
addExternalDataSource
Add external dataSource under given code, so higson will recognize it, when fetching for parameters that have defined this external source.- Parameters:
code- under which dataSource will be availabledataSource- external dataSource
-
setExternalDataSources
Same asaddExternalDataSources(Map)and it will iterate over given map and calladdExternalDataSource(String, DataSource)- Parameters:
map- of datasource and theirs codes
-
redefineDomainCache
public void redefineDomainCache(DomainCache newMpDomainCache, MpDomainCacheProvider newDomainCacheProvider, DomainCacheManager newDomainCacheManager) Setup custom domain cache, provider and manager for it. If developer provider custom implementations, then duringcreate()higson will skip building them on its own.- Parameters:
newMpDomainCache- custom domain cachenewDomainCacheProvider- custom domain cache providernewDomainCacheManager- custom domain cache manager
-
setExternalModulesForPython
-
setThrowOnNormalizeInputValueException
public void setThrowOnNormalizeInputValueException(boolean throwOnNormalizeInputValueException) -
addFunctionInvocationInterceptor
public void addFunctionInvocationInterceptor(FunctionInvocationInterceptor functionInvocationInterceptor) Add user defined function invocation interceptor. Higson triggers added interceptor before every function invocation.- Parameters:
functionInvocationInterceptor- User defined function invocation interceptor- See Also:
-
setFunctionLogLevelCacheTTL
Set time-to-live (TTL) for function log level cached entries. -
attachLogListener
-
setIdleChecker
-
setMaxIdleTime
-
setReloadPolicy
-
getWatcherStartDelaySeconds
Deprecated, for removal: This API element is subject to removal in a future version.Use
watchersConfigandgetStartDelaySeconds()of selected watcher- Returns:
- watcher start delay in seconds of
watchersConfig.paramWatcherConfig
-
getWatcherPauseSeconds
Deprecated, for removal: This API element is subject to removal in a future version.Use
watchersConfigandgetWatcherPauseSecondsof selected watcher- Returns:
- pause of watchers in seconds of
watchersConfig.paramWatcherConfig
-
getWatcherErrorPauseSeconds
Deprecated, for removal: This API element is subject to removal in a future version.Use
watchersConfigandgetErrorPauseSeconds()of selected watcher- Returns:
- pause during some error of watchers in seconds of
watchersConfig.paramWatcherConfig
-
getScheduleWatcherPauseSeconds
Deprecated, for removal: This API element is subject to removal in a future version.Use
watchersConfigandgetWatcherPauseSeconds()fromscheduleRuntimeWatcherConfig- Returns:
- pause in seconds of global schedule watcher
-
getRefreshWatcherConfig
Deprecated, for removal: This API element is subject to removal in a future version.Use
watchersConfigandgetRefreshWatcherConfig()instead- Returns:
- configuration of refresh watcher
-
getParamWatcherConfig
Deprecated, for removal: This API element is subject to removal in a future version.Use
watchersConfigandgetParamWatcherConfig()instead- Returns:
- configuration of parameters watcher
-
getFunctionWatcherConfig
Deprecated, for removal: This API element is subject to removal in a future version.Use
watchersConfigandgetFunctionWatcherConfig()instead- Returns:
- configuration of functions watcher
-
setWatcherStartDelaySeconds
Deprecated, for removal: This API element is subject to removal in a future version.usewatchersConfigand setdelayon any of selected watchersSetup delay of watchers in seconds. Default value is set toWatchersConfig.WATCHER_DEFAULT_START_DELAYseconds. Parameter and function watchers will have the same delay.- Parameters:
watcherStartDelaySeconds- delay in seconds
-
setWatcherPauseSeconds
Deprecated, for removal: This API element is subject to removal in a future version.usewatchersConfigand setpause()on any of selected watchersSetup pause of watchers in seconds. Default value is set toWatchersConfig.WATCHER_DEFAULT_PAUSEseconds. Parameter and function watchers will have the same pause.- Parameters:
watcherPauseSeconds- pause in seconds
-
setWatcherErrorPauseSeconds
Deprecated, for removal: This API element is subject to removal in a future version.usewatchersConfigand seterror()on any of selected watchersSetup pause during some error of watchers in seconds. Default value is set toWatchersConfig.WATCHER_DEFAULT_RECOVERYseconds. Parameter and function watchers will have the same pause.- Parameters:
watcherErrorPauseSeconds- error pause in seconds
-
setWatcherForceSyncSeconds
Deprecated, for removal: This API element is subject to removal in a future version.usewatchersConfigand setforce()onparamWatcherConfigSet the time after which the watcher will force a full cache synchronization. Currently only the param watcher supports this setting.- Parameters:
seconds- force sync pause in seconds
-
setRefreshWatcherConfig
Deprecated, for removal: This API element is subject to removal in a future version.usewatchersConfigand setrefreshWatcherConfigSets the refresh watcher configuration (delay, pause, error pause) -
setDomainWatcherInvalidateCacheTime
@Deprecated(forRemoval=true) public void setDomainWatcherInvalidateCacheTime(int domainWatcherInvalidateCacheTime, TemporalUnit unit) Deprecated, for removal: This API element is subject to removal in a future version.usewatchersConfigand setinvalidateondomainWatcherConfigSetup lifespan of domain trees in cache, if there are not used. By default domain tree will be removed from cache, if it's last build exceedsWatchersConfig.DOMAIN_WATCHER_INVALIDATE_TIMEWatchersConfig.DOMAIN_WATCHER_INVALIDATE_TIME_UNIT(or any time defined by this method).- Parameters:
domainWatcherInvalidateCacheTime- value of lifespan. By default it will beWatchersConfig.DOMAIN_WATCHER_INVALIDATE_TIMEunit- used with value from lifespan. By default it will beWatchersConfig.DOMAIN_WATCHER_INVALIDATE_TIME_UNIT
-
setScheduleWatcherPauseSeconds
@Deprecated(forRemoval=true) public void setScheduleWatcherPauseSeconds(int scheduleWatcherPauseSeconds) Deprecated, for removal: This API element is subject to removal in a future version.usewatchersConfigand setpause()ofscheduleRuntimeWatcherConfigSetup pause in seconds of global schedule watcher. Default value is set toWatchersConfig.SCHEDULE_WATCHER_DEFAULT_PAUSEseconds.- Parameters:
scheduleWatcherPauseSeconds- value of pause seconds
-
watchersConfigandgetFunctionWatcherConfig()instead