Home Help Center

automatic reconnection

bterwijnbterwijn Member Bas TerwijnOrganization: University of AmsterdamProject: distributed systems
I'm looking for a way to automatically make clients connect to servers and continue normal operations in the event that:

1) The client is started earlier then the server.

2) The server is shutdown and restarted on another host while the client is calling its methods.

This way I avoid race conditions while starting the system and will be able to kill and restart both the client and the server while still continuing normal operations. I have this working by catching exceptions and reconnecting, but now I want to hide this extra complexity so that my client and server programs remain simple, look similar to this:

SERVER
Ice::ObjectAdapterPtr adapter=
communicator()->createObjectAdapterWithEndpoints("Hello", "default");

Ice::ObjectPtr object = new HelloI;
HelloI::setHelloProxy(communicator(),adapter,object,"hello2");
// register to IcePack/Admin
// On default this overwrites any existing proxies with that name

adapter->activate();
communicator()->waitForShutdown();


CLIENT
HelloPrx hello=HelloI::getHelloProxy(communicator(),"hello2");
// retrieve from IcePack/Admin

while(1)
{
hello->methodCall();
}

Note that the 'hello->methodCall()' is hidding the fact that it internally catches any 'Ice::ConnectionRefusedExceptions' when the server is down and will then try to reconnect using the getHelloProxy() method above with the name 'hello->ice_getIdentity().name' indefinitly.

To hide the extra complexity I'm thinking of hiding it by changing the slice2cpp, slice2java, slice2*... code generators to generate the required code.

Do you think this would be a good idea?

The problem seems standard, are there any solutions available? did others ever do anything similar?

Is there any additional documentation available on the code generators?

Thanks you for your time,
Bas Terwijn

Comments

  • marcmarc FloridaAdministrators, ZeroC Staff Marc LaukienOrganization: ZeroC, Inc.Project: The Internet Communications Engine ZeroC Staff
    Ice can automatically retry for you. Please see the description of the property Ice.RetryIntervals for details, and search the Ice manual for "retry". Also have a look at the property Ice.Trace.Retry, and the "idempotent" operation modifier.
  • bterwijnbterwijn Member Bas TerwijnOrganization: University of AmsterdamProject: distributed systems
    Thank you for your responds.

    It's working although I can not set the retry strategy to repeat indefinitly. Next time I spend more time searching the manual instead of programming it myself. :o

    Thanks again,
    Bas Terwijn
  • bterwijnbterwijn Member Bas TerwijnOrganization: University of AmsterdamProject: distributed systems
    I'm looking for a way to do the following but could not find a solution in the manual.

    I want my client to retry connecting to 'someObject', as the client needs this object to function properly, but I don't want it to retry connecting to 'log' which is my logger. When the 'log' object isn't available the client should continue normal operations but without logging anything. In order to retry I have set the 'Ice.RetryIntervals' property in my config file so that it tries reconnecting every second for one minute, but now my client is also retrying its connection to the 'log' object.

    My question is, how do I make the client code below work both when the 'log' object is and isn't available?

    Maybe there is a way to set the 'Ice.RetryIntervals' property for specific connections?

    CLIENT
    Ice::ObjectPrx base = communicator()->stringToProxy("someObject");
    objectPrx object = objectPrx::checkedCast(base);

    base = communicator()->stringToProxy("log");
    LogPrx log = LogPrx::checkedCast(base);

    while (1)
    {
    object->someMethod();
    log->log("some message");
    sleep(1);
    }

    I hope you can help me, thank you in advance,
    Bas Terwijn
  • marcmarc FloridaAdministrators, ZeroC Staff Marc LaukienOrganization: ZeroC, Inc.Project: The Internet Communications Engine ZeroC Staff
    There is currently no way to set retry intervals per proxy or per connection. You can only set retry intervals per communicator. So you could create two communicators, with two different settings for Ice.RetryIntervals, and use one of them for your regular proxies, and the other for the "log" proxy.
  • rc_hzrc_hz Member Eric RCOrganization: www.genband.comProject: No project yet ✭✭✭
    ...There is currently no way to set retry intervals per proxy or per connection. You can only set retry intervals per communicator...

    Maybe it is better to add this feature that we can set retry intervals per proxy or per connection.
Sign In or Register to comment.