Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <omnetpp.h>
- class Server : public cSimpleModule
- {
- private:
- cQueue queue; //the queue; first job in the queue is being serviced
- cMessage *departure; //message-reminder of the end of service (job departure)
- simtime_t departure_time; //time of the next departure - time in omnet
- cOutVector proces;
- cMessage *pomiar;
- simtime_t T;
- cLongHistogram roz_kol;
- cLongHistogram roz_kol2;
- cLongHistogram roz_kol3;
- protected:
- virtual void initialize();
- virtual void handleMessage(cMessage *msgin);
- };
- Define_Module(Server);
- void Server::initialize()
- {
- departure = new cMessage("Departure");
- pomiar = new cMessage("Pomiar");
- T = 1;
- scheduleAt(T, pomiar);
- }
- void Server::handleMessage(cMessage *msgin)
- {
- if(msgin == pomiar)
- {
- roz_kol.collect(queue.length());
- scheduleAt(simTime()+T, pomiar);
- }
- else if (msgin==departure) //job departure
- {
- roz_kol2.collect(queue.length());
- cMessage *msg = (cMessage *)queue.pop(); //remove job from the head of the queue
- proces.record(queue.length());
- send(msg,"out"); //send it out
- if (!queue.empty()) //schedule next departure event
- {
- departure_time=simTime()+par("service_time");
- scheduleAt(departure_time,departure); //bear reminder
- }
- }
- else //job arrival
- {
- roz_kol3.collect(queue.length());
- if (queue.empty())
- {//service process
- departure_time=simTime()+par("service_time"); //compute future time, when service finish
- scheduleAt(departure_time,departure); //schedule in the future special message
- }
- queue.insert(msgin); //put job at the end of the queue
- proces.record(queue.length());
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement