ServiceCallback 인터페이스

비동기 콜백 대화를 핸들해야 하는 서비스 구성요소가 이 인터페이스를 구현합니다.

용도

이 인터페이스의 메소드를 사용하여 서비스에 대한 비동기 요청을 작성한 구성요소에 응답을 리턴할 수 있습니다. 성공하려면 클라이언트가 서비스를 호출할 때 구성요소가 서비스에 티켓을 전달해야 합니다.

이 프로그램은 클라이언트에 대한 알람 서비스를 구현합니다.
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()));
        }
    }
}
관련 참조
Component 인터페이스
EndPointReference 인터페이스
EndPointReferenceFactory 인터페이스
서비스 예외
InterfaceType 인터페이스
Service 인터페이스
ServiceImplAsync 인터페이스
ServiceImplSync 인터페이스
ServiceManager 클래스
Ticket 인터페이스
관련 정보
Interface ServiceCallback APIs

이용약관 |

최종 갱신: 2006년 4월 13일

(c) Copyright IBM Corporation 2005, 2006.
이 Information Center는 Eclipse 기술을 기반으로 합니다. (http://www.eclipse.org 웹 사이트 참조)