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

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

public interface IAgent{/// /// Sends a Message to the agent./// /// void PostMessage(Message m);}}/// /// Returns the agent i<strong>de</strong>ntifier./// AgentId GetId();10. Class MAP.Agentusing System;using System.Threading;using System.Collections;namespace MAP{/// /// Defines a <strong>de</strong>legate that can be used for handling theMessageArrived event for/// Conversations./// public <strong>de</strong>legate void MessageArrivedEventHandler(Message m);/// /// Defines a generic <strong><strong>de</strong>s</strong>ign for agents. Instantiable subclasses mustprovi<strong>de</strong> an/// implementation for method Execute./// public abstract class Agent : MarshalByRefObject, IAgent{// The Agent IDprivate readonly AgentId id;// Queue of Messagesprotected MessageQueue msgQueue;// Event raised when Messages arrive.internal event MessageArrivedEventHandler MessageArrived;// List of WeakReferences to the Threads <strong>de</strong>pending on this andits Activitiesprivate IList threads;// Main Threadprivate readonly Thread mainThread;/// /// To be invoked by subclasses./// /// protected Agent(){threads = new ArrayList();// Initialization of the queue of Messages.msgQueue = new MessageQueue(this);// Registration to the Message Transporter.id = MessageTransporter.GetMT().Register(this);MSc EMOOSE Thesis – http://www.emn.fr/EMOOSE 86

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

Saved successfully!

Ooh no, something went wrong!