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 Details

    • getProduct

      Provides a reference to the SzProduct instance associated with this SzEnvironment.

      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 this SzEnvironment.
      Throws:
      IllegalStateException - If this SzEnvironment instance has been destroyed.
      SzException - If there was a failure in obtaining or initializing the SzProduct instance.
    • getConfig

      Provides a reference to the SzConfig instance associated with this SzEnvironment.

      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 this SzEnvironment.
      Throws:
      IllegalStateException - If this SzEnvironment instance has been destroyed.
      SzException - If there was a failure in obtaining or initializing the SzConfig instance.
    • getEngine

      Provides a reference to the SzEngine instance associated with this SzEnvironment.

      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 this SzEnvironment.
      Throws:
      IllegalStateException - If this SzEnvironment instance has been destroyed.
      SzException - If there was a failure in obtaining or initializing the SzEngine instance.
    • getConfigManager

      Provides a reference to the SzConfigManager instance associated with this SzEnvironment.

      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 this SzEnvironment.
      Throws:
      IllegalStateException - If this SzEnvironment instance has been destroyed.
      SzException - If there was a failure in obtaining or initializing the SzConfigManager instance.
    • getDiagnostic

      Provides a reference to the SzDiagnostic instance associated with this SzEnvironment.

      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 this SzEnvironment.
      Throws:
      IllegalStateException - If this SzEnvironment instance has been destroyed.
      SzException - If there was a failure in obtaining or initializing the SzDiagnostic instance.
    • getActiveConfigId

      long getActiveConfigId() throws IllegalStateException, SzException
      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);
      }
      

      Returns:
      The currently active configuration ID.
      Throws:
      IllegalStateException - If this SzEnvironment instance has been destroyed.
      SzException - If there was a failure in obtaining the active config ID.
    • reinitialize

      void reinitialize(long configId) throws IllegalStateException, SzException
      Reinitializes the SzEnvironment 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 this SzEnvironment instance has been destroyed.
      SzException - If there was a failure reinitializing.
    • destroy

      void destroy()
      Destroys this SzEnvironment 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 its destroy() 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 its destroy() method called, otherwise false.