Znav | ||||
---|---|---|---|---|
|
The number of simultaneous synchronous requests a server is capable of supporting is determined by the number of threads in the server's thread pool. If all of the threads are busy dispatching long-running operations, then no threads are available to process new requests and therefore clients may experience an unacceptable lack of responsiveness.
...
An alternate use case for AMD is an operation that requires further processing after completing the client's request. In order to minimize the client's delay, the operation returns the results while still in the dispatch thread, and then continues using the dispatch thread for additional work.
On this page:
Table of Contents | ||
---|---|---|
|
Enabling AMD with Metadata in C++
...
Specifying metadata at the operation level (rather than at the interface or class level) minimizes the amount of generated code and, more importantly, minimizes complexity: although the asynchronous model is more flexible, it is also more complicated to use. It is therefore in your best interest to limit the use of the asynchronous model to those operations that need it, while using the simpler synchronous model for the rest.
Ztop |
---|
AMD Mapping in C++
The C++ mapping emits the following code for each AMD operation:
A callback class used by the implementation to notify the Ice run time about the completion of an operation. The name of this class is formed using the pattern
AMD_
class
_op
. For example, an operation namedfoo
defined in interfaceI
results in a class namedAMD_I_foo
. The class is generated in the same scope as the interface or class containing the operation. Several methods are provided:Neither
ice_response
norice_exception
throw any exceptions to the caller.- The dispatch method, whose name has the suffix
_async
. This method has avoid
return type. The first parameter is a smart pointer to an instance of the callback class described above. The remaining parameters comprise the in-parameters of the operation, in the order of declaration.
...
Wiki Markup |
---|
{zcode:cpp} void foo_async(const AMD_I_fooPtr&, Ice::Short); {zcode} |
Ztop |
---|
AMD Exceptions in C++
There are two processing contexts in which the logical implementation of an AMD operation may need to report an exception: the dispatch thread (the thread that receives the invocation), and the response thread (the thread that sends the response).
...
Whether raised in a dispatch thread or reported via the callback object, user exceptions are validated and local exceptions may undergo translation.
Ztop |
---|
AMD Example in C++
To demonstrate the use of AMD in Ice, let us define the Slice interface for a simple computational engine:
...
Wiki Markup |
---|
{zcode:cpp} Job::Job(const Demo::AMD_Model_interpolatePtr& cb, const Demo::Grid& grid, Ice::Float factor) : _cb(cb), _grid(grid), _factor(factor) { } void Job::execute() { if (!interpolateGrid()) { _cb?->ice_exception(Demo::RangeError()); return; } _cb?->ice_response(_grid); } {zcode} |
...
If interpolation was successful, ice_response
is called to send the modified grid back to the client.
Ztop |
---|
See Also
- Asynchronous Method Invocation (AMI) in C++
- The Ice Threading Model
- User Exceptions
- Run-Time Exceptions
Zret |
---|
Znav | ||||
---|---|---|---|---|
|