Archived

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

simple IcePack demo?

I'm trying to get the indirect binding working, with no success until now. Is there an example simular to:

Ice-2.1.0/demo/IcePack/simple

But then without the 'application.xml' file that is required to start the server??

Or maybe there are instructions on how to modify the 'Server.cpp' file so that it can be run from the commandline directly using './server' so without 'icepackadmin'.

thanks for your time,
Bas Terwijn

Comments

  • benoit
    benoit Rennes, France
    Yes, you can just try this with the demo/Ice/hello demo. If you take a look at the config file you'll find the following lines at the end:
    #                                                                               
    # Uncomment the following lines if you want to run this demo with the           
    # IcePack registry. Note that we override properties previously set             
    # above, so make sure to comment out these properties to run the demo           
    # without IcePack.                                                              
    #                                                                               
    #Hello.Proxy=hello@HelloAdapter                                                 
    #Hello.Endpoints=tcp:udp:ssl                                                    
    #Hello.AdapterId=HelloAdapter                                                   
    #Ice.Default.Locator=IcePack/Locator:default -p 10006                           
    

    These properties configure the server and client to use indirect binging. Uncomment these lines and then to run the demo:
       $ cd Ice-2.1.1/demo/Ice/hello
       $ icepackregistry --Ice.Config=config
       $ ./server
       $ ./client
    

    Hope this helps!

    Benoit.
  • Thanks for your quick reply.

    The 'demo/Ice/hello' demo uses the 'config' file to share the name of the adapter as shown below (slightly modified):

    config:
    Ice.Default.Locator=IcePack/Locator:default -p 10006
    Hello.Endpoints=default
    Hello.AdapterId=HelloAdapter

    server:
    Ice::ObjectAdapterPtr adapter= communicator()->createObjectAdapter("Hello");
    Ice::ObjectPtr object = new HelloI;
    adapter->add(object,Ice::stringToIdentity("hello"));

    client:
    string proxy = "hello@HelloAdapter";
    Ice::ObjectPrx base = communicator()->stringToProxy(proxy);
    HelloPrx hello = HelloPrx::checkedCast(base);

    This works but I have two problems with this solution:

    1) I don't want to have the adapter defined in the config file because then I need to update this file every time I add a new object type (besides the Hello type). I tried different ways but failed. How can this be done?

    2) An adapter seems to be associated with a particular host, meaning that I have to define multiple adapters when I have multiple hosts running servers that all provide Hello objects under different names (This seems to conflict with the location transparancy). How can this be avoided?

    Ideally I'm looking for a solution simular to:

    config:
    Ice.Default.Locator=IcePack/Locator:default -p 10006
    #NO ADAPTERS SPECIFIED

    server:
    Ice::ObjectPtr object = new HelloI;
    communicator()->add(object,Ice::stringToIdentity("hello123"));
    #OBJECT PUBLISHED UNDER NAME 'hello123', NO ADAPTER USED

    client:
    string proxy = "hello123";
    Ice::ObjectPrx base = communicator()->stringToProxy(proxy);
    HelloPrx hello = HelloPrx::checkedCast(base);

    Something like this is simple, I don't see why Ice has to make things more difficult then this. Paragraph 35.3.2 of the Ice2.1.0 manual seems to describe something similar where the object is only referred to by its identity (not in combination with an adapter). Is this correct?

    Please send me any suggestions that you might have, Thanx in advance.
    Bas Terwijn
  • bernard
    bernard Jupiter, FL
    Hi Bas,

    You can use the same object adapter with many types of objects ... there is no need to create a separate adapter per type. If you don't want any per-adapter configuration, you can specify your endpoints programmatically: use createObjectAdapterWithEndpoints(name, endpoints) instead of createObjectAdapter(name).

    Using adapter ids instead of hostnames/IP addresses and ports in your proxies provides location transparency: you can move your server (with its adapters) to another host and the proxies will remain valid.

    IcePack maintains an Adapter table (to resolve adapter ids) and an Object table (to resolve simple proxies with just the identity like your "hello123"). You can create entries in this Object table with icepackadmin, programmatically using the IcePack::Admin interface, and with IcePack deployment descriptors (see 35.9.13 in the Ice 2.1.0 manual).

    Cheers,
    Bernard
  • benoit
    benoit Rennes, France
    Here's how your code would look like if you want to register the object using the IcePack::Admin interface:
    config:
    -------
    Ice.Default.Locator=IcePack/Locator:default -p 10006
    
    client:
    ------
    string proxy = "hello123";
    Ice::ObjectPrx base = communicator()->stringToProxy(proxy);
    HelloPrx hello = HelloPrx::checkedCast(base);
    
    server:
    -------
    #include <IcePack/Admin.h>
    ...
    Ice::ObjectPtr object = new HelloI;
    Ice::ObjectAdapterPtr adapter = communicator()->createObjectAdapterWithEndpoints("Hello", "default");
    Ice::ObjectPrx proxy = adapter->add(object, Ice::stringToIdentity("hello123"));
    
    IcePack::AdminPrx admin = IcePack::AdminPrx::checkedCast(communicator->stringToProxy("IcePack/Admin"));
    admin->addObjectWithType(proxy, proxy->ice_id())
    

    Let us know if you need more information!

    Benoit.
  • Thanks

    hi Bernard and Benoit,

    Thanks, I got it working now, your help is greatly appreciated.

    I don't fully understand the difference yet between your suggestion and my earlier attempt,.... back to reading the manual I suppose. :)

    keep up the good work,
    Bas Terwijn
  • IcePack::AdminPrx

    dear Zeroc people,

    I have a question regrding the 'IcePack::AdminPrx' type.

    I'm trying to hide most of the complexity of writing Ice clients, servers, publishers and subscibers by putting it im my class 'IAS_Application' which is derived from the 'Ice::Application' class as shown below:

    #include <Ice/Ice.h>
    #include <IcePack/Query.h>

    using namespace std;

    class IAS_Application : virtual public Ice::Application
    {
    public:
    int main(int argc, char *argv[], const char *cp = 0)
    {
    cout<<"IAS_Application: initializing"<<endl;
    return Ice::Application::main(argc,argv,cp);
    };

    virtual int run(int argc, char *argv[])
    {
    IcePack::AdminPrx admin= IcePack::AdminPrx::checkedCast(communicator()->stringToProxy("IcePack/Admin"));
    // other initialization, e.g. IceStorm
    // Terminate cleanly on receipt of a signal
    shutdownOnInterrupt();
    cout<<"IAS_Application: done initializing"<<endl;

    return IAS_run(argc,argv);
    };

    virtual int IAS_run(int argc, char *argv[]) =0;
    }



    But when I compile (a server for example) I get the following error message:

    "error: `AdminPrx' is not a member of `IcePack'"

    I can't seem to fix this but the strange thing is that I can use 'IcePack::AdminPrx' in my server itself without any problems (as recommended above in this thread by Benoit):

    #include <IAS_Application.h>
    #include <IcePack/Admin.h>

    using namespace std;

    class MyApplication : virtual public IAS_Application
    {
    public:
    virtual int IAS_run(int argc, char *argv[]) {

    IcePack::AdminPrx admin =
    IcePack::AdminPrx::checkedCast( communicator()->stringToProxy("IcePack/Admin"));



    What could be the problem (I'm using Ice2.1.1)?
    Do you have any advise on how to try and fix it?

    thank you for your time,
    Bas Terwijn
  • benoit
    benoit Rennes, France
    bterwijn wrote:
    dear Zeroc people,

    I have a question regrding the 'IcePack::AdminPrx' type.

    I'm trying to hide most of the complexity of writing Ice clients, servers, publishers and subscibers by putting it im my class 'IAS_Application' which is derived from the 'Ice::Application' class as shown below:

    #include <Ice/Ice.h>
    #include <IcePack/Query.h>

    You should include <IcePack/Admin.h> here instead of <IcePack/Query.h>. Then, you just need to include <IAS_Application.h> in your server sources (no need to include <IcePack/Admin.h>).

    Hope this helps!

    Benoit.
  • Thank you very much for your responds.

    I now realize I have made a stupid 'copy-paste' error which I overlooked for three hours. Sorry to have bothered you with such a trivial error.

    greetings,
    Bas Terwijn