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

question: servant locators


I am trying to write a servant locator example similar to the one defined in Section 16.6.5 of the programmers guide. I have some questions though, any help is really appreciated.

What I'm trying to do is to register the Ice Object for PboneBook with the ObjectAdapter, and to have the Ice Objects for "PhoneEntry"s created using servant locators on demand.

First, Supposing the locate() is implemented similar to what is described in the guide, it is not clear to me what the implemenation of "PhoneEntryPtr PhoneBook::search(string name)" (for example searching using a string) should be. For this search operation to return a PhoneEntryPtr does it have to create one, or can it return the one created in locate() operation ?

Second, I suppose my client will look like below, for the ice definitions given. From the mappings it looks like the return type of "search" operation is PhoneBookEntryPtr and not a Prx, and this confuses me.

Ice::ObjectPrx base = ic->stringToProxy(
"PhoneBook:default -p 10000");

std::string proxyProperty = "SimpleProxy";

PhoneBookPrx book = PhoneBookPrx::checkedCast (base);

PhoneEntryPtr entry =
book->search (argv[1]);


Thanks a lot.



  • I *think* PhoneBook::search() should return a PhoneBookPrx, so the ice definition should be PhoneEntry * search(...), not PhoneEntry search(...).

    Then you can implement search() to just return a proxy.

    PhoneBookI::search (string name,
    Ice::Current &c) {

    Ice::Identity myId = Ice::stringToIdentity (name);

    return PhoneEntryPrx::uncheckedCast(c.adapter->createProxy (myId));

    Create the actual Ice object (instantiate servant) to handle the request in locate() method.