Znav |
---|
next | Asynchronous Dynamic Invocation and Dispatch in C-Sharp |
---|
prev | Asynchronous Dynamic Invocation and Dispatch in C++ |
---|
|
This page describes the asynchronous Java mapping for the ice_invoke
proxy function and the Blobject
class.
On this page:
Calling ice_invoke
Asynchronously in Java
The asynchronous mapping for ice_invoke
resembles that of the static AMI mapping. Multiple overloadings are provided to support the use of callbacks and request contexts. The return value and the parameters operation
, mode
, and inParams
have the same semantics as for the synchronous version of ice_invoke
.
Basic Asynchronous Mapping for ice_invoke
in Java
The basic mapping is shown below:
Wiki Markup |
---|
{zcode:java}
Ice.AsyncResult begin_ice_invoke(
String operation,
Ice.OperationMode mode,
byte[] inParams);
Ice.AsyncResult begin_ice_invoke(
String operation,
Ice.OperationMode mode,
byte[] inParams,
java.util.Map<String, String> __context);
boolean end_ice_invoke(Ice.ByteSeqHolder outParams, Ice.AsyncResult __result);
{zcode} |
User exceptions are handled differently than for static asynchronous invocations. Calling end_ice_invoke
can raise system exceptions but never raises user exceptions. Instead, the boolean return value of end_ice_invoke
indicates whether the operation completed successfully (true) or raised a user exception (false). If the return value is true, the results are encoded in the byte sequence; otherwise, the byte sequence contains the encoded user exception.
Generic Asynchronous Callback Mapping for ice_invoke
in Java
The generic callback API is also available:
Wiki Markup |
---|
{zcode:java}
Ice.AsyncResult begin_ice_invoke(
String operation,
Ice.OperationMode mode,
byte[] inParams,
Ice.Callback __cb);
Ice.AsyncResult begin_ice_invoke(
String operation,
Ice.OperationMode mode,
byte[] inParams,
java.util.Map<String, String> __context,
Ice.Callback __cb);
{zcode} |
Refer to the static AMI mapping for an example of subclassing Ice.Callback
.
Type-Safe Asynchronous Callback Mapping for ice_invoke
in Java
The type-safe callback API looks as follows:
Wiki Markup |
---|
{zcode:java}
Ice.AsyncResult begin_ice_invoke(
String operation,
Ice.OperationMode mode,
byte[] inParams,
Ice.Callback_Object_ice_invoke __cb);
Ice.AsyncResult begin_ice_invoke(
String operation,
Ice.OperationMode mode,
byte[] inParams,
java.util.Map<String, String> __context,
Ice.Callback_Object_ice_invoke __cb);
{zcode} |
Callers must supply a subclass of Ice.Callback_Object_ice_invoke
:
Wiki Markup |
---|
{zcode:java}
package Ice;
public abstract class Callback_Object_ice_invoke extends ...
{
public abstract void response(boolean __ret, byte[] outParams);
public abstract void exception(LocalException __ex);
}
{zcode} |
The boolean argument to response
indicates whether the operation completed successfully (true) or raised a user exception (false). If the return value is true, the results are encoded in the byte sequence; otherwise, the byte sequence contains the encoded user exception.
Subclassing BlobjectAsync
in Java
BlobjectAsync
is the name of the asynchronous counterpart to Blobject
:
Wiki Markup |
---|
{zcode:java}
package Ice;
public abstract class BlobjectAsync extends Ice.ObjectImpl {
public abstract void ice_invoke_async(
Ice.AMD_Object_ice_invoke cb,
byte[] inParams,
Ice.Current current);
// ...
}
{zcode} |
To implement asynchronous dynamic dispatch, a server must subclass BlobjectAsync
and override ice_invoke_async
.
As with any other asynchronous operation, the first argument to the servant's member function is always a callback object. In this case, the callback object is of type Ice.AMD_Object_ice_invoke
, shown here:
Wiki Markup |
---|
{zcode:java}
package Ice;
public interface AMD_Object_ice_invoke {
void ice_response(boolean result, byte[] outParams);
void ice_exception(java.lang.Exception ex);
}
{zcode} |
Upon a successful invocation, the servant must invoke ice_response
on the callback object, passing true
as the first argument and encoding the operation results into outParams
. To report a user exception, the servant invokes ice_response
with false
as the first argument and the encoded form of the exception in outParams
.
In the dynamic dispatch model, the ice_exception
function must not be used to report user exceptions; doing so results in the caller receiving UnknownUserException
.
See Also
Znav |
---|
next | Asynchronous Dynamic Invocation and Dispatch in C-Sharp |
---|
prev | Asynchronous Dynamic Invocation and Dispatch in C++ |
---|
|