Archived

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

invocation between two services in the IceBox

Hi~

I have two services in the IceBox.
One service try to invoke a function of another service for collocation optimization.

suppose service's name is Print1 and Print2 respectively.

and I set the properties in the IceBox configuration file.

IceBox.UseSharedCommunicator.Print1=1
IceBox.UseSharedCommunicator.Print2=1

IceBox runs on single machine.

This is my code...

void
demo::print1MessageI::print1(const Ice::Current& current)
{

Ice::ObjectAdapterPtr objptr = current.adapter;

Ice::CommunicatorPtr ic = objptr->getCommunicator();

print2MessagePrx prx = print2MessagePrx::checkedCast(ic->stringToProxy("print2:tcp -p 9997")); /* always recieved null proxy. */

if(!prx){
std::cout << "invalid proxy..." << std::endl;
return;
}

std::cout << "this is message from Print1..." << std::endl;
prx->print2();
}

Whenever I am trying to get proxy for print2, I recieved null proxy.

But when I invoked print2 outside the IceBox with client I made, It works well.

Do I have some mistakes in my idea?

Comments

  • matthew
    matthew NL, Canada
    I'm afraid that the information you have provided is insufficient to debug your issue. However, I just modified the IceBox Ice demo to replicate your situation and it works as expected.

    I've attached the modified demo to this post so you can see what I did in my test.

    To ensure that the invocation uses collocation optimization I broke the call in a debugger. As expected with a shared communicator I see:
    (gdb) where
    #0  HelloI::sayHello (this=0x510f00) at HelloI.cpp:27
    #1  0x000b444e in IceDelegateD::Demo::Hello::sayHello (this=0x511a20, __context=0x0) at Hello.cpp:458
    #2  0x000b2779 in IceProxy::Demo::Hello::sayHello (this=0x5119b0, __ctx=0x0) at Hello.cpp:279
    #3  0x000bb515 in IceProxy::Demo::Hello::sayHello (this=0x5119b0) at Hello.h:180
    #4  0x000bb345 in HelloForwardI::forward (this=0x5100e0, c=@0xb018498c) at HelloI.cpp:21
    #5  0x000b1dd1 in Demo::HelloForward::___forward (this=0x5100e0, __current=@0xb018498c) at Hello.cpp:516
    #6  0x000b342d in Demo::HelloForward::__dispatch (this=0x5100e0, in=@0xb018498c, current=@0xb018498c) at Hello.cpp:542
    #7  0x0029ae58 in IceInternal::Incoming::invoke ()
    #8  0x002631b7 in Ice::ConnectionI::invokeAll ()
    #9  0x0026b24b in Ice::ConnectionI::message ()
    #10 0x003576bc in IceInternal::ThreadPool::run ()
    #11 0x00358cbd in IceInternal::ThreadPool::EventHandlerThread::run ()
    

    That is the call from the HelloForward to the Hello object avoids the network invocation. Without the shared communicator the call goes over the network as expected:
    (gdb) where
    #0  HelloI::sayHello (this=0x50d8a0) at HelloI.cpp:27
    #1  0x000b2221 in Demo::Hello::___sayHello (this=0x50d8a0, __current=@0xb038c98c) at Hello.cpp:704
    #2  0x000b3343 in Demo::Hello::__dispatch (this=0x50d8a0, in=@0xb038c98c, current=@0xb038c98c) at Hello.cpp:746
    #3  0x0029ae58 in IceInternal::Incoming::invoke ()
    #4  0x002631b7 in Ice::ConnectionI::invokeAll ()
    #5  0x0026b24b in Ice::ConnectionI::message ()
    #6  0x003576bc in IceInternal::ThreadPool::run ()
    #7  0x00358cbd in IceInternal::ThreadPool::EventHandlerThread::run ()
    
  • Thanks But...

    Thanks Metthew

    I saw your code, there is much different implementations rather than I made.

    my properties in config.icebox

    IceBox.Service.Print=print1Service:create --Ice.Config=config.print1
    IceBox.Service.Print2=print2Service:create --Ice.Config=config.print2

    As you can see, I have made two different so files libprint1Service.so, libprint2Service.so respectively.

    my point is invocations between functions in separated so file under collocation optimization.

    This is very very important point in our project.

    start() function in print1ServiceI.cpp file is

    void print1ServiceI::start(const std::string& name, const Ice::CommunicatorPtr& communicator, const Ice::StringSeq& args)
    {
    _adapter = communicator->createObjectAdapter(name); /* name is Print1 */
    _adapter->add(new demo::print1MessageI, communicator->stringToIdentity("print1"));
    _adapter->activate();
    }

    start() function in print2ServiceI file is

    void print2ServiceI::start(const std::string& name, const Ice::CommunicatorPtr& communicator, const Ice::StringSeq& args)
    {
    _adapter = communicator->createObjectAdapter(name); /* name is Print2 */
    _adapter->add(new demo2::print2MessageI, communicator->stringToIdentity("print2"));
    _adapter->activate();
    }

    <print1I.cpp is>

    void
    demo:print1MessageI:print1(const Ice::Current& current)
    {
    Ice::ObjectAdapterPtr objptr = current.adapter;
    Ice::CommunicatorPtr ic = objptr->getCommunicator();

    print2MessagePrx prx = print2MessagePrx::checkedCast(ic->stringToProxy("print2:tcp -p 9997")); /* always recieved null proxy. */

    if(!prx){
    std::cout << "invalid proxy..." << std::endl;
    return;
    }

    std::cout << "this is message from Print1..." << std::endl;
    prx->print2();
    }

    <print2I.cpp is>

    void
    demo2::print2MessageI::print2(const Ice::Current& current)
    {
    std::cout << "This is message from print2..." << std::endl;
    }

    print1.ice is

    module demo {
    interface print1Message{
    void print1();
    };
    };

    print2.ice is

    module demo2 {
    interface print2Message{
    void print2();
    };
    };

    I thought services(which are contained different so file) in an IceBox have a diffrent object adapter each other, and these object adapters could share the same communicator with UseSharedCommunicator property.

    Am I wrong?

    in your start() funtion in HelloServiceI.cpp has created one object adapter and registered HelloForwardI servant and HelloI sevant on same object adapter. finally you made two service within one

    suppose some situations....

    If I got a service from someone with binary so file and I loaded this so file in my IceBox, I'd like to invoke a function in this service with my service under collocation optimization environment.
    is it impossible?

    sorry for my poor english.. :)
  • matthew
    matthew NL, Canada
    I thought services(which are contained different so file) in an IceBox have a diffrent object adapter each other, and these object adapters could share the same communicator with UseSharedCommunicator property.

    Am I wrong?

    in your start() funtion in HelloServiceI.cpp has created one object adapter and registered HelloForwardI servant and HelloI sevant on same object adapter. finally you made two service within one

    suppose some situations....

    If I got a service from someone with binary so file and I loaded this so file in my IceBox, I'd like to invoke a function in this service with my service under collocation optimization environment.
    is it impossible?

    I think the situation should be the same.

    Using one service DLL that is loaded twice versus loading two service DLLs should not be relevant.

    My example actually does create two object adapters each with a unique name (one is named Hello and the other HelloForward).

    The same object being registered with both also should not matter in this case.

    You can try this for yourself by changing the code:
    void
    HelloServiceI::start(const string& name, const Ice::CommunicatorPtr& communicator, const Ice::StringSeq& args)
    {
        _adapter = communicator->createObjectAdapter(name);
        if(name == "HelloForward")
        {
            _adapter->add(new HelloForwardI, communicator->stringToIdentity("helloforward"));
        }
        else
        {
            _adapter->add(new HelloI, communicator->stringToIdentity("hello"));
        }
        _adapter->activate();
    }
    

    If you do that you'll need to fix the config.client (change the port from 10000 to 11000), and also fix HelloI.cpp (change 10000 to 11000).

    The quickest way to sort this issue out is for you to reply with a complete, self contained compilable example that demonstrates this issue. Also can you confirm your operating system, compiler and Ice version please?

    Best Regards, Matthew