Home Help Center

Multi-language Mobile Agent

barbarescobarbaresco Member Rafael BarbarescoOrganization: Federal University of Santa CatarinaProject: Mobile Agents for a Search Engine
Hello,

I've been implementing a mobile agent using ICE.
Now I'm trying to make a communication with different languages.

I have the server in C++ and client in Java. The client instantiates an agent and send it (by value) to the server so it can use it's methods and attributes.
My question is: is it possible? Does the C++ server recognize the client's Java object?

I tried it and I get "NoObjectFactoryException" even though the server has the C++ equivalent object factory:

Error:
!! 07/05/12 13:38:09:202 Client: error: main: Ice.UnknownLocalException
unknown = "BasicStream.cpp:1811: Ice::NoObjectFactoryException:
protocol error: no suitable object factory found for `::MobileAgent::ExtendedAgent'"

Server.cpp:
...
Ice::ObjectFactoryPtr factory;
    communicator()->addObjectFactory(factory, MobileAgent::ExtendedAgent::ice_staticId());
...

AgenteGenerico.ice:
module MobileAgent {
	
	sequence<byte> ba;
	
	class Agent {
		string text;
		int execute();
	};
	
	class ExtendedAgent extends Agent {
		int num;
	};
	
	interface ClientContact {
		int send(Agent pigeon);
	};
	
	interface ServerContact {
		int initiate(Agent pigeon, ClientContact* proxy);
	};
	
};

- Rafael

Comments

  • xdmxdm La Coruña, SpainAdministrators, ZeroC Staff Jose Gutierrez de la ConchaOrganization: ZeroC, Inc.Project: Ice Developer ZeroC Staff
    Hi,

    When you pass and object by value and the class has operations, only data members are send over the wire, the receiver must provide the implementation of these operations.
    Ice::ObjectFactoryPtr factory;
    communicator()->addObjectFactory(factory, MobileAgent::ExtendedAgent::ice_staticId());
    

    Here you call addObjectFactory with a null ptr, you must instead pass your object factory implementation, something like.
    class ObjectFactory : public Ice::ObjectFactory
    {
    public:
    
        Ice::ObjectPtr
        create(const string& type)
        {
            if(type == MobileAgent::ExtendedAgent::ice_staticId())
            {
                return new ExtendedAgentI;
            }
            assert(false);
            return 0;
        }
    
        void destroy()
        {
        }
    };
    ...
    Ice::ObjectFactoryPtr factory = new ObjectFactory;
    communicator()->addObjectFactory(factory, MobileAgent::ExtendedAgent::ice_staticId());
    

    See also:

    Why do I get a NoObjectFactoryException? - ZeroC Documentation - ZeroC

    Architectural Implications of Classes - Ice 3.4 - ZeroC

    Pass-by-Value Versus Pass-by-Reference - Ice 3.4 - ZeroC
  • barbarescobarbaresco Member Rafael BarbarescoOrganization: Federal University of Santa CatarinaProject: Mobile Agents for a Search Engine
    Oh, right. I forgot about the object factory implementation. I'll do it now.
    Thank you.

    - Rafael
Sign In or Register to comment.