Class SzCoreEnvironment

java.lang.Object
com.senzing.sdk.core.SzCoreEnvironment
All Implemented Interfaces:
SzEnvironment

public final class SzCoreEnvironment extends Object implements SzEnvironment
Provides the core implementation of SzEnvironment that directly initializes the Senzing SDK modules and provides management of the Senzing environment in this process. .
  • Field Details

  • Method Details

    • newBuilder

      public static SzCoreEnvironment.Builder newBuilder()
      Creates a new instance of SzCoreEnvironment.Builder for setting up an instance of SzCoreEnvironment. Keep in mind that while multiple SzCoreEnvironment.Builder instances can exists, only one active instance of SzCoreEnvironment can exist at time. An active instance is one that has not yet been destroyed.
      Returns:
      The SzCoreEnvironment.Builder for configuring and initializing the SzCoreEnvironment.
    • getActiveInstance

      public static SzCoreEnvironment getActiveInstance()
      Gets the current active instance of SzCoreEnvironment. 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 then null is returned.
      Returns:
      The current active instance of SzCoreEnvironment, or null if there is no active instance.
    • getConfigManager

      public SzConfigManager getConfigManager() throws IllegalStateException, SzException
      Description copied from interface: SzEnvironment
      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);
      }
      

      Specified by:
      getConfigManager in interface SzEnvironment
      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

      public SzDiagnostic getDiagnostic() throws IllegalStateException, SzException
      Description copied from interface: SzEnvironment
      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);
      }
      

      Specified by:
      getDiagnostic in interface SzEnvironment
      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.
    • getEngine

      public SzEngine getEngine() throws IllegalStateException, SzException
      Description copied from interface: SzEnvironment
      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);
      }
      

      Specified by:
      getEngine in interface SzEnvironment
      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.
    • getProduct

      public SzProduct getProduct() throws IllegalStateException, SzException
      Description copied from interface: SzEnvironment
      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);
      }
      

      Specified by:
      getProduct in interface SzEnvironment
      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.
    • destroy

      public void destroy()
      Description copied from interface: SzEnvironment
      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();
      }
      
      

      Specified by:
      destroy in interface SzEnvironment
    • isDestroyed

      public boolean isDestroyed()
      Description copied from interface: SzEnvironment
      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:
      isDestroyed in interface SzEnvironment
      Returns:
      true if this instance has had its SzEnvironment.destroy() method called, otherwise false.
    • getActiveConfigId

      public long getActiveConfigId() throws IllegalStateException, SzException
      Description copied from interface: SzEnvironment
      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:
      getActiveConfigId in interface SzEnvironment
      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

      public void reinitialize(long configId) throws IllegalStateException, SzException
      Description copied from interface: SzEnvironment
      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);
      }
      

      Specified by:
      reinitialize in interface SzEnvironment
      Parameters:
      configId - The configuration ID with which to initialize.
      Throws:
      IllegalStateException - If this SzEnvironment instance has been destroyed.
      SzException - If there was a failure reinitializing.