//end NEW
}
@Override
protected int process(NetMessage message) throws jmt.common.exception.NetException {
Job job;
double delay;
int c;
switch (message.getEvent()) {
case NetEvent.EVENT_START:
//case EVENT_START:
//the random source creates all the jobs requested by each class.
//for each job created, it sends to itself a message whose delay is the time of
//departure of the job, calculated using the strategy of the corresponding class
//log.write(NetLog.LEVEL_RELEASE, null, this, NetLog.EVENT_START);
ListIterator<JobClass> jobClasses = getJobClasses().listIterator();
JobClass jobClass;
while (jobClasses.hasNext()) {
jobClass = jobClasses.next();
//NEW
//@author Stefano Omini
if (jobClass.getType() == JobClass.CLOSED_CLASS) {
//closed class: no arrivals
continue;
}
//end NEW
c = jobClass.getId();
// Calculates the delay of departure (1/lambda)
if (strategy[c] != null) {
job = new Job(jobClass);
delay = strategy[c].wait(this);
sendMe(job, delay);
//log.write(NetLog.LEVEL_DEBUG, job, this, NetLog.JOB_CREATED);
}
}
break;
case NetEvent.EVENT_ACK:
//case EVENT_ACK:
//if there are waiting jobs, takes the first, set its bornTime and
//forwards it to the service section.
//then it creates a new job and sends to itself a message whose delay is the time of
//departure of that job.
//otherwise, if there are no waiting jobs, sets coolstart=true
if (waitingJobs.size() != 0) {
job = waitingJobs.removeFirst();
c = job.getJobClass().getId();
job.born();
//NEW
//@author Stefano Omini, Bertoli Marco
// in RandomSource the job is created (--> SystemEnteringTime is initialized)
// but then is delayed as long as the random interarrival time ("delay")
//
// to compute system response time, the job starting time must be
// reset (otherwise it will correspond to the creation time and not to the
// leaving time, which is "delay" seconds after)
// Signals to global jobInfoList new added job
this.getOwnerNode().getQueueNet().getJobInfoList().addJob(job);
//end NEW
sendForward(job, 0.0);
//log.write(NetLog.LEVEL_DEBUG, job, this, NetLog.JOB_OUT);
// Create a new job and send it to me delayed
job = new Job(getJobClasses().get(c));
delay = strategy[c].wait(this);
sendMe(job, delay);
//log.write(NetLog.LEVEL_DEBUG, job, this, NetLog.JOB_CREATED);
} else {
coolStart = true;
}
break;
case NetEvent.EVENT_JOB:
//case EVENT_JOB
//if coolStart=false adds the job to the list of waiting jobs.
//
//if coolStart=true (no waiting jobs) the job is forwarded, an ack message
//is sent to the source of the message and a new job is created (the random source
//sends to itself a message, whose delay is the time of departure of the new job).
//log.write(NetLog.LEVEL_DEBUG, message.getJob(), this, NetLog.JOB_IN);
// Gets the job from the message
job = message.getJob();
if (coolStart) {
// Gets the class of the job
c = job.getJobClass().getId();
//no control is made on the number of jobs created
//it's an open class
job.born();
//NEW
//@author Stefano Omini, Bertoli Marco
// in RandomSource the job is created (--> SystemEnteringTime is initialized)
// but then is delayed as long as the random interarrival time ("delay")
//
// to compute system response time, the job starting time must be
// reset (otherwise it will correspond to the creation time and not to the
// leaving time, which is "delay" seconds after)
// Signals to global jobInfoList new added job
this.getOwnerNode().getQueueNet().getJobInfoList().addJob(job);
//end NEW
sendForward(job, 0.0);
send(NetEvent.EVENT_ACK, job, 0.0, message.getSourceSection(), message.getSource());
//log.write(NetLog.LEVEL_DEBUG, job, this, NetLog.JOB_OUT);
job = new Job(job.getJobClass());
delay = strategy[c].wait(this);
sendMe(job, delay);
// Sets coolStart to false, next job should wait ack
coolStart = false;