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.

{/// /// Allows for specific conversations between Agents withsynchronized and/// asynchronized Message sending./// Conversation messages are not stored into the Agent'sMessageQueue after the/// Conversation has been initiated, i.e. the Agent has sent at leastone Message/// as part of the Conversation. Instead, Messages are obtaineddirectly from the/// Conversation object by the mean of the MessageArrived event ofthe Agent./// [Serializable]public class Conversation : ICloneable{// Last received Message in the synchronized and async casesprivate Message syncReply, asyncReply;// To get the agent's MessageArrived eventprivate Agent agent;// The main lockprivate Object aLock;// Whether a Message is expected after an async Message sendingprivate bool expectingMessage;// MessageArrived event handlersprivate MessageArrivedEventHandler syncHandler, asyncHandler;// Unique ID of thisprivate Guid i<strong>de</strong>ntifier;// States and current stateprivate enum States {JUST_CREATED, NOT_INITIATED, INITIATED,CLOSED};private States currentState;public Conversation() : this(Guid.NewGuid(),States.JUST_CREATED) {}private Conversation(Guid id, States state){i<strong>de</strong>ntifier = id;syncReply = null;asyncReply = null;expectingMessage = false;aLock = new Object();agent = null;currentState = state;syncHandler = newMessageArrivedEventHandler(HandleSyncNotification);asyncHandler = newMessageArrivedEventHandler(HandleAsyncNotification);}/// /// Returns whether a Message belongs to the context of this./// /// /// public bool AppliesTo(Message m){return this.Equals(m.Conversation);}MSc EMOOSE Thesis – http://www.emn.fr/EMOOSE 91

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

Saved successfully!

Ooh no, something went wrong!