Advertisement
kanciastopantalones

tymoteusz TUUUBA

Mar 11th, 2016
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.71 KB | None | 0 0
  1. #include <omnetpp.h>
  2.  
  3. class Server : public cSimpleModule
  4. {
  5. private:
  6. cQueue queue; //the queue; first job in the queue is being serviced
  7. cMessage *departure; //message-reminder of the end of service (job departure)
  8. simtime_t departure_time; //time of the next departure - time in omnet
  9. cOutVector proces;
  10. cMessage *pomiar;
  11. simtime_t T;
  12. cLongHistogram roz_kol;
  13. cLongHistogram roz_kol2;
  14. cLongHistogram roz_kol3;
  15.  
  16. protected:
  17. virtual void initialize();
  18. virtual void handleMessage(cMessage *msgin);
  19.  
  20. };
  21.  
  22. Define_Module(Server);
  23.  
  24. void Server::initialize()
  25. {
  26. departure = new cMessage("Departure");
  27. pomiar = new cMessage("Pomiar");
  28. T = 1;
  29. scheduleAt(T, pomiar);
  30. }
  31.  
  32.  
  33. void Server::handleMessage(cMessage *msgin)
  34. {
  35. if(msgin == pomiar)
  36. {
  37. roz_kol.collect(queue.length());
  38. scheduleAt(simTime()+T, pomiar);
  39. }
  40. else if (msgin==departure) //job departure
  41. {
  42. roz_kol2.collect(queue.length());
  43.  
  44. cMessage *msg = (cMessage *)queue.pop(); //remove job from the head of the queue
  45. proces.record(queue.length());
  46. send(msg,"out"); //send it out
  47. if (!queue.empty()) //schedule next departure event
  48. {
  49. departure_time=simTime()+par("service_time");
  50. scheduleAt(departure_time,departure); //bear reminder
  51. }
  52. }
  53. else //job arrival
  54. {
  55. roz_kol3.collect(queue.length());
  56. if (queue.empty())
  57. {//service process
  58. departure_time=simTime()+par("service_time"); //compute future time, when service finish
  59. scheduleAt(departure_time,departure); //schedule in the future special message
  60. }
  61. queue.insert(msgin); //put job at the end of the queue
  62. proces.record(queue.length());
  63. }
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement