Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Published by Scroll Versions from space IceMaster and version 3.7.1

Znav
nextslice2matlab Command-Line Options
prevMATLAB Mapping for Classes

Asynchronous Method Invocation (AMI) is the term used to describe the client-side support for the asynchronous programming model. AMI supports both oneway and twoway requests, but unlike their synchronous counterparts, AMI requests never block the application. When a client issues an AMI request, the Ice run time hands the message off to the local transport buffer or, if the buffer is currently full, queues the request for later delivery. The application can then continue its activities and poll or wait for completion of the invocation, or receive a callback when the invocation completes.

...

In addition to the synchronous proxy method, slice2matlab generates the following asynchronous proxy method:

Code Block
languagematlab
titleMATLAB
classdef EmployeesPrx < Ice.ObjectPrx
    methods
        function result = getName(obj, number, varargin)  % Synchronous method
            ...
        end
        function future = getNameAsync(obj, number, varargin) % Asynchronous method
            ...
        end
    end
    ...
end

...

Here's an example that calls getNameAsync:

Code Block
languagematlab
titleMATLAB
e = ...; % Get EmployeesPrx proxy
future = e.getNameAsync(99);

% Continue to do other things here...

name = f.fetchOutputs();

...

The generated code looks like this:

Code Block
languagematlab
titleMATLAB
classdef ExamplePrx < Ice.ObjectPrx
    methods
        function future = opAsync(obj, inp1, inp2, varargin)
            ...
        end
        ...
    end
    ...
end

Now let's call fetchOutputs to demonstrate how to retrieve the results when the invocation completes:

Code Block
languagematlab
titleMATLAB
e = ...; % Get EmployeesPrx proxy
future = e.opAsync(5, 'demo');
...
[r, outp1, outp2] = future.fetchOutputs();

...

The Future object that is returned by asynchronous proxy methods has an API that resembles MATLAB's parallel.Future class:

Code Block
languagematlab
titleMATLAB
classdef Future < ...
    methods
        function ok = wait(obj, state, timeout)
        function varargout = fetchOutputs(obj)
        function cancel(obj)
    end
    properties(SetAccess=private) % Read only properties
        ID
        NumOutputArguments
        Operation
        Read
        State
    end
end

...

  • wait()
    This method blocks until the invocation completes and returns true if it completed successfully or false if it failed.
  • wait(state)
    This method blocks until the desired state is reached (see the description of the State property below). For example, calling future.wait('finished') is equivalent to calling future.wait(). The method returns true if the desired state was reached and no exception has occurred, or false otherwise.
  • wait(state, timeout)
    This method blocks for a maximum of timeout seconds until the desired state is reached, where timeout is a double value. The method returns true if the desired state was reached and no exception has occurred, or false otherwise.
  • fetchOutputs()
    This method blocks until the invocation completes. If it completed successfully, fetchOutputs returns the results (if any). If the invocation failed, fetchOutputs raises the exception. This method can only be invoked once.

...

Znav
nextslice2matlab Command-Line Options
prevMATLAB Mapping for Classes