Archived

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

passing a context to a locator

Hello!

We need to implement transactional behaviour into an Ice based architecture. The Ice context mechanism seems to be a fine solution to pass the transaction context to all servant calls. However, we are also enthusiastic about locators and started to use them. But there seems to be a gap. Within the locator we need to select records from our database in order to invoke the requested servants. These selects must be done in the appropriate database transaction contexts. But we can't pass the transaction handle from the client to the locator residing on the server! Though the locator receives a context (via the Ice::Current parameter), there seems to be no way to fill that context on the client side.

Looks like locators can't be used when transactions are required, or am I missing something? Or is there a better recommendation to realize transactions within an Ice based architecture?

Thanks!

Robert.

Comments

  • marc
    marc Florida
    I'm afraid I don't understand. Why is there no way to fill in the context at the client side? It's simply the last parameter of any operation call. Alternatively, you can set a default context with the proxy's ice_newContext() operation.

    For the server side, you receive the context through the current parameter in a servant locator, as well as in each individual operation call.
  • Further details

    Hi Marc,

    thanks for your fast reaction!

    My problem is that the locator is not only called by method invocations but also when a servant/proxy pair is just created. For example I might call stringToProxy() on the client's adapter what results in an incarnation of a servant via it's locator. It looks like this on the client side:

    ::std::string szFilePrxString = "file/" + fileId + ":" + ic->getProperties()->getProperty("Fileservice.Endpoints");
    Ice::ObjectPrx obj = ic->stringToProxy(szFilePrxString);
    CFilePrx file = CFilePrx::checkedCast(obj);

    This triggers the server's file locator which selects the file in the database - but I don't know how to pass the client specific transaction context.

    Cheers

    Robert.
  • marc
    marc Florida
    stringToProxy() does not result in any method invocation on the server, but checkedCast() does. And you are right, there is no way to explicitly pass a context to checkedCast(). This is something we must fix.

    In the meantime, you can use the default context as a workaround. For example:

    Ice::Context ctx = ...
    Ice::ObjectPrx p = ...
    p = p->ice_newContext(ctx);
    MyModule::DerivedObjectPrx q = MyModule::DerivedObjectPrx::checkedCast(p);

    Then all invocations on p will use ctx as context implicitly.

    Another workaround is to explicitly call ice_isA() in combination with an uncheckedCast:

    Ice::Context ctx = ...
    Ice::ObjectPrx p = ...
    MyModule::DerivedObjectPrx q;
    if(p->ice_isA("::MyModule::DerivedObject", ctx))
    q = MyModule::DerivedObjectPrx::uncheckedCast(p);
  • Thank you!

    Great and fast explanation, this really helped!