10.07.2015 Views

pdf - 395 K - Ecole des mines de Nantes

pdf - 395 K - Ecole des mines de Nantes

pdf - 395 K - Ecole des mines de Nantes

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

the agent terminates, the thread is terminated as well. The .Net framework supportsconcurrency facilities for ensuring that no inconsistent state is reached.When the framework is exten<strong>de</strong>d, it can be appropriate to mo<strong>de</strong>l the agent’s meta-behaviourthrough a statechart diagram.3.1.2 Message queue and strong encapsulationBecause of its strong encapsulation and unpredictable autonomy, an agent should not reactsynchronously to external events or the arrival of messages. Thus external threads should notbe allowed to invoke the agent’s methods directly. Such a thread would possibly modify theagent’s internal state in<strong>de</strong>pen<strong>de</strong>ntly from the agent’s will.Instead, agents react to incoming messages asynchronously. When a thread accesses an agentby posting a message, the message is just stored in the agent’s message queue. Then themessage is processed whenever the agent <strong>de</strong>ci<strong><strong>de</strong>s</strong> so. The message queue has the role of aninterface between the agent and the external world.3.2 Synchronized inter-activity communicationBecause agents work asynchronously with their external world, it is necessary to provi<strong><strong>de</strong>s</strong>ome synchronization mechanisms for allowing them to interoperate easily. For that purpose,agent activities can use conversation objects.A conversation <strong>de</strong>fines a specific context in which messages can be exchanged. This allowsfor synchronized and asynchronous requests/replies between activities from different agents.The synchronized case is similar to method invocation: the thread of the activity is blockeduntil a reply is obtained. The asynchronous case allows the activity to do some work whileexpecting the reply.The agent whose activity creates a conversation is the initiator. The conversation istransmitted to another agent as an embedment in a standard message. The message isprocessed normally by the recipient agent through its message queue. However, when themessage is handled by an activity, the conversation can be obtained from the message forsending new messages in the context of the conversation. The conversation is then consi<strong>de</strong>redas handled by the agent.The implementation is based on C# events. The principle is that when a conversation ishandled by an agent, incoming messages that have been sent in the context of theconversation bypass the agent’ message queues and are obtained directly by the handlingactivity through an event handler.The figure below summarized the steps of the use of conversations.MSc EMOOSE Thesis – http://www.emn.fr/EMOOSE 42

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!