
Invoking components
Components with modules can use components on any node of cluster on IBM® Business Process Manager.
Before you begin
About this task
Tip: A component in a
module can invoke a component within the same module, known as an intra-module invocation. Implement
external calls (inter-module invocations) by exporting the interface in the providing component and
importing the interface in the calling component.
Important: When invoking a
component that resides on a different server than the one on which the calling module is running,
you must perform additional configurations to the servers. The configurations required depend on
whether the component is called asynchronously or synchronously. How to configure the application
servers in this case is described in related tasks.
Procedure
Example of invoking a component
The following example creates a ServiceManager
class.
ServiceManager serviceManager = new ServiceManager();
The following example uses the ServiceManager class to obtain a list of
components from a file that contains the component
references.
InputStream myReferences = new FileInputStream("MyReferences.references");
ServiceManager serviceManager = new ServiceManager(myReferences);
The following code locates a component that implements the StockQuote Java
interface.
StockQuote stockQuote = (StockQuote)serviceManager.locateService("stockQuote");
The following code locates a component that implements either a Java or WSDL port type interface.
The calling module uses the Service interface to interact with the
component.
Tip: If the component implements a Java interface, the component can
be invoked through either the interface or the invoke() method.
Service stockQuote = (Service)serviceManager.locateService("stockQuote");
The following example shows MyValue, code that calls another
component.
public class MyValueImpl implements MyValue {
public float myValue throws MyValueException {
ServiceManager serviceManager = new ServiceManager();
// variables
Customer customer = null;
float quote = 0;
float value = 0;
// invoke
CustomerInfo cInfo =
(CustomerInfo)serviceManager.locateService("customerInfo");
customer = cInfo.getCustomerInfo(customerID);
if (customer.getErrorMsg().equals("")) {
// invoke
StockQuote sQuote =
(StockQuote)serviceManager.locateService("stockQuote");
Ticket ticket = sQuote.getQuote(customer.getSymbol());
// … do something else …
quote = sQuote.getQuoteResponse(ticket, Service.WAIT);
// assign
value = quote * customer.getNumShares();
} else {
// throw
throw new MyValueException(customer.getErrorMsg());
}
// reply
return value;
}
}