Package com.senzing.sdk
Interface SzEnvironment
- All Known Implementing Classes:
SzCoreEnvironment
public interface SzEnvironment
Provides a factory interface for obtaining the references to the Senzing SDK
singleton instances that have been initialized.
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
-
Method Summary
Modifier and TypeMethodDescriptionvoiddestroy()Destroys thisSzEnvironmentand invalidates any SDK singleton references that has previously provided.longGets the currently active configuration ID for theSzEnvironment.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.booleanChecks if this instance has had itsdestroy()method called.voidreinitialize(long configId) Reinitializes theSzEnvironmentwith the specified configuration ID.
-
Method Details
-
getProduct
Provides a reference to theSzProductinstance 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); }- 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
-
getEngine
Provides a reference to theSzEngineinstance 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); }- 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
-
getConfigManager
Provides a reference to theSzConfigManagerinstance 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); }- 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 theSzDiagnosticinstance 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); }- 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
-
getActiveConfigId
Gets the currently active configuration ID for theSzEnvironment.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); }- 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
Reinitializes theSzEnvironmentwith 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); }- 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
-
destroy
void destroy()Destroys thisSzEnvironmentand 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(); }- Since:
- 4.0.0
-
isDestroyed
boolean isDestroyed()Checks if this instance has had itsdestroy()method called.Usage:
// obtain the SzEnvironment (varies by application) SzEnvironment env = getEnvironment(); if (!env.isDestroyed()) { // destroy the environment env.destroy(); }- Returns:
trueif this instance has had itsdestroy()method called, otherwisefalse.- Since:
- 4.0.0
-