ClassNotFoundException / sharing instances between scopes

Hi,

I’m quite new with Ignition SDK and this is my first post here so please be patient :slight_smile:

I created a module that exposes some methods so they are available as functions in Jython scripts. Module performs some initializations in the gateway hook and amongst other things instantiates a singleton class.

I’m receiving the following error when calling one of the functions in a Jython script at designer or client scope (it works OK at gateway scope):
ClassNotFoundException: com.inductiveautomation.ignition.gateway.datasource.query.DBQuery$StreamingHandler).

In module.xml I added my module JAR for the 3 scopes (e.g. MyModule.jar). I also added there the 3 “hooks” (client, designer and gateway) where I expose my methods to the different scopes. In those hooks I invoke addScriptModule with an instance of my API class as a parameter. None of the API methods call directly DBQuery class.

DBQuery.StreamingHandler is not invoked directly on the exposed method, but depending on some situations it will call different chained classes until reaching a class using DBQuery. What should I do to fix this issue? Is there a way to have a function at client or designer scope indirectly invoking some class defined only at gateway level?

On the other hand, this leads to a second question: in principle this class not found error should not have happened when calling the function in Jython, as at module startup a singleton class -mentioned at the top- was created in the gateway hook (this class uses DBQuery after creating the instance to load some data). So it seems singleton instance created at module startup in the gateway hook is not visible in the other scopes as those end up creating separate instances. Is possible all scopes “see” the same instance? Thanks in advance!

I think you need to go into a little more detail on what these functions are doing exactly. It sounds like a situation where you don’t actually want to execute the same logic on the client, but instead want to do an RPC call to the gateway, execute it there, and return the result.

As for your second question, no, you can’t share a singleton across the three scopes. Each scope isn’t even being loaded on the same JVM…

[quote=“Kevin.Herron”]I think you need to go into a little more detail on what these functions are doing exactly. It sounds like a situation where you don’t actually want to execute the same logic on the client, but instead want to do an RPC call to the gateway, execute it there, and return the result.

As for your second question, no, you can’t share a singleton across the three scopes. Each scope isn’t even being loaded on the same JVM…[/quote]

Hi, Kevin

understood. Right, since scopes are loaded in different JVM it seems what I need is to do RPC calls for the API methods at designer/client scopes as all logic behind those functions is gateway-oriented. Will look into ModuleRPCFactory. Thanks for the clarification.