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.

System.Messaging.MessageQueue queue =GetMessageQueue(address);if (queue == null){// Failed to obtain queueConsole.Write("Cannot find MSMQ queue on host{0}",address);Console.WriteLine(" so cannot send message{0}.", m);}else{// Queue successfully obtainedSystem.Messaging.Message msg = newSystem.Messaging.Message(m);msg.Formatter = new BinaryMessageFormatter();queue.Send(msg);}}}/// /// Allows IAgents to register and get an ID./// /// /// public AgentId Register(IAgent agent){Debug.Assert(agent != null);AgentId id = null;lock (table){if (!table.ContainsValue(agent)){do {id = AgentId.NewId();} while(table.Contains(id));table.Add(id, agent);Console.WriteLine("MT - Ad<strong>de</strong>d: {0} for {1}",id, agent);}// Else agent is already registered}// Register AgentAddressNameServer.GetNS().Register(id, Middleware.ThisAddress);return id;}/// /// Handles incoming Messages asynchronously./// /// /// private void RemoteMessageArrived(Object source,ReceiveCompletedEventArgs asyncReceive){System.Messaging.MessageQueue queue =(System.Messaging.MessageQueue)source;// Get the System.Messaging.MessageSystem.Messaging.Message msqmMessage = queue.EndReceive(asyncReceive.AsyncResult);MSc EMOOSE Thesis – http://www.emn.fr/EMOOSE 71

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

Saved successfully!

Ooh no, something went wrong!