Archived

This forum has been archived. Please start a new discussion on GitHub.

Best practice for managing proxies in C++

Hello,
I have a thread class that calls periodically an Interface with ACM support. I store as member of the class the communicator and recreate the proxy each time the Server is down but it does not feel right.
What I do not really understand is when to invalidate the proxy. Apparentely the stringToProxy function can never fail providing the string syntax is correct. How the checkedCast function know if the proxy is available ? Does it perform a network request behind the scene ? Basically could I keep the same proxy, wether the Server is online or not, and only manage with exceptions when there is not Server running ?
Thanks for your help

Comments

  • xdm
    xdm La Coruña, Spain

    You don't need to recreate the proxy, the proxy will transparently establish a new connection with the server if required.

    How the checkedCast function know if the proxy is available ? Does it perform a network request behind the scene ?

    Yes, it does a remote invocation,checkedCast invokes ice_isA in the remote servant to check if it implements the desired interface.

    What I do not really understand is when to invalidate the proxy.

    You never need to invalidate direct or indirect proxies, for fixed proxies that are tied to a specific connection you need to invalidate them when the connection is lost or closed. In your case seems you are using a direct proxy created with stringToProxy so no need to invalidate it

    see also https://doc.zeroc.com/ice/3.7/ice-overview/ice-architecture/terminology#Terminology-DirectProxies

  • Thanks for your quick answer, always a pleasure to post here.

    Actually I do not use a direct proxy, the string is a well-known object.

    But then that means I need to store an Ice::ObjectPrx rather than my Interface Proxy since the checkedCast will fail if the server is not running at the initial call. This is pretty inconvenient and I am pretty sure there is a better way to do it when I see how elegant things are done with the Ice framework.

    If you have any suggestion, I would be very happy.

  • xdm
    xdm La Coruña, Spain

    But then that means I need to store an Ice::ObjectPrx rather than my Interface Proxy since the checkedCast will fail if the server is not running at the initial call. This is pretty inconvenient and I am pretty sure there is a better way to do it when I see how elegant things are done with the Ice framework.

    You can use uncheckedCast instead of checkedCast , uncheckedCast doesn't make any remote invocations and then handle any errors when you use the proxy to make remote calls.