Thanks to all of you for your helpful comments.
As shown in the example Scripting Library module structure tree I provided in my previous message,
- I have defined separate interfaces (and abstract base classes) for each scripting function F1 and F2 in Common.
The purpose of this step is to follow @pturmel's comment "An interface in Common that stubs the functions for which you need RPC. Only those functions, not anything else your scripts might do."
- To follow @pturmel 's comment "An implementation of that interface in Client (and indirectly Designer) that delegates to the RPC invocation methods for each such function.",
The following code snippet has been developed in ClientScriptModuleF1 that makes this class delegate calls to the rpc object. The same logic has been implemented in ClientScriptModuleF2.
package com.inductiveautomation.ignition.scriptinglibrary.client;
import com.inductiveautomation.ignition.client.gateway_interface.ModuleRPCFactory;
import com.inductiveautomation.ignition.scriptinglibrary.common.InterfceClassF1 ;
import com.inductiveautomation.ignition.scriptinglibrary.common.AbstractScriptModuleF1;
public class ClientScriptModuleF1 extends AbstractScriptModuleF1 {
private final InterfceClassF1 rpc;
public ClientScriptModuleF1() {
rpc = ModuleRPCFactory.create(
"com.inductiveautomation.ignition.scriptinglib.ScriptingLibrary",
InterfceClassF1.class
);
}
@Override
protected String FunctionFromF1Impl(String param1, String param2) {
return rpc.FunctionFromF1(param1, param2);
}
}
Also, the following code snippet has been included in ScriptingLibraryClientHook and ScriptingLibraryDesignerHook
@Override
public void initializeScriptManager(ScriptManager manager) {
super.initializeScriptManager(manager);
manager.addScriptModule(
"system.newlib",
new ClientScriptModuleF1(),
new PropertiesFileDocProvider());
manager.addScriptModule(
"system.newlib",
new ClientScriptModuleF2(),
new PropertiesFileDocProvider());
}
}
- To follow @pturmel 's third comment, I have developed GatewayScriptModuleF1 and GatewayScriptModuleF2 classes as implementation of the interfaces in Gateway that actually does the work.
And
To manage multiple objects in RPC handler I added the following class to Gateway scope as suggested by @Kevin.Herron:
package com.inductiveautomation.ignition.scriptinglibrary.gateway;
import com.inductiveautomation.ignition.scriptinglibrary.common.InterfceClassF1;
import com.inductiveautomation.ignition.scriptinglibrary.common.InterfceClassF2;
public class MultiplexingRPCHandler implements InterfceClassF1, InterfceClassF2 {
private final GatewayScriptModuleF1 scriptModuleF1;
private final GatewayScriptModuleF2 scriptModuleF2;
public MultiplexingRPCHandler(GatewayScriptModuleF1 scriptModuleF1, GatewayScriptModuleF2 scriptModuleF2) {
this.scriptModuleF1 = scriptModuleF1;
this.scriptModuleF2 = scriptModuleF2;
}
@Override
public String FunctionFromF1(String param1, String param2) {
return scriptModuleF1.FunctionFromF1Impl(param1, param2);
}
@Override
public String FunctionFromF2(String param1, String param2) {
return scriptModuleF2.FunctionFromF2Impl(param1, param2);
}
}
Then, revised ScriptingLibraryGatewayHook as follows:
public class ScriptingLibraryGatewayHook extends AbstractGatewayModuleHook {
private final Logger logger = LoggerFactory.getLogger(getClass());
private final GatewayScriptModuleF1 scriptModuleF1 = new GatewayScriptModuleF1();
private final GatewayScriptModuleF2 scriptModuleF2 = new GatewayScriptModuleF2();
private final MultiplexingRPCHandler rpcHandler = new MultiplexingRPCHandler(scriptModuleF1, scriptModuleF2);
@Override
public void setup(GatewayContext context) {
}
@Override
public void startup(LicenseState activationState) {
}
@Override
public void shutdown() {
}
@Override
public void initializeScriptManager(ScriptManager manager) {
super.initializeScriptManager(manager);
manager.addScriptModule(
"system.newlib",
scriptModuleF1,
new PropertiesFileDocProvider());
manager.addScriptModule(
"system.newlib",
scriptModuleF2,
new PropertiesFileDocProvider());
}
@Override
public Object getRPCHandler(ClientReqSession session, String projectName) {return rpcHandler;}
}
When building and testing my developed module, it appears to work correctly. Would you mind confirming whether I am on the right track?