Class SzCoreEnvironment
- All Implemented Interfaces:
SzEnvironment
SzEnvironment that directly
initializes the Senzing SDK modules and provides management of the Senzing
environment in this process.
Usage:
// get the settings (varies by application)
String settings = getSettings();
// get the instance name (varies by application)
String instanceName = getInstanceName();
// construct the environment
SzEnvironment env = SzCoreEnvironment.newBuilder()
.instanceName(instanceName)
.settings(settings)
.verboseLogging(false)
.build();
// use the environment for some time (usually as long as application is running)
...
// destroy the environment when done (sometimes in a finally block)
env.destroy();
- Since:
- 4.0.0
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classSzCoreEnvironment.AbstractBuilder<E extends SzCoreEnvironment,B extends SzCoreEnvironment.AbstractBuilder<E, B>> Provides a base class for builder implementations ofSzCoreEnvironmentand its derived classes.static classThe builder class for creating an instance ofSzCoreEnvironment.static interfaceProvides an interface for initializing an instance ofSzCoreEnvironment. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringThe default instance name to use for the Senzing initialization.static final StringThe default "bootstrap" settings with which to initialize theSzCoreEnvironmentwhen an explicit settings value has not been provided viaSzCoreEnvironment.AbstractBuilder.settings(String). -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedSzCoreEnvironment(SzCoreEnvironment.Initializer initializer) Protected constructor used by theSzCoreEnvironment.Builderto construct the instance. -
Method Summary
Modifier and TypeMethodDescriptionvoiddestroy()Destroys thisSzEnvironmentand invalidates any SDK singleton references that has previously provided.protected <T> TCalled byexecute(Callable)after ensuring that this instance is not destroyed and ensuring any calls todestroy()will block until after this method's invocation is completed.protected <T> TExecutes the specifiedCallabletask viadoExecute(Callable)after ensuring that this instance is not destroyed and will not be destroyed before the task's completion.longImplemented fromSzEnvironment.getActiveConfigId().static SzCoreEnvironmentGets the current active instance ofSzCoreEnvironment.Provides a reference to theSzConfigManagerinstance associated with thisSzEnvironment.Provides a reference to theSzDiagnosticinstance associated with thisSzEnvironment.Provides a reference to theSzEngineinstance associated with thisSzEnvironment.Provides a reference to theSzProductinstance associated with thisSzEnvironment.booleanImplemented fromSzEnvironment.isDestroyed().static SzCoreEnvironment.BuilderCreates a new instance ofSzCoreEnvironment.Builderfor setting up an instance ofSzCoreEnvironment.voidreinitialize(long configId) Implemented fromSzEnvironment.reinitialize(long).protected booleanInternal method that is called bygetActiveInstance()to validate the active instance before returning it.
-
Field Details
-
DEFAULT_INSTANCE_NAME
The default instance name to use for the Senzing initialization. The value is""Senzing Instance". An explicit value can be provided viaSzCoreEnvironment.AbstractBuilder.instanceName(String)during initialization.- Since:
- 4.0.0
- See Also:
-
DEFAULT_SETTINGS
The default "bootstrap" settings with which to initialize theSzCoreEnvironmentwhen an explicit settings value has not been provided viaSzCoreEnvironment.AbstractBuilder.settings(String). If this is used it will initialize Senzing when installed in its default path and provide full access access to only theSzProductinterface as well as limited access to theSzConfigManagerinterface (i.e.: for functionality not dealing with registered configuration ID's). The value of this constant is"{ }".NOTE: Using these settings is only useful for accessing the the full functionality of the
SzProductinterface and limited functionality of theSzConfigManagerinterface sinceSzEngineandSzDiagnosticrequire database access to connect to the Senzing repository. Further, someSzConfigManagerfunctionality (particularly any functionality that works with registered configurations that have configuration ID's) also requires database access to connect to the Senzing repository.The value of this constant is
"{ }".- Since:
- 4.0.0
- See Also:
-
-
Constructor Details
-
SzCoreEnvironment
Protected constructor used by theSzCoreEnvironment.Builderto construct the instance.- Parameters:
initializer- TheSzCoreEnvironment.Initializerwith which to construct (typically an instance ofSzCoreEnvironment.AbstractBuilder).- Since:
- 4.1.0
-
-
Method Details
-
newBuilder
Creates a new instance ofSzCoreEnvironment.Builderfor setting up an instance ofSzCoreEnvironment. Keep in mind that while multipleSzCoreEnvironment.Builderinstances can exists, only one active instance ofSzCoreEnvironmentcan exist at time. An active instance is one that has not yet been destroyed.Alternatively, you can directly call the
Builder()constructor.- Returns:
- The
SzCoreEnvironment.Builderfor configuring and initializing theSzCoreEnvironment. - Since:
- 4.0.0
-
getActiveInstance
Gets the current active instance ofSzCoreEnvironment. An active instance is is one that has been constructed and has not yet been destroyed. There can be at most one active instance. If no active instance exists thennullis returned.- Returns:
- The current active instance of
SzCoreEnvironment, ornullif there is no active instance. - Since:
- 4.0.0
-
execute
Executes the specifiedCallabletask viadoExecute(Callable)after ensuring that this instance is not destroyed and will not be destroyed before the task's completion.This is used by the core implementations of
SzEngine,SzProduct,SzConfigManager,SzConfigandSzDiagnosticto execute their functionality and ensure the environment is stable during execution.If successful, this will return the result of the
Callabletask. If not successful, this will throw any exception produced by theCallabletask, wrapping it in anSzExceptionif it is a checked exception that is not of typeSzException.- Type Parameters:
T- The return type.- Parameters:
task- TheCallabletask to execute.- Returns:
- The result from the
Callabletask. - Throws:
SzException- If theCallabletask triggers a failure.SzEnvironmentDestroyedException- If thisSzCoreEnvironmentinstance has already been destroyed.- Since:
- 4.1.0
-
doExecute
Called byexecute(Callable)after ensuring that this instance is not destroyed and ensuring any calls todestroy()will block until after this method's invocation is completed.If successful, this will return the result of the
Callabletask. If not successful, this will throw any exception produced by theCallabletask. -
getConfigManager
Provides a reference to the
SzConfigManagerinstance associated with thisSzEnvironment.Usage:
// How to obtain an SzConfigManager instance try { // obtain the SzEnvironment (varies by application)SzEnvironmentenv = getEnvironment(); // get the config manager SzConfigManager configMgr = env.getConfigManager(); ... } catch (SzException e) { // handle or rethrow the exception logError("Failed to get SzConfigManager.", e); }Implemented to return an instance of
SzConfigManagerthat will execute all of its functionality viaexecute(Callable). If you need to change the functionality of the returned instance consider usingProxyandInvocationHandlerto proxy the returned instance.- Specified by:
getConfigManagerin interfaceSzEnvironment- Returns:
- The
SzConfigManagerinstance associated with thisSzEnvironment. - Throws:
SzEnvironmentDestroyedException- If thisSzEnvironmentinstance has been destroyed.SzException- If there was a failure in obtaining or initializing theSzConfigManagerinstance.- Since:
- 4.0.0
-
getDiagnostic
Provides a reference to the
SzDiagnosticinstance associated with thisSzEnvironment.Usage:
// How to obtain an SzDiagnostic instance try { // obtain the SzEnvironment (varies by application)SzEnvironmentenv = getEnvironment(); SzDiagnostic diagnostic = env.getDiagnostic(); ... } catch (SzException e) { // handle or rethrow the exception logError("Failed to get SzDiagnostic.", e); }Implemented to return an instance of
SzDiagnosticthat will execute all of its functionality viaexecute(Callable). If you need to change the functionality of the returned instance consider usingProxyandInvocationHandlerto proxy the returned instance.- Specified by:
getDiagnosticin interfaceSzEnvironment- Returns:
- The
SzDiagnosticinstance associated with thisSzEnvironment. - Throws:
SzEnvironmentDestroyedException- If thisSzEnvironmentinstance has been destroyed.SzException- If there was a failure in obtaining or initializing theSzDiagnosticinstance.- Since:
- 4.0.0
-
getEngine
Provides a reference to the
SzEngineinstance associated with thisSzEnvironment.Usage:
// How to obtain an SzEngine instance try { // obtain the SzEnvironment (varies by application)SzEnvironmentenv = getEnvironment(); SzEngine engine = env.getEngine(); ... } catch (SzException e) { // handle or rethrow the exception logError("Failed to get SzEngine.", e); }Implemented to return an instance of
SzEnginethat will execute all of its functionality viaexecute(Callable). If you need to change the functionality of the returned instance consider usingProxyandInvocationHandlerto proxy the returned instance.- Specified by:
getEnginein interfaceSzEnvironment- Returns:
- The
SzEngineinstance associated with thisSzEnvironment. - Throws:
SzEnvironmentDestroyedException- If thisSzEnvironmentinstance has been destroyed.SzException- If there was a failure in obtaining or initializing theSzEngineinstance.- Since:
- 4.0.0
-
getProduct
Provides a reference to the
SzProductinstance associated with thisSzEnvironment.Usage:
// How to obtain an SzProduct instance try { // obtain the SzEnvironment (varies by application)SzEnvironmentenv = getEnvironment(); SzProduct product = env.getProduct(); ... } catch (SzException e) { // handle or rethrow the exception logError("Failed to get SzProduct.", e); }Implemented to return an instance of
SzProductthat will execute all of its functionality viaexecute(Callable). If you need to change the functionality of the returned instance consider usingProxyandInvocationHandlerto proxy the returned instance.- Specified by:
getProductin interfaceSzEnvironment- Returns:
- The
SzProductinstance associated with thisSzEnvironment. - Throws:
SzEnvironmentDestroyedException- If thisSzEnvironmentinstance has been destroyed.SzException- If there was a failure in obtaining or initializing theSzProductinstance.- Since:
- 4.0.0
-
destroy
public void destroy()Destroys this
SzEnvironmentand invalidates any SDK singleton references that has previously provided. If this instance has already been destroyed then this method has no effect.Usage:
// obtain the SzEnvironment (varies by application) SzEnvironment env = getEnvironment(); if (!env.isDestroyed()) { // destroy the environment env.destroy(); }Implemented to block until all concurrent in-flight operations that are executing via the
execute(Callable)are complete before destroying this instance. Once destroyed, a new instance of this class can be created, but only one instance can be active concurrently in the same process.This method will invalidate any
SzEngine,SzProduct,SzDiagnostic,SzConfigManagerorSzConfigthat was provided through this instance.- Specified by:
destroyin interfaceSzEnvironment- Since:
- 4.0.0
-
isDestroyed
public boolean isDestroyed()Implemented fromSzEnvironment.isDestroyed().Checks if this instance has had its
SzEnvironment.destroy()method called.Usage:
// obtain the SzEnvironment (varies by application) SzEnvironment env = getEnvironment(); if (!env.isDestroyed()) { // destroy the environment env.destroy(); }- Specified by:
isDestroyedin interfaceSzEnvironment- Returns:
trueif this instance has had itsSzEnvironment.destroy()method called, otherwisefalse.- Since:
- 4.0.0
-
validateActiveInstance
protected boolean validateActiveInstance()Internal method that is called bygetActiveInstance()to validate the active instance before returning it. It is expected that if this instance is in the process of destroying itself, then this method will block until the completion of thedestroy()method.trueis returned if this instance is active and has not had itsdestroy()method called, otherwisefalseis returned for an instance that was already destroyed.This method should be overridden by derived classes that override
destroy().IMPORTANT: If this instance is in the process of being destroyed (e.g.: waiting for in-flight operations to complete) then this method must block until destruction is complete.
- Returns:
trueif this instance if still active, orfalseif this instance has been destroyed.- Since:
- 4.1.0
-
getActiveConfigId
Implemented fromSzEnvironment.getActiveConfigId().Gets the currently active configuration ID for the
SzEnvironment.Usage:
// How to get the active config ID for the SzEnvironment try { // obtain the SzEnvironment (varies by application) SzEnvironment env = getEnvironment(); // get the active config ID long activeConfigId = env.getActiveConfigId(); // do something with the active config ID (varies by application) SzConfigManager configMgr = env.getConfigManager(); long defaultConfigId = configMgr.getDefaultConfigId(); if (activeConfigId != defaultConfigId) { // reinitialize the environment with the default config ID env.reinitialize(defaultConfigId); } } catch (SzException e) { // handle or rethrow the exception logError("Failed to verify the active config ID.", e); }- Specified by:
getActiveConfigIdin interfaceSzEnvironment- Returns:
- The currently active configuration ID.
- Throws:
SzEnvironmentDestroyedException- If thisSzEnvironmentinstance has been destroyed.SzException- If there was a failure in obtaining the active config ID.- Since:
- 4.0.0
-
reinitialize
Implemented fromSzEnvironment.reinitialize(long).Reinitializes the
SzEnvironmentwith the specified configuration ID.Usage:
// How to get the active config ID for the SzEnvironment try { // obtain the SzEnvironment (varies by application) SzEnvironment env = getEnvironment(); // get the active config ID long activeConfigId = env.getActiveConfigId(); // do something with the active config ID (varies by application) SzConfigManager configMgr = env.getConfigManager(); long defaultConfigId = configMgr.getDefaultConfigId(); if (activeConfigId != defaultConfigId) { // reinitialize the environment with the default config ID env.reinitialize(defaultConfigId); } } catch (SzException e) { // handle or rethrow the exception logError("Failed to verify the active config ID.", e); }- Specified by:
reinitializein interfaceSzEnvironment- Parameters:
configId- The configuration ID with which to initialize.- Throws:
SzEnvironmentDestroyedException- If thisSzEnvironmentinstance has been destroyed.SzException- If there was a failure reinitializing.- Since:
- 4.0.0
-