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();
-
Method Summary
Modifier and TypeMethodDescriptionvoid
destroy()
Destroys thisSzEnvironment
and invalidates any SDK singleton references that has previously provided.long
Gets the currently active configuration ID for theSzEnvironment
.Provides a reference to theSzConfig
instance associated with thisSzEnvironment
.Provides a reference to theSzConfigManager
instance associated with thisSzEnvironment
.Provides a reference to theSzDiagnostic
instance associated with thisSzEnvironment
.Provides a reference to theSzEngine
instance associated with thisSzEnvironment
.Provides a reference to theSzProduct
instance associated with thisSzEnvironment
.boolean
Checks if this instance has had itsdestroy()
method called.void
reinitialize
(long configId) Reinitializes theSzEnvironment
with the specified configuration ID.
-
Method Details
-
getProduct
Provides a reference to theSzProduct
instance associated with thisSzEnvironment
.Usage:
// How to obtain an SzProduct instance try { // obtain the SzEnvironment (varies by application)
SzEnvironment
env = getEnvironment(); SzProduct product = env.getProduct(); ... } catch (SzException e) { // handle or rethrow the exception logError("Failed to get SzProduct.", e); }- Returns:
- The
SzProduct
instance associated with thisSzEnvironment
. - Throws:
IllegalStateException
- If thisSzEnvironment
instance has been destroyed.SzException
- If there was a failure in obtaining or initializing theSzProduct
instance.
-
getConfig
Provides a reference to theSzConfig
instance associated with thisSzEnvironment
.Usage:
// How to obtain an SzConfig instance try { // obtain the SzEnvironment (varies by application)
SzEnvironment
env = getEnvironment(); SzConfig config = env.getConfig(); ... } catch (SzException e) { // handle or rethrow the exception logError("Failed to get SzConfig.", e); }- Returns:
- The
SzConfig
instance associated with thisSzEnvironment
. - Throws:
IllegalStateException
- If thisSzEnvironment
instance has been destroyed.SzException
- If there was a failure in obtaining or initializing theSzConfig
instance.
-
getEngine
Provides a reference to theSzEngine
instance associated with thisSzEnvironment
.Usage:
// How to obtain an SzEngine instance try { // obtain the SzEnvironment (varies by application)
SzEnvironment
env = getEnvironment(); SzEngine engine = env.getEngine(); ... } catch (SzException e) { // handle or rethrow the exception logError("Failed to get SzEngine.", e); }- Returns:
- The
SzEngine
instance associated with thisSzEnvironment
. - Throws:
IllegalStateException
- If thisSzEnvironment
instance has been destroyed.SzException
- If there was a failure in obtaining or initializing theSzEngine
instance.
-
getConfigManager
Provides a reference to theSzConfigManager
instance associated with thisSzEnvironment
.Usage:
// How to obtain an SzConfigManager instance try { // obtain the SzEnvironment (varies by application)
SzEnvironment
env = 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
SzConfigManager
instance associated with thisSzEnvironment
. - Throws:
IllegalStateException
- If thisSzEnvironment
instance has been destroyed.SzException
- If there was a failure in obtaining or initializing theSzConfigManager
instance.
-
getDiagnostic
Provides a reference to theSzDiagnostic
instance associated with thisSzEnvironment
.Usage:
// How to obtain an SzDiagnostic instance try { // obtain the SzEnvironment (varies by application)
SzEnvironment
env = getEnvironment(); SzDiagnostic diagnostic = env.getDiagnostic(); ... } catch (SzException e) { // handle or rethrow the exception logError("Failed to get SzDiagnostic.", e); }- Returns:
- The
SzDiagnostic
instance associated with thisSzEnvironment
. - Throws:
IllegalStateException
- If thisSzEnvironment
instance has been destroyed.SzException
- If there was a failure in obtaining or initializing theSzDiagnostic
instance.
-
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:
IllegalStateException
- If thisSzEnvironment
instance has been destroyed.SzException
- If there was a failure in obtaining the active config ID.
-
reinitialize
Reinitializes theSzEnvironment
with 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 configuraiton ID with which to initialize.- Throws:
IllegalStateException
- If thisSzEnvironment
instance has been destroyed.SzException
- If there was a failure reinitializing.
-
destroy
void destroy()Destroys thisSzEnvironment
and 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(); }
-
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:
true
if this instance has had itsdestroy()
method called, otherwisefalse
.
-