Archived

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

Problem with "createObjectAdapter()"

Hi all,

I've implemented a server to support two facets, while implementing server to create objectAdapter I've followed the two approaches in which, I am successfully in 1st approach, but some problems in the 2nd approach. The following are the approaches.

1). In 1st approach to create "ObjectAdapterPtr" I've used the method
"communicator()->createObjectAdapterWithEndpoints("SimpleAdapter","tcp -h 127.0.0.1 -p 10001");". In this approach I've added two facets to the adapter and following is the code:-

Ice::ObjectAdapterPtr adapter = communicator()->createObjectAdapterWithEndpoints
("ServerAdapter","tcp -h 192.168.147.202 -p 10000");

Ice::ObjectPtr object1 = new PrinterI;
Ice::ObjectPtr disp = new sampd;

Ice::Identity id = Ice::stringToIdentity("SimplePrinter");
adapter->add(object1,id);
adapter->addFacet(disp,id,"Display");
adapter->activate();

2). In the above approach I am able to successfully call the functions exposed byt these two facets using client.

3). Science we are using configuration files (*.ice.cfg) to hold the Endpoint details I have tried changing my code to use "createObjectAdapter()" method instead of "createObjectAdapterWithEndpoints()". Following is the changed code.

const char AdapterName[] = "ServerAdapter";
Ice::ObjectAdapterPtr adapter =
communicator()->createObjectAdapter(AdapterName);
Ice::ObjectPtr object1 = new PrinterI;
Ice::ObjectPtr disp = new sampd;

Ice::Identity id = Ice::stringToIdentity("SimplePrinter");
adapter->add(object1,id);
adapter->addFacet(disp,id,"Display");
adapter->activate();

The following is the config file content which I am using: -

AdapterName.Endpoints=tcp -p 10001 -h 192.168.147.248 : tcp -p 10001 -h 127.0.0.1

5). For both the approaches the client I am using to get the default and secondary facets using the following code:-

ic = Ice::initialize(argc,argv);
stringstream proxyName;
proxyName << "SMTPConfigServer" << ":tcp -h " << "localhost" << " -p " << "10001";
Ice::ObjectPrx base = ic->stringToProxy(proxyName.str());
IServer1Prx pserver1 = NULL;
pserver1 = IServer1Prx::checkedCast(base);

if (pserver1)
{
cout<<"found default facet;
}
IServer2Prx pserver2 = NULL;
pserver2 = IServer2Prx::checkedCast(base,"Display");

if(pserver2)
{
cout<<" pserver2 found !!"<<endl;
}

Info:-

1). With the second approach I am able to successfully access the default facet, but facing problems when I am trying to get the second facet.

2). With the first approach I am able to retrieve the both the facets successfully.

NEED HELP:-

Any body kindly help me to proceed further using second approach as we are forced to use configuration files to hold the End point details. Appreciate your immediate help.

Thanks in advance.
Phani Kommula,

