Facebook
From Damian, 1 Month ago, written in Plain Text.
This paste is a reply to serwer from Damian - go back
Embed
Viewing differences between serwer and Re: serwer
#include <omnetpp.h>
&lt;omnetpp.h&gt;
//using namespace omnetpp; //for Omnet++ ver. 5

class Server : public cSimpleModule
{  
  private:
    cQueue queue;             //the queue of jobs; it is assumed that the first job in the queue is the one being serviced
 cMessage *departure;        //special message; it reminds about the end of service and the need for job departure
 simtime_t departure_time;   //time of the next departure

 double L;
 int n;
 int acc,lost;

  protected:
    virtual void initialize();
    virtual void handleMessage(cMessage *msgin);

};

Define_Module(Server);


void Server::initialize()

 departure = new cMessage("Departure");
cMessage(&quot;Departure&quot;);
 acc=lost=0;
 L=0;
 WATCH(L);
 n=par("n");
n=par(&quot;n&quot;);
}


void Server::handleMessage(cMessage *msgin)  //two types of messages may arrive: a job from the source, or the special message initiating job departure
{  
    if (msgin==departure)   //job departure
 {
  cMessage *msg = (cMessage *)queue.pop();    //remove the finished job from the head of the queue

  send(msg,"out");                            send(msg,&quot;out&quot;);                            //depart the finished job
  if (!queue.isEmpty())                         //if the queue is not empty, initiate the next service, i.e. schedule the next departure event in the future
  {
   departure_time=simTime()+par("service_time");
departure_time=simTime()+par(&quot;service_time&quot;);
         scheduleAt(departure_time,departure);
  }
 }
 else if(queue.length()<n)                  length()&lt;n)                  //job arrival
 {
     acc++;
  if (queue.isEmpty())
  {
   departure_time=simTime()+par("service_time");
departure_time=simTime()+par(&quot;service_time&quot;);
            scheduleAt(departure_time,departure);
  }
  queue.insert(msgin); //insert the job at the end of the queue
 }
 else
 {
     lost++;
     delete msgin;
 }
    L=(double)lost/(acc+lost);
}