Service components that need to handle asynchronous callback interactions implement this interface.
Use the method in this interface to return a response to a component that has made an asynchronous request to the service. To succeed, the component must pass the service a ticket when the client invokes the service.
package sample.alarm; import java.util.Date; import com.ibm.websphere.sca.Service; import com.ibm.websphere.sca.ServiceCallback; import com.ibm.websphere.sca.ServiceManager; import com.ibm.websphere.sca.Ticket; import com.ibm.websphere.sca.scdl.OperationType; import com.ibm.websphere.sca.scdl.Reference; import com.ibm.websphere.sca.sdo.DataFactory; import commonj.sdo.DataObject; import commonj.sdo.Type; /* * This code implements the alarm interface and invokes the timer asynchronously. */ public class SimpleDIIAlarmImpl implements SimpleAlarm, ServiceCallback { public void setAlarm(String name, int duration) { ServiceManager serviceManager = new ServiceManager(); // Submit the request // Get the setTimer input type and construct the argument accordingly Service asyncTimerService = (Service) serviceManager.locateService("timer"); Reference reference = asyncTimerService.getReference(); OperationType operationType = reference.getOperationType("startTimer"); Type inputType = operationType.getInputType(); DataFactory dataFactory = DataFactory.INSTANCE; DataObject input = dataFactory.create(inputType); input.set(0, new Integer(duration)); input.set(1, name); // Invoke the timer service Ticket ticket = asyncTimerService.invokeAsyncWithCallback("startTimer", input); System.out.println("Sent async with callback."); } /* * @see com.ibm.websphere.sca.ServiceCallback#onInvokeResponse * (com.ibm.websphere.sca.Ticket, java.lang.Object, java.lang.Exception) */ public void onInvokeResponse(Ticket arg0, Object arg1, Exception arg2) { System.out.println("onInvokeResponse()"); if (arg2 != null) { System.out.println("Timer ran into exception: " + arg2.getMessage()); } else { System.out.println("Alarm " + arg1 + " went off at " + new Date(System.currentTimeMillis())); } } }
Parent topic: Programming interfaces
Related reference
Component interface
DataFactory interface
EndPointReference interface
EndPointReferenceFactory interface
Service exceptions
InterfaceType interface
Service interface
ServiceImplAsync interface
ServiceImplSync interface
ServiceManager class
Ticket interface
Related information
Interface ServiceCallback APIs
Last updated: Tue Sep 20 03:22:37 2005
Copyright IBM Corporation 2005.
This information center is powered by Eclipse technology (http://www.eclipse.org)