ServiceCallback interface

Service components that need to handle asynchronous callback interactions implement this interface.

Purpose

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.

Examples

This program implements a service that is an alarm for a client.
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()));
        }
    }
}
Related reference
Component interface
EndPointReference interface
EndPointReferenceFactory interface
Service exceptions
InterfaceType interface
Service interface
ServiceImplAsync interface
ServiceImplSync interface
ServiceManager class
Ticket interface
Related information
Interface ServiceCallback APIs

Terms of use |

Last updated: Tue Feb 21 17:21:49 2006

(c) Copyright IBM Corporation 2005.
This information center is powered by Eclipse technology (http://www.eclipse.org)