504 DISTRIBUTED OBJECT-BASED SYSTEMS CHAP . 9
communication system to pass the result of an asynchronous invocation . An important design issue is that asynchronous method invocations do not affect the original implementation of an object . In other words , it is the client ’ s responsibility to transform the original synchronous invocation into an asynchronous one ; the server is presented a normal ( synchronous ) invocation request .
Constructing an asynchronous invocation is done in two steps . First , the original interface as implemented by the object is replaced by two new interfaces that are to be implemented by client-side software only . One interface contains the specification of methods that the client can call . None of these methods returns a value or has any output parameter . The second interface is the callback interface . For each operation in the original interface , it contains a method that will be called by the client ’ s ORB to pass the results of the associated method as called by the client .
As an example , consider an object implementing a simple interface with just one method :
int add ( in int i , in int j , out int k );
Assume that this method ( which we expressed in CORBA IDL ) takes two nonnegative integers i and j and returns i + j as output parameter k . The operation is assumed to return −1 if the operation did not successfully complete . Transforming the original ( synchronous ) method invocation into an asynchronous one with call % backs is achieved by first generating the following pair of method specifications ( for our purposes , we choose convenient names instead of following the strict rules as specified in OMG , 2001b ):
void sendcb�add ( in int i , in int j ); void replycb�add ( in int ret�val , in int k );
// Called by the client // Called by the client ’ s ORB
In effect , all output parameters from the original method specification are removed from the method that is to be called by the client , and returned as input parameters of the callback operations . Likewise , if the original method specified a return value , that value is passed as an input parameter to the callback operation .
The second step consists of simply compiling the generated interfaces . As a result , the client is offered a stub that allows it to asynchronously invoke sendcb�add . However , the client will need to provide an implementation for the callback interface , in our example containing the method replycb�add . Note that these changes do not affect the server-side implementation of the object . Using this example , the callback model is summarized in Fig . 9-7 .
As an alternative to callbacks , CORBA provides a polling model . In this model , the client is offered a collection of operations to poll its ORB for incoming results . As in the callback model , the client is responsible for transforming the original synchronous method invocations into asynchronous ones . Again , most of the work can be done by automatically deriving the appropriate method specifications from the original interface as implemented by the object .