Comments

  • Note that:

    AdapterName.Endpoints=tcp -p 10001 -h 192.168.147.248 : tcp -p 10001 -h 127.0.0.1

    Should be:

    ServerAdapter.Endpoints=tcp -p 10001 -h 192.168.147.248 : tcp -p 10001 -h 127.0.0.1

    Assuming that this is simply a typo and not the real cause of your problem, what error do you exactly get when you access the 2nd facet? If you get an exception, what is the full exception message? What traces do you get if you set both Ice.Trace.Network=2 and Ice.Trace.Protocol=1?
  • Problem with "CreateObjectAdapter()" Need help

    Hi Marc,

    Thanks a lot for the quick response.

    In my configuration file the entry is same as you mentioned. For the
    sake of readability I had to place it like that, I am so sorry:)

    The following are the code snippets from my program. This time, I didn't
    change any names;)

    1) In 1st approach to create "ObjectAdapterPtr", I've used the method
    "communicator()->createObjectAdapterWithEndpoints("SimpleAdapter", "tcp
    -h 127.0.0.1 -p 10001");".
    In this approach I've added two facets to the adapter and following
    is the code:-

    Ice::ObjectAdapterPtr adapter =
    communicator()->createObjectAdapterWithEndpoints
    ("ServerAdapter","tcp -h 127.0.0.1 -p 10001");

    Ice::ObjectPtr object1 = new PrinterI;
    Ice::ObjectPtr disp = new sampd;

    Ice::Identity id = Ice::stringToIdentity("SimpleServer");
    adapter->add(object1,id);
    adapter->addFacet(disp,id,"Display");
    adapter->activate();

    2) In the above approach I am able to successfully call the functions
    exposed byt these two facets using client.

    3). Science we are using configuration files (*.ice.cfg) to hold the
    Endpoint details I have tried changing my code to use
    "createObjectAdapter()" method instead of
    "createObjectAdapterWithEndpoints()". Following is the changed code.

    const char AdapterName[] = "ServerAdapter";
    Ice::ObjectAdapterPtr adapter =
    communicator()->createObjectAdapter(AdapterName);
    Ice::ObjectPtr object1 = new PrinterI;
    Ice::ObjectPtr disp = new sampd;

    Ice::Identity id = Ice::stringToIdentity("SimpleServer");
    adapter->add(object1,id);
    adapter->addFacet(disp,id,"Display");
    adapter->activate();

    The following is the config file content which I am using: -

    ServerAdapter.Endpoints=tcp -p 10001 -h 192.168.147.202 : tcp -p 10001
    -h 127.0.0.1

    4) Currently for both the approaches, I am using the following code in the client
    to get the default and secondary facets.

    ic = Ice::initialize(argc,argv);
    stringstream proxyName;
    proxyName << "SimpleServer" << ":tcp -h " << "localhost" << " -p " <<
    "10001";
    Ice::ObjectPrx base = ic->stringToProxy(proxyName.str());
    IServer1Prx pserver1 = NULL;
    pserver1 = IServer1Prx::checkedCast(base);

    if (pserver1)
    {
    cout<<"found default facet;
    }
    IServer2Prx pserver2 = NULL;
    pserver2 = IServer2Prx::checkedCast(base,"Display");

    if(pserver2)
    {
    cout<<" pserver2 found !!"<<endl;
    }


    5) The exception which was caught:

    /usr/include/IceUtil/Handle.h:39: IceUtil::NullHandleException

    6). The Ice.Trace.Network = 2 result is:

    [ ./client: Network: trying to establish tcp connection to 127.0.0.1:10001 ]
    [ ./client: Network: tcp connection established
    local address = 127.0.0.1:33311
    remote address = 127.0.0.1:10001 ]

    7). The Ice.Trace.Protocol = 1 result is:

    [pkommula@mlvirtmachine5 pkommula]$ ./client --Ice.Trace.Protocol=1
    [ ./client: Protocol: received validate connection
    message type = 3 (validate connection)
    compression status = 0 (not compressed; do not compress response, if any)
    message size = 14 ]
    [ ./client: Protocol: sending request
    message type = 0 (request)
    compression status = 0 (not compressed; do not compress response, if any)
    message size = 75
    request id = 1
    identity = SimpleServer
    facet =
    operation = ice_isA
    mode = 1 (nonmutating)
    context = ]
    [ ./client: Protocol: received reply
    message type = 2 (reply)
    compression status = 0 (not compressed; do not compress response, if any)
    message size = 26
    request id = 1
    reply status = 0 (ok) ]
    [ ./client: Protocol: sending request
    message type = 0 (request)
    compression status = 0 (not compressed; do not compress response, if any)
    message size = 78
    request id = 2
    identity = SimpleServer
    facet = 2
    operation = ice_isA
    mode = 1 (nonmutating)
    context = ]
    [ ./client: Protocol: received reply
    message type = 2 (reply)
    compression status = 0 (not compressed; do not compress response, if any)
    message size = 48
    request id = 2
    reply status = 3 (facet not exist)
    identity = SimpleServer
    facet = 2
    operation = ice_isA ]
    /usr/include/IceUtil/Handle.h:39: IceUtil::NullHandleException
    [pkommula@mlvirtmachine5 pkommula]$




    Kindly give your suggestions to proceed further. Thanks in advance.

    Thanks & Regards,
    Phani Kommula.
  • bernard
    bernard Jupiter, FL
    Hi Phani,

    Since your code is fairly simple, could you package your client, server and config file in one zip file and post it? This would help us reproduce and understand this problem.

    Also, which OS, C++ compiler, and Ice version are you using?

    Best regards,
    Bernard
  • Problem with "CreateObjectAdapter()" Need help

    Hi Bernard,

    The following are the versions of what you asked for:

    C++ Version
    g++ (GCC) 3.2 20020903 (Red Hat Linux 8.0 3.2-7)
    Ice Version
    ice-2.1.2 (Its a RPM Package File we have installed)
    OS Version
    Red Hat 8.0


    The Server code which we are using, I cannot share due to security reasons, I don't own the Server code. But I can share the code snippet where the object adapter is being created and how the objects are being added to the adapter.
    I can send you the client code, but that might not be of much help.

    The basic requirement is that I need to add a secondary facet to the existing server and the server is using a configure (.cfg) file to get the endpoints. I have added the Secondary facet but I am unable to connect too it. I am able to use/connect to the default facet.

    I am trying to write my own Server which replicates the basic functionality of the existing Server. In my Server I am trying to get the endpoints from a configure (.cfg) file. But I was not successful. The client says no Server found. I am attaching the code for the Server-Client which I wrote.

    Can you provide me with any basic Server code which uses a cfg file to get the end points? If you can provide me any help, my problem will be resolved.

    Kindly help me on this. My work is critical and your help would be greatly appreciated.

    Thanks and Regards,
    Phani Kommula.
  • my proble is resolved

    Hi all,
    Thanks for your help , I am able to solve the problem.