Commit 24ee1127 authored by rosemaryng's avatar rosemaryng
Browse files

[Retry Full] Added temporary solution in Queue and related class to handle case for retrial full

parent 6c3defb2
package jmt.engine.NetStrategies.ImpatienceStrategies;
import jmt.common.exception.IncorrectDistributionParameterException;
import jmt.engine.NetStrategies.ImpatienceStrategies.ImpatienceMeasurement.DoubleValueImpatienceMeasurement;
import jmt.engine.NetStrategies.ImpatienceStrategies.ImpatienceMeasurement.ImpatienceMeasurement;
import jmt.engine.random.Distribution;
import jmt.engine.random.Parameter;
import org.apache.commons.lang.mutable.MutableDouble;
public class Retrial implements Impatience {
private Distribution distribution;
private Parameter parameter;
private ImpatienceType impatienceType;
public Retrial(Distribution distribution, Parameter parameter) {
this.distribution = distribution;
this.parameter = parameter;
}
/**
* Returns the type of impatience
*/
@Override
public ImpatienceType impatienceType() {
return impatienceType;
}
@Override
public boolean isImpatienceType(ImpatienceType type) {
return impatienceType == type;
}
@Override
public void generateImpatience(ImpatienceMeasurement impatienceObject) {
if (!(impatienceObject instanceof DoubleValueImpatienceMeasurement)) {
throw new IllegalArgumentException("Supplied argument for generateImpatience() method in "
+ "Retrial must be of type DoubleValueImpatienceMeasurement.");
}
Double retrialDelay = 0.0;
try {
retrialDelay = distribution.nextRand(parameter);
if (retrialDelay < 0.0) {
retrialDelay = 0.0;
}
} catch (IncorrectDistributionParameterException e) {
e.printStackTrace();
}
//
// MutableDouble impatienceObjectAsDouble = (DoubleValueImpatienceMeasurement) impatienceObject;
// impatienceObjectAsDouble.setValue(retrialDelay);
}
public void generateRandomDelay(DoubleValueImpatienceMeasurement value) {
try {
Double retrialDelay = distribution.nextRand(parameter);
System.out.println(retrialDelay);
} catch (IncorrectDistributionParameterException e) {
e.printStackTrace();
}
}
}
......@@ -21,12 +21,14 @@ package jmt.engine.NodeSections;
import java.util.*;
import jmt.common.exception.IncorrectDistributionParameterException;
import jmt.common.exception.NetException;
import jmt.engine.NetStrategies.ImpatienceStrategies.Balking;
import jmt.engine.NetStrategies.ImpatienceStrategies.ImpatienceMeasurement.BooleanValueImpatienceMeasurement;
import jmt.engine.NetStrategies.ImpatienceStrategies.ImpatienceMeasurement.DoubleValueImpatienceMeasurement;
import jmt.engine.NetStrategies.ImpatienceStrategies.Impatience;
import jmt.engine.NetStrategies.ImpatienceStrategies.ImpatienceType;
import jmt.engine.NetStrategies.ImpatienceStrategies.Retrial;
import jmt.engine.NetStrategies.QueueGetStrategy;
import jmt.engine.NetStrategies.QueuePutStrategy;
import jmt.engine.NetStrategies.QueueGetStrategies.FCFSstrategy;
......@@ -48,6 +50,11 @@ import jmt.engine.QueueNet.NodeSection;
import jmt.engine.QueueNet.SimConstants;
import jmt.engine.QueueNet.WaitingRequest;
import jmt.engine.dataAnalysis.Measure;
import jmt.engine.random.Distribution;
import jmt.engine.random.Exponential;
import jmt.engine.random.ExponentialPar;
import jmt.engine.random.engine.MersenneTwister;
import jmt.engine.random.engine.RandomEngine;
/**
* This class implements a generic finite/infinite queue. In finite queue, if
......@@ -93,6 +100,8 @@ public class Queue extends InputSection {
public static final String FINITE_WAITING = "waiting queue";
public static final String FINITE_RETRIAL = "retry full";
private String[] dropStrategies;
private int size;
private int maxRunning;
......@@ -117,7 +126,11 @@ public class Queue extends InputSection {
private JobInfoList FJList;
// Backup buffer when the main jobsList is full
private JobInfoList waitingRequests;
// private List<WaitingRequest> waitingRequests;
// Retrial group when the main jobsLis (primary queue) is full
private List<Integer> retrialFullGroup = new ArrayList<>();
private Retrial retrial;
//number of reneged jobs
private int renegedJobs;
......@@ -268,6 +281,7 @@ public class Queue extends InputSection {
public Queue(Integer size, Integer maxRunning, Boolean serverPreemptive, String[] dropStrategies, QueueGetStrategy getStrategy, QueuePutStrategy[] putStrategies) {
this(size.intValue(), maxRunning.intValue(), serverPreemptive.booleanValue(), false, getStrategy, putStrategies);
// Decodes drop strategies
this.dropStrategies = dropStrategies;
for (int i = 0; i < dropStrategies.length; i++) {
if (dropStrategies[i].equals(FINITE_DROP)) {
drop[i] = true;
......@@ -275,9 +289,10 @@ public class Queue extends InputSection {
} else if (dropStrategies[i].equals(FINITE_BLOCK)) {
drop[i] = false;
block[i] = true;
} else if (dropStrategies[i].equals(FINITE_WAITING)) {
} else if (dropStrategies[i].equals(FINITE_WAITING) || dropStrategies[i].equals(FINITE_RETRIAL)) {
drop[i] = false;
block[i] = false;
// retrial = new Retrial((Distribution) new Exponential(), new ExponentialPar());
}
}
}
......@@ -349,6 +364,9 @@ public class Queue extends InputSection {
//TODO rose: waiting Requests is not used
waitingRequests = new LinkedJobInfoList(jobClasses.size());
// waitingRequests.setNetSystem(node.getNetSystem());
// retrialFullGroup = new LinkedJobInfoList(jobClasses.size());
if (putStrategies == null) {
putStrategies = new QueuePutStrategy[jobClasses.size()];
for (int i = 0; i < putStrategies.length; i++) {
......@@ -470,10 +488,15 @@ public class Queue extends InputSection {
//source node is the owner node of this section, an ack is sent and a waiting
//request is created. If the source is another node the waiting request is created
//only if drop is false, otherwise an ack is sent but the job is rejected.
//
//If the selected drop is retry full, then the job is placed in the retrial group which the job will attempt to
//retry after a random amount of time.
//If the queue is infinite, the job is put into the queue and an ack is sent
job = message.getJob();
System.out.println("now dealing with" + job.getId());
System.out.println(retrialFullGroup);
//----REDIRECTION BEHAVIOUR----------//
if (redirectionON) {
......@@ -567,9 +590,30 @@ public class Queue extends InputSection {
}
// otherwise if job has been sent by another node
else if (!drop[job.getJobClass().getId()]) { //whether the user select drop
// if drop is true reject the job, else add the job to waitingRequests
addJobToBuffer(job, message, BufferType.WAITING_REQUESTS);
setRenegingEvent(job);
// if drop is true reject the job, else add the job to waitingRequests or retrial group
// Retry Full route
if (dropStrategies != null && dropStrategies[0].equals(FINITE_RETRIAL) ) {
// System.out.println("retrial!");
double randomDelay = new DoubleValueImpatienceMeasurement().doubleValue();;
try {
Exponential exponential = new Exponential();
RandomEngine randEngine = job.getNetSystem().getEngine();
exponential.setRandomEngine(randEngine);
randomDelay = exponential.nextRand(new ExponentialPar(0.5));
System.out.println("RandomDelay: " + randomDelay);
// retrial.generateImpatience(retrialDelay);
} catch (IncorrectDistributionParameterException e) {
e.printStackTrace();
}
retrialFullGroup.add(job.getId());
sendMe(NetEvent.EVENT_JOB, job, randomDelay);
} else {
addJobToBuffer(job, message, BufferType.WAITING_REQUESTS);
setRenegingEvent(job);
}
// if blocking is disabled, sends ack otherwise router of the previous node remains busy
if (!block[job.getJobClass().getId()]) {
......
......@@ -404,6 +404,7 @@ public class SimSystem {
}
} else {
//if the entity is not WAITING the event is put in the deferred queue
//TODO rose: figure out what is deferred queue
deferred.add(e);
}
}
......
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