Class NCEmbeddedProbe


  • public class NCEmbeddedProbe
    extends Object
    Embedded probe controller. Typically, data probes are launched in their own independent JVMs. However, in some cases it is more convenient for model implementation or preferable for performance reasons to host a data model (and hence the data probe) in the same "client" JVM.

    The standard processing flow with the data probe running in a separate JVM looks like this:
    App ⇒ JVM1(REST Server) ⇒ JVM2(Probe) ⇒ JVM1(REST Server) ⇒ App
    There are at least 4 networks hops between client application request and response.

    However, when using native Java Client or Java Test Client in embedded probe mode the processing flow is shortened:
    JVM1(App) ⇒ JVM2(REST Server) ⇒ JVM1(Probe ⇒ App)
    In this case there are only 2 hops as both client application and the data probe (and the model) are hosted in the same JVM.

    Notes:

    • Embedded probe is only available for JVM processes (and can be used with any JVM languages).
    • There can be only one embedded probe per JVM.
    • Once data probe is stopped and cannot be started again in the same JVM.
    • Even though the caller can register local-JVM listener for the query results, these results will still be asynchronously delivered to the REST server in the usual manner so that other clients could fetch these results to maintain internal logging, tracing and metrics. If the client application hosting data model and its probe is the only client for that model it needs to cancel the request on the REST server after receiving a local-JVM callback to release associated resources on the REST server.
    • Constructor Detail

      • NCEmbeddedProbe

        public NCEmbeddedProbe()
    • Method Detail

      • start

        public static boolean start​(String cfgFile)
        Start the embedded probe with given configuration file. It is equivalent to starting a probe using -config=cfgFile command line argument.
        Parameters:
        cfgFile - Configuration file path. It should be either a full path or the file name that can be found in the current working directory or on the classpath as a class loader resource.
        Returns:
        Whether or not probe started ok.
        Throws:
        org.apache.nlpcraft.common.NCException - Thrown in case of any errors starting the data probe.
      • start

        @SafeVarargs
        public static boolean start​(Class<? extends NCModel>... mdlClasses)
        Starts the embedded probe with default configuration and specified models to deploy.
        Parameters:
        mdlClasses - One or more data model classes to be deployed by the embedded probe.
        Returns:
        Whether or not probe started ok.
        Throws:
        org.apache.nlpcraft.common.NCException - Thrown in case of any errors starting the data probe.
      • start

        @SafeVarargs
        public static boolean start​(String probeId,
                                    String tok,
                                    String upLink,
                                    String dnLink,
                                    Class<? extends NCModel>... mdlClasses)
        Starts the embedded probe with default configuration and specified overrides.
        Parameters:
        probeId - Probe ID.
        tok - Probe token.
        upLink - Probe up-link to the server.
        dnLink - Probe down-link from the server.
        mdlClasses - One or more data model classes to be deployed by the embedded probe.
        Returns:
        Whether or not probe started ok.
        Throws:
        org.apache.nlpcraft.common.NCException - Thrown in case of any errors starting the data probe.
      • stop

        public static void stop()
        Stops the embedded probe, if it was started before. Note that the probe cannot be started again in the same JVM process.
        Throws:
        org.apache.nlpcraft.common.NCException - Thrown in case of any errors stopping the data probe.
      • registerCallback

        public static void registerCallback​(Consumer<NCEmbeddedResult> cb)
        Registers the callback on query processing results. Results from all models deployed on this embedded probe will trigger this callback.
        Parameters:
        cb - Callback to register.
        Throws:
        org.apache.nlpcraft.common.NCException - Thrown in case of any errors registering a callback.
      • unregisterCallback

        public static void unregisterCallback​(Consumer<NCEmbeddedResult> cb)
        Unregisters previously registered callback. Ignored if given callback wasn't registered before.
        Parameters:
        cb - Callback to unregister.
        Throws:
        org.apache.nlpcraft.common.NCException - Thrown in case of any errors unregistering a callback.