Archived

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

Can't throw CollocationOptimizationException

Hi!

When I invoke an AMI operation using a proxy that is configured to use collocation optionzation and the servant is collocated, but Ice run time doesn't raises CollocationOptimizationException and the invocatkon doesn't work.
I saw that CollocationOptimizationException would be raised in this case in Ice manual.

My code:
     ... ...
     while (true) {
          try {
              prx->begin_sayHello ();
              std::cout << "success asyn invoke- ";
              break;
          } catch (const Ice::CollocationOptimizationException &) {
              prx = prx->ice_collocationOptimized(false);
              std::cout << "Failed asyn invoke, off collocation optimized." << std::endl;
          }
      }
      ... ...

The servant whose object adapter was created by the same communicator as the proxy.
But invocation begin_sayHello doesn't work ("success asyn invoke- " is outputted) and no Ice::CollocationOptimizationException is rasied.

There is another code I modified, It works well, I catch CollocationOptimizationException and the invocation begin_sayHello does work.
     ... ...
     try {
         prx = ice_getConnection ();
     } catch (const Ice::CollocationOptimizationException &) {
         prx = prx-ice_collocationOptimized(false);
         std::cout << "catch Ice CollocationOptimizationException." << std::endl;
     }

     prx->begin_sayHello ();
     ... ...

I'm confused why the first doesn't work!

Here is my whole test code.
My os is Red Hat Enterprise Linux Server release 5.

Comments

  • mes
    mes California
    Hi,

    Thank you for posting a sample project.

    The exception behavior for asynchronous invocations is different than the behavior for synchronous invocations. As described in the manual, the only exception that is raised by a begin_ method is CommunicatorDestroyedException. All other exceptions are raised by the end_ method.

    The ice_getConnection method is a synchronous invocation and therefore CollocationOptimizationException is raised directly to the calling thread.

    In summary, you should receive a CollocationOptimizationException if you call end_sayHello or register an asynchronous callback.

    Regards,
    Mark
  • I got it! Thanks very much!