Using existing Java code — A comparison of design alternatives

Concepts and terms

PRPC provides multiple ways to take advantage of existing Java code when developing an application. For example:

This topic describes when you might use each option.

EJB and Java connectors

When your application needs to send requests to an external EJB application, use an EJB connector (Rule-Connect-EJB).

When your application is to send requests to an external Java-based application that is not an EJB, or interact with an external Java class that is maintained outside of PRPC, use a Java connector (Rule-Connect-Java).

By using a connector rule to call an external Java class, you can reuse the connector rule in multiple places, while maintaining the Java code the connector interacts with in a single place. Additionally, when connector rules run, they set Performance tool timers for the external connections. If a performance issue or question arises, you can determine how much time the external Java class spends processing the connector's request. You can also track connector rules in the Tracer tool, which can record the start and end of connector operations.

For PRPC to access the external application or Java class, place the .jar or class files in both the PRPC compile time and runtime class paths. See the PDN article About the Process Commander class paths.

Java steps

While a Java step in an activity can call external Java classes, as a best practice, use Java connectors. Pegasystems design and development guardrails encourage you to use Java steps in activities sparingly. Don't use Java in an activity step when you can use a rule to accomplish the processing goal.

However, there are specific and limited cases when you do need to use Java in an activity.

For example, use a Java step to call a Java method in the Public API. Specifically, to create custom authentication activities, use Java steps to call the setSecurityProfile() and setUserAuthenticated() Java methods of the PRAuthentication interface. (For information about writing custom authentication activities, search for the PDN article Authentication
in Process Commander
, a document available in the Integration area.)

Function rules

If the existing Java code that you want to use is a procedural method or routine that does not use member variables, refer to other Java classes, or maintain state, you can create a function rule (Rule-Utility-Function rule type) and store the code in the rule. That way you can maintain the code within the PegaRULES database as a rule that is subject to versioning, which means the correct version of the function rule is selected at runtime based on a user´s RuleSet list. However, the SmartBuild design and development guardrails encourage you to use custom Java sparingly.

Function rules typically perform simple computations or transformations. You can use them in activity preconditions and transitions, when rules, expressions, and so on. You can update them and recompile them without stopping and restarting PRPC.

Related topics About EJB Connect rules
About Java Connect rules
About Function rules
About Activity rules

UpConcepts