#include <omnetpp.h>
//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");
acc=lost=0;
L=0;
WATCH(L);
n=par("n");
}
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"); //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");
scheduleAt(departure_time,departure);
}
}
else if(queue.length()<n) //job arrival
{
acc++;
if (queue.isEmpty())
{
departure_time=simTime()+par("service_time");
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);
}
{"html5":"htmlmixed","css":"css","javascript":"javascript","php":"php","python":"python","ruby":"ruby","lua":"text\/x-lua","bash":"text\/x-sh","go":"go","c":"text\/x-csrc","cpp":"text\/x-c++src","diff":"diff","latex":"stex","sql":"sql","xml":"xml","apl":"apl","asterisk":"asterisk","c_loadrunner":"text\/x-csrc","c_mac":"text\/x-csrc","coffeescript":"text\/x-coffeescript","csharp":"text\/x-csharp","d":"d","ecmascript":"javascript","erlang":"erlang","groovy":"text\/x-groovy","haskell":"text\/x-haskell","haxe":"text\/x-haxe","html4strict":"htmlmixed","java":"text\/x-java","java5":"text\/x-java","jquery":"javascript","mirc":"mirc","mysql":"sql","ocaml":"text\/x-ocaml","pascal":"text\/x-pascal","perl":"perl","perl6":"perl","plsql":"sql","properties":"text\/x-properties","q":"text\/x-q","scala":"scala","scheme":"text\/x-scheme","tcl":"text\/x-tcl","vb":"text\/x-vb","verilog":"text\/x-verilog","yaml":"text\/x-yaml","z80":"text\/x-z80"}