Home Help Center

AMD and timing

ngambek2003ngambek2003 Member Budyanto HimawanOrganization: WMS Inc.Project: Casino back end services ✭✭
Hi,

If I have an AMD method and I do the following
AMethod_async(callback, ...)
{
      ...
      callback->ice_response(result);
      
      // This publishes to an ice storm topic.
      publisher->publish();
}

If the client that calls the method also has a subscriber to the topic that publisher publishes to is the client guaranteed to get the result from the method call before getting the ice storm notification?

Comments

  • mesmes CaliforniaAdministrators, ZeroC Staff Mark SpruiellOrganization: ZeroC, Inc.Project: Ice Developer ZeroC Staff
    Hi,

    No, it is not guaranteed that the client will receive its reply to the invocation of AMethod before it receives the message from IceStorm. It is quite likely, but not guaranteed. For example, the client thread pool in the client might be busy at the time the server thread pool in the client receives the IceStorm message. If your client needs this guarantee (such as to prevent a race condition), you'll need to handle it in the client.

    Regards,
    Mark
  • ngambek2003ngambek2003 Member Budyanto HimawanOrganization: WMS Inc.Project: Casino back end services ✭✭
    Hi Mark,

    Thanks for the response.

    I'm still trying to picture how it can really happen.

    So the client is calling AMethod_async. The client call is NOT AMI, so a client thread is tied up waiting for the response. Next the server responds using ice_response(). What does it mean when ice_response() returns? Doesn't it mean that the client has gotten the response at that point?

    Thanks
    Budyanto
  • benoitbenoit Rennes, FranceAdministrators, ZeroC Staff Benoit FoucherOrganization: ZeroC, Inc.Project: Ice ZeroC Staff
    Hi,

    When the ice_response call returns, there are 2 cases:
    • the response is sent immediately to the client. The client will likely receive the response before the publish call in the server but it's not guaranteed because the server doesn't wait for any acknowledgment from the client.
    • the response is queued with the Ice connection for latter sending. This can happen for example if the connection has many or large other responses to send. In this case, you don't really know when the response is sent: it is sent in the background by another server thread (if and when available).

    Your client shouldn't rely on receiving the response before the update from IceStorm since there are no guarantees that it will be the case.

    Cheers,
    Benoit.
Sign In or Register to comment.