-
Notifications
You must be signed in to change notification settings - Fork 7
create_mobile_agent
create_mobile_agent(Agent_name, (IP, Port), Handler).
Agent_name: <atom ? > IP: <atom +>, Port: <integer +> Handler: <atom + >
Creates a mobile agent within the platform specified by the IP and Port, confers it a name and allocates its handler.
This predicate creates a mobile agent with the name Agent_name given by the user. It allocates the handler (which is a predicate specified by the user) Handler. The agent is created in the platform running at the IP and Port specified within. This predicate automatically creates the agent-specific predicates and asserts them within the specified platform. If the platform already contains an agent with the same name, it overwrites the same with this new agent having the specified name and handler.
In case the name of the agent is not specified by the user, then the predicate automatically calls get_new_name_alpha/1 and then assigns a new name to this agent.
Let the handler predicate for an agent be agent handler.
agent_handler(guid,(IP,Port),main):-
writeln("hello!!"),
writeln("I am the handler").
?- create_mobile_agent (myagent, (localhost, 6000), agent_handler).
This command will create an agent with name “myagent” as specified by the user carrying code specified by the handler “agent_handler”. On successful execution of the predicate, the prolog terminal will display the following result:
Agent with name myagent created.
?- create_mobile_agent (Agent_name, (localhost, 6000), agent_handler).
In this, the Agent_name is generated by calling get_new_name_alpha/1. The platform will automatically generate a name for the agent and then with that named agent is created. On successful creation of agent, the predicate will display the following result:
Agent with name cvfzap created
Agent_name = cvfzap.
where ‘cvfzap’ is the randomly generated agent name.