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.

}// Start agent's main Thread.ThreadStart starter = new ThreadStart(Execute);mainThread = new Thread(starter);mainThread.Start();manipulatesthe Agent./// /// Defines the meta-behaviour of the agent. The meta-behaviour/// (starts, suspends, stops) all the different behaviours of/// protected abstract void Execute();/// /// See IAgent.GetId/// /// public AgentId GetId(){return id;}/// /// Defines the <strong>de</strong>fault behaviour when a not-un<strong>de</strong>rstood Messageis received./// Called by MessageQueue./// /// protected internal virtual void MessageNotUn<strong>de</strong>rstood(Message m){Console.WriteLine("Not un<strong>de</strong>rstood: {0} received by {1}",m, this);}/// /// Returns a new Thread that is referenced by this so thatthis has control/// over the Thread. Should only be called by subclasses orclass Activity./// /// /// internal protected Thread NewThread(ThreadStart starter){Thread t = new Thread(starter);// A WeakReference references the Thread until itsfinalization starts// Look for already existing free WeakReferences in theListfor (int i = 0; i < threads.Count; i++){WeakReference wr = (WeakReference) threads[i];if (!wr.IsAlive){// This WeakReference is free: use itwr.Target = t;return t;}}// No free WeakReference found: create and add a new oneMSc EMOOSE Thesis – http://www.emn.fr/EMOOSE 87

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

Saved successfully!

Ooh no, something went wrong!