a7505d3f962a391026ba4ea072067656.ppt
- Количество слайдов: 16
Tutorial 5 Object to Agent Communication Fuhua Lin, Ph. D, Professor, School of Computing and Information Systems Athabasca University, Alberta, Canada Nov. 7, 2009
• In many cases, besides starting one or more agents, an external application needs to interact with the agents to instruct them to perform some tasks. For instance, an agentbased online book-selling system must notify the book buyer agent each time there is a new book to buy. • Similarly, the book buyer agent must notify the system when it successfully purchases a book
• However, the Agent. Controoler class does not disclose the reference of the wrapped agent instance and therefore the external application can not invoke any method of the agent directly. • Interactions between an external application and an agent started by means of the inprocess interface are made possibly by the object-to-agent (O 2 A) communication mechanism.
• Idea: – Each agent has a synchronized FIFO queue (called O 2 A queue) where the external application can put Java objects that can be later extracted by the agent. – The Agent. Controller object wrapping an agent provides the put. O 2 AObject() method that can be used by the external application to insert objects in the O 2 A queue of the agent. – Similarly. The Agent class provides the get. O 2 AObject() method that can be used by the agent to read objects passed by the external application.
• The O 2 A communication mechanism is disabled by default and so an agent wishing to interact with external applications must enable it explicitly by means of the set. Enable. O 2 ACommunication() method. • Similarly to the standard message queue model, inserting an object into the O 2 A queue of an agent has the effect of restarting all behaviors of the agent to give them a chance to read and process the inserted object.
Object to Agent Communication • Jade provides the Object-to-Agent (O 2 A) communication mechanism, which is basically FIFO queue where the external application can put Java objects that can be later extracted by the agent Agent Controller _______ … put. O 2 AObject(); … Object 1 put. O 2 AObject() O 2 A queue External Java Application Cond. Var Agent _______ … get. O 2 AObject(); … Object 1
The external application (1)
External application (2)
test. Agent (1)
test. Agent (2)
Running result Wrong! We did not see the display of the passed objects!
Agent Controller _______ … put. O 2 AObject(); … startup. Latch latch External Java Application put. O 2 AObject() O 2 A queue Object 1 Agent _______ … get. O 2 AObject(); … Object 1
Add Class Cond. Var serving as an event semaphore
The external application with class Condvar (2) To achieve a startup Synchronization!!!
Class test. Agent with class Cond. Var (1)
Running Results ✓
a7505d3f962a391026ba4ea072067656.ppt