비동기 콜백 대화를 핸들해야 하는 서비스 구성요소가 이 인터페이스를 구현합니다.
이 인터페이스의 메소드를 사용하여 서비스에 대한 비동기 요청을 작성한 구성요소에 응답을 리턴할 수 있습니다. 성공하려면 클라이언트가 서비스를 호출할 때 구성요소가 서비스에 티켓을 전달해야 합니다.
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())); } } }