Archived

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

How to correctly restore bidirectional communication after network failure?

Hi!

I have two services that use a bidirectional connection.

First service initialize connection:
            ITimerServicePrx twowayPrx = ITimerServicePrxHelper.uncheckedCast(communicator().stringToProxy("TimerService:tcp -h 192.168.0.208 -p 5551"));
            twowayPrx.ice_getConnection().setAdapter(adapter);

Second service calls method of first service:
                ITimerServiceListenerPrx listener = ITimerServiceListenerPrxHelper.uncheckedCast(current__.con.createProxy(Ice.Util.stringToIdentity("TimerServiceListener")));
                listener.OnTimer(time);

After network failure direct calls from first to second service are restored successfully. But callbacks are not restored.

How can I correctly restore callbacks? When and how I should call setAdapter to restore connection?

Comments

  • benoit
    benoit Rennes, France
    Hi Sergey,

    Is there any reason why you don't use Glacier2 instead of using bi-directional connections directly?

    Whenever a bi-dir connection fails, all the proxies created in the server from this connection need to be re-created with the new connection. You also need to re-associate the client object adapter with the new connection. You will need to figure out (both in the server and the client) when a new connection is re-established for this to work correctly. With Ice 3.6b, the Ice::Connection interface provides a setCallback method that allows you to register a callback to be notified when the connection is dropped. See https://doc.zeroc.com/display/Ice36/New+Features+in+Ice+3.6+beta#NewFeaturesinIce3.6beta-ActiveConnectionManagement for more information.

    When using bi-directional connections directly, it's often a good idea to implement a concept of "session" similar to Glacier2 sessions. The session is tight to the connection and whenever the connection fails, the session object is destroyed and re-created. The creation of the session deals with setting up the client-side object adapter, callbacks and the proxies in the client. The adapter is also typically set on the connection when the session is created with the new connection. On the server side, the session implementation can store the callback proxies provided by the client on session creation.

    Glacier2 provides such a session concept so I recommend you to checkout the Glacier2 demos from your Ice demo distribution. You can also checkout our online chat demo: https://www.zeroc.com/chat/index.html

    Cheers,
    Benoit.
  • Hi Benoit!
    Thanks for your reply!

    In my case Glacier2 is not suitable solution.

    I have network topology consist of several frontend and one application server (real scheme is more complex but this is not significant here).

    Frontends sent to application server one-way commands. If command processed successfully, application server should send back nothing. But if error are occurred application server should send one-way message exactly to source of one-way command (one of frontend server).

    My idea is use for this task bidirectional communication. All frontends contains one adapter that contains identical Identity. When some problem on application server is happened it just create proxy using known Identity and send error information back to frontend.