package initialization; import com.senzing.sdk.*; import com.senzing.sdk.core.SzCoreEnvironment; /** * Provides an example of priming the engine to improve the performance * of subsequent engine function calls. */ public class EnginePriming { public static void main(String[] args) { // get the senzing repository settings String settings = System.getenv("SENZING_ENGINE_CONFIGURATION_JSON"); if (settings == null) { System.err.println("Unable to get settings."); throw new IllegalArgumentException("Unable to get settings"); } // create a descriptive instance name (can be anything) String instanceName = EnginePriming.class.getSimpleName(); // initialize the Senzing environment SzEnvironment env = SzCoreEnvironment.newBuilder() .settings(settings) .instanceName(instanceName) .verboseLogging(false) .build(); try { SzEngine engine = env.getEngine(); long start = System.nanoTime(); System.out.println("Priming Senzing engine..."); engine.primeEngine(); long duration = (System.nanoTime() - start) / ONE_MILLION; System.out.println("Primed Senzing engine. (" + duration + "ms)"); } catch (SzException e) { // handle any exception that may have occurred System.err.println("Senzing Error Message : " + e.getMessage()); System.err.println("Senzing Error Code : " + e.getErrorCode()); e.printStackTrace(); throw new RuntimeException(e); } catch (Exception e) { System.err.println(); System.err.println("*** Terminated due to critical error ***"); e.printStackTrace(); if (e instanceof RuntimeException) { throw ((RuntimeException) e); } throw new RuntimeException(e); } finally { // IMPORTANT: make sure to destroy the environment env.destroy(); } } private static final long ONE_MILLION = 1000000L; }