Commit a8845579 authored by rosemaryng's avatar rosemaryng
Browse files

Modified Queue and relevant classes for backward compatibility

parent a7cd311b
......@@ -21,6 +21,7 @@ package jmt.engine.NetStrategies.QueueGetStrategies;
import jmt.engine.NetStrategies.QueueGetStrategy;
import jmt.engine.QueueNet.Job;
import jmt.engine.QueueNet.JobClass;
import jmt.engine.QueueNet.JobInfo;
import jmt.engine.QueueNet.JobInfoList;
/**
......@@ -48,4 +49,10 @@ public class FCFSstrategy extends QueueGetStrategy {
return queue.removeFirst(jobClass).getJob();
}
@Override
public JobInfo peek(JobInfoList queue) {
return queue.getFirstJob();
}
}
......@@ -21,6 +21,7 @@ package jmt.engine.NetStrategies.QueueGetStrategies;
import jmt.engine.NetStrategies.QueueGetStrategy;
import jmt.engine.QueueNet.Job;
import jmt.engine.QueueNet.JobClass;
import jmt.engine.QueueNet.JobInfo;
import jmt.engine.QueueNet.JobInfoList;
/**
......@@ -48,4 +49,10 @@ public class LCFSstrategy extends QueueGetStrategy {
return queue.removeLast(jobClass).getJob();
}
@Override
public JobInfo peek(JobInfoList queue) {
return queue.getLastJob();
}
}
......@@ -46,14 +46,6 @@ public abstract class QueueGetStrategy implements AutoCheck {
*/
public abstract Job get(JobInfoList queue, JobClass jobClass);
//TODO: This method is deleted
/**
* This method should be overridden to return the JobInfo of the job that would be returned from a get() call.
* HOWEVER, this method should *NOT* remove the Job from the queue.
* @param queue
* @return The JobInfo of the job that would have been returned had the get() method been invoked.
*/
public abstract JobInfo peek(JobInfoList queue);
public boolean check() {
......
......@@ -242,6 +242,8 @@ public class PSServer extends ServiceSection {
jobReceived = entry.getKey();
timeLeftToRenege = entry.getValue();
}
// Rose: so this is essentially getting the last item in the map? or is there ever only one job?
// in that case we could just use a Pair(?)
// Add the extra information (impatienceType and timeLeftToRenege) to the PSJobInfo of jobReceived
PSJobInfo psJobInfo = (PSJobInfo) psJobsList.lookFor(jobReceived);
......
......@@ -21,6 +21,8 @@ package jmt.engine.QueueNet;
import jmt.engine.simEngine.RemoveToken;
import org.apache.commons.math3.util.Pair;
import java.util.Objects;
/**
* This class implements a generic job of a queue network.
* @author Francesco Radaelli, Marco Bertoli
......@@ -235,4 +237,18 @@ public class Job implements Cloneable {
//resetClass();
}
//rose: is this necessary?
@Override
public boolean equals(Object that) {
if (!(that instanceof Job)) {
return false;
}
Job a = (Job) that;
return a.getId() == this.Id;
}
@Override
public int hashCode() {
return getId();
}
}
......@@ -328,6 +328,7 @@ public class LinkedJobInfoList implements JobInfoList {
/* (non-Javadoc)
* @see jmt.engine.QueueNet.JobInfoList#lookFor(jmt.engine.QueueNet.Job)
*/
//TODO rose: should we use a better way to compare 2 jobs(?)
public JobInfo lookFor(Job job) {
ListIterator<JobInfo> it = list.listIterator();
JobInfo jobInfo = null;
......
......@@ -268,271 +268,6 @@ public class QueueNetwork {
}
}
//TODO: delete?
/**
* Get the total number of dropped jobs in the whole network
* @return the total number of dropped jobs in the whole network
*/
public int getDroppedJobs() {
//dropped jobs
int dropped = 0;
for (int i = 0; i < nodes.size(); i++) {
NetNode node = nodes.get(i);
NodeSection section;
try {
section = node.getSection(NodeSection.INPUT);
if (section instanceof Queue) {
dropped += ((Queue) section).getDroppedJobs();
} else if (section instanceof Storage) {
dropped += ((Storage) section).getDroppedJobs();
} else if (section instanceof BlockingQueue) {
dropped += ((BlockingQueue) section).getDroppedJobs();
}
section = node.getSection(NodeSection.OUTPUT);
if (section instanceof Fork) {
dropped += ((Fork) section).getDroppedJobs();
}
} catch (NetException ne) {
continue;
}
}
return dropped;
}
/**
* Get the total number of dropped jobs in the whole network for the specified class
* @param jobClass the job class
* @return the total number of dropped jobs in the whole network for the specified class
*/
public int getDroppedJobs(JobClass jobClass) {
//dropped jobs
int dropped = 0;
int classIndex = jobClass.getId();
for (int i = 0; i < nodes.size(); i++) {
NetNode node = nodes.get(i);
NodeSection section;
try {
section = node.getSection(NodeSection.INPUT);
if (section instanceof Queue) {
dropped += ((Queue) section).getDroppedJobsPerClass(classIndex);
} else if (section instanceof Storage) {
dropped += ((Storage) section).getDroppedJobsPerClass(classIndex);
} else if (section instanceof BlockingQueue) {
dropped += ((BlockingQueue) section).getDroppedJobsPerClass(classIndex);
}
section = node.getSection(NodeSection.OUTPUT);
if (section instanceof Fork) {
dropped += ((Fork) section).getDroppedJobsPerClass(classIndex);
}
} catch (NetException ne) {
continue;
}
}
return dropped;
}
/**
* Get the total number of reneged jobs in the whole network
* @return the total number of reneged jobs in the whole network
*/
public int getRenegedJobs() {
//reneged jobs
int reneged = 0;
for (int i = 0; i < nodes.size(); i++) {
NetNode node = nodes.get(i);
NodeSection section;
try {
section = node.getSection(NodeSection.INPUT);
if (section instanceof Queue) {
reneged += ((Queue) section).getRenegedJobs();
}
} catch (NetException ne) {
continue;
}
}
return reneged;
}
/**
* Get the total number of reneged jobs in the whole network for the specified class
* @param jobClass the job class
* @return the total number of reneged jobs in the whole network for the specified class
*/
public int getRenegedJobs(JobClass jobClass) {
//reneged jobs
int reneged = 0;
int classIndex = jobClass.getId();
for (int i = 0; i < nodes.size(); i++) {
NetNode node = nodes.get(i);
NodeSection section;
try {
section = node.getSection(NodeSection.INPUT);
if (section instanceof Queue) {
reneged += ((Queue) section).getRenegedJobsPerClass(classIndex);
}
} catch (NetException ne) {
continue;
}
}
return reneged;
}
/**
* Gets the total number of switched jobs in the whole network
* @param jobClass the job class
* @return the total number of switched jobs in the whole network
*/
public int getSwitchedJobs() {
//switched jobs
int switched = 0;
for (int i = 0; i < nodes.size(); i++) {
NetNode node = nodes.get(i);
NodeSection section;
try {
section = node.getSection(NodeSection.SERVICE);
if (section instanceof ClassSwitch) {
switched += ((ClassSwitch) section).getSwitchedJobs();
}
section = node.getSection(NodeSection.OUTPUT);
if (section instanceof Fork) {
switched += ((Fork) section).getSwitchedJobs();
}
} catch (NetException ne) {
continue;
}
}
return switched;
}
/**
* Gets the total number of switched jobs in the whole network for the specified class
* @param jobClass the job class
* @return the total number of switched jobs in the whole network for the specified class
*/
public int getSwitchedJobs(JobClass jobClass) {
//switched jobs
int switched = 0;
for (int i = 0; i < nodes.size(); i++) {
NetNode node = nodes.get(i);
NodeSection section;
try {
section = node.getSection(NodeSection.SERVICE);
if (section instanceof ClassSwitch) {
switched += ((ClassSwitch) section).getSwitchedJobsPerClass(jobClass.getId());
}
section = node.getSection(NodeSection.OUTPUT);
if (section instanceof Fork) {
switched += ((Fork) section).getSwitchedJobsPerClass(jobClass.getId());
}
} catch (NetException ne) {
continue;
}
}
return switched;
}
/**
* Gets the total number of consumed jobs in the whole network
* @param jobClass the job class
* @return the total number of consumed jobs in the whole network
*/
public int getConsumedJobs() {
//consumed jobs
int consumed = 0;
for (int i = 0; i < nodes.size(); i++) {
NetNode node = nodes.get(i);
NodeSection section;
try {
section = node.getSection(NodeSection.INPUT);
if (section instanceof Enabling) {
consumed += ((Enabling) section).getConsumedJobs();
}
} catch (NetException ne) {
continue;
}
}
return consumed;
}
/**
* Gets the total number of consumed jobs in the whole network for the specified class
* @param jobClass the job class
* @return the total number of consumed jobs in the whole network for the specified class
*/
public int getConsumedJobs(JobClass jobClass) {
//consumed jobs
int consumed = 0;
for (int i = 0; i < nodes.size(); i++) {
NetNode node = nodes.get(i);
NodeSection section;
try {
section = node.getSection(NodeSection.INPUT);
if (section instanceof Enabling) {
consumed += ((Enabling) section).getConsumedJobsPerClass(jobClass.getId());
}
} catch (NetException ne) {
continue;
}
}
return consumed;
}
/**
* Gets the total number of produced jobs in the whole network
* @param jobClass the job class
* @return the total number of produced jobs in the whole network
*/
public int getProducedJobs() {
//produced jobs
int produced = 0;
for (int i = 0; i < nodes.size(); i++) {
NetNode node = nodes.get(i);
NodeSection section;
try {
section = node.getSection(NodeSection.OUTPUT);
if (section instanceof Firing) {
produced += ((Firing) section).getProducedJobs();
}
} catch (NetException ne) {
continue;
}
}
return produced;
}
/**
* Gets the total number of produced jobs in the whole network for the specified class
* @param jobClass the job class
* @return the total number of produced jobs in the whole network for the specified class
*/
public int getProducedJobs(JobClass jobClass) {
//produced jobs
int produced = 0;
for (int i = 0; i < nodes.size(); i++) {
NetNode node = nodes.get(i);
NodeSection section;
try {
section = node.getSection(NodeSection.OUTPUT);
if (section instanceof Firing) {
produced += ((Firing) section).getProducedJobsPerClass(jobClass.getId());
}
} catch (NetException ne) {
continue;
}
}
return produced;
}
//TODO: delete?
/**
* Aborts all the measures linked to the queue network
*/
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment