Using Connect Java rules versus function rules to call external Java methods
A developer asks: I have an existing Java class with fewer than a dozen methods that do computation and return a result (no I/O, no external data, no side effects). I need to integrate these within a Process Commander application. I have the Java source code for the class.
Create a Rule-Utility-Library. Create a Rule-Utility-Function for each method. Call the functions from an activity, expression, anywhere.
Use a Rule-Connect-Java. Create an activity that accepts a parameter to determine which original Java method to call.
When is Design B preferable? Why? Also, we do observe that for Design B, the app server needs to be stopped and restarted whenever the CLASS files change.
if it's a simple calculation you're trying to perform, where methods don't depend on each other, where you don't need to keep the code organized, where you don't need member variables – that is, it's less object-oriented and instead mere calculation - then the library and function rule approach is fine..
But if you're doing something that's more complex, requires saving state, and so on, it is better to code it in a Java class and then plug it in with a Connect Java rule.
The other benefits of Connect Java rules are:
- You can use the Performance tool
- You don't need the source code but can work with just the class files.
- Tracer output is more complete. With Tracer you don't see the step where you're calling an external class if that's embedded within a function.