Skip Navigation

Multiple Responses Handling

As described in this chapter, the host communications service sends commands to the host and receives a response. When sending commands to the Sabre Host for specific scenarios the host may respond back with multiple responses.

As described in this chapter, the host communications service sends commands to the host and receives a response. When sending commands to the Sabre Host for specific scenarios the host may respond back with multiple responses. Using the same com.sabre.edge.cf.host.Communication service it is possible to handle all upcoming responses being sure that other Red App will not take over it using the Locking mechanism. To achieve this, follow the guideline below:

  1. Write a listener class listening on HOST_RESPONSE event and register it in redapp.xml.

public class HostResponseListener implements IEventListener
{
    @Override
    public void handleEvent(IEvent event)
    {
        HostResponse rsp = (HostResponse) event.getContext().getResponse();
        // here you can process host response (rsp) or
        // you can store it and process later
    }
}
  1. Obtain ISRWCommunication service

ISRWCommunication com = Activator.getDefault().getServiceReference(ISRWCommunication.class);
  1. Lock host using LockingServiceClient instance

ClientResponse <LockResponse> rsp = new LockServiceClient(com).send(new LockRequest());
if (rsp.isSuccess())
{
    LockResponse lr = (LockResponse) rsp.getPayload();
    lockId = lr.getLockId();
}
else
{
    //process rsp.getErrors()
}
  1. Send request to host via HostServiceClient instance and receiving synchronously the first response and all upcoming responses (including the first one) will be handled asynchronously by listener.

ClientResponse <HostResponse> rsp =
     new HostServiceClient(com).send(new HostCommand(lockId, command));
//here you can process first response rsp.getPayload().getText()
  1. When you are sure that all responses come to listener then unlock host via UnlockServiceClient instance.

ClientResponse <LockResponse> rsp =
         new UnlockServiceClient(com).send(new UnlockRequest(lockId));
Note
working code sample has been included in com.sabre.redapp.example.cf.host example plugin.