Develop service components to provide reusable logic to multiple
applications within your server.
Before you begin
This task assumes that you have already developed and identified processing
that is useful for multiple modules.
Why and when to perform this task
Multiple modules can use a service component. Exporting a service
component makes it available to other modules that refer to the service component
through an interface. This task describes how to build the service component
so that other modules can use it.
Note: A single service component
can contain multiple interfaces.
Steps for this task
- Define the data object to move data between the caller and the
service component.
The data object and its type is part of the
interface between the callers and the service component.
- Define an interface that the callers will use to reference the
service component.
This interface definition names the service
component and lists any methods available within the service component.
- Develop the class that defines the implementation.
- If the component is long running (or asynchronous), continue with
step 4.
- If the component is not long running (or synchronous), continue with
step 5.
- Develop an asynchronous implementation.
Important: An asynchronous component interface cannot have
a joinsTransaction property set to true.
- Define the interface that represents the synchronous service
component.
- Define the implementation of the service component.
- Continue with step 6.
- Develop a synchronous implementation.
- Define the interface that represents the synchronous service
component.
- Define the implementation of the service component.
- Save the component interfaces and implementations
in files with a .java extension.
- Package the service module and necessary resources
in a JAR file.
See "Deploying a module to a production server" in
this information center for a description of steps 7 through 9.
- Run the serviceDeploy command to create an installable
EAR file containing the application.
- Install the application on the server node.
- Optional: Configure the wires between the callers and
the corresponding service component, if calling a service component in another
service module.
The "Administering" section of this information
center describes configuring the wires.
Examples of developing components
Examples of developing components
This example shows
a synchronous service component that implements a single method, CustomerInfo.
The first section defines the interface to the service component that implements
a method called getCustomerInfo.
public interface CustomerInfo {
public Customer getCustomerInfo(String customerID);
}
The following block of code implements the service component.
public class CustomerInfoImpl implements CustomerInfo {
public Customer getCustomerInfo(String customerID) {
Customer cust = new Customer();
cust.setCustNo(customerID);
cust.setFirstName("Victor");
cust.setLastName("Hugo");
cust.setSymbol("IBM");
cust.setNumShares(100);
cust.setPostalCode(10589);
cust.setErrorMsg("");
return cust;
}
}
This example develops an asynchronous service component.
The first section of code defines the interface to the service component that
implements a method called getQuote.
public interface StockQuote {
public float getQuote(String symbol);
}
The following section is the implementation of the class
associated with StockQuote.
public class StockQuoteImpl implements StockQuote {
public float getQuote(String symbol) {
return 100.0f;
}
}
This next section of code implements the asynchronous
interface, StockQuoteAsync.
public interface StockQuoteAsync {
// deferred response
public Ticket getQuoteAsync(String symbol);
public float getQuoteResponse(Ticket ticket, long timeout);
// callback
public Ticket getQuoteAsync(String symbol, StockQuoteCallback callback);
}
This section is the interface, StockQuoteCallback, which
defines the onGetQuoteResponse method.
public interface StockQuoteCallback {
public void onGetQuoteResponse(Ticket ticket, float quote);
}
What to do next
Invoke the service.
Last updated: Thu 26 Oct 2006 10:30:05
(c) Copyright IBM Corporation 2005, 2006.
This information center is powered by Eclipse technology (http://www.eclipse.org)