Commit 73458e3b authored by rosemaryng's avatar rosemaryng
Browse files

[Refactor] Removed unnecessary helper methods and helper classes to reduce...

[Refactor] Removed unnecessary helper methods and helper classes to reduce line of codes and improve readability
parent 6f8d72eb
......@@ -97,6 +97,7 @@ public class Queue extends InputSection {
private String[] dropStrategies;
private ServiceStrategy[] retrialDistributionStrategies;
private int size; // queue + servers
......
......@@ -553,6 +553,28 @@ public class LinkedJobInfoList implements JobInfoList {
doRemove(jobInfo, 0, 0);
}
// @Override
// public void remove(JobInfo jobInfo, int event) {
// if (event == NetEvent.EVENT_RETRIAL_JOB) {
// int c = jobInfo.getJob().getJobClass().getId();
// updateQueueLength(jobInfo);
// updateUtilization(jobInfo);
// updateUtilizationJoin(jobInfo);
// updateThroughput(jobInfo);
// finalRemove(jobInfo, list, 0);
// finalRemove(jobInfo, listPerClass[c], 0);
// jobsOut++;
// jobsOutPerClass[c]++;
// lastJobOutTime = getTime();
// lastJobOutTimePerClass[c] = getTime();
// totalSojournTime += getTime() - jobInfo.getEnteringTime();
// totalSojournTimePerClass[c] += getTime() - jobInfo.getEnteringTime();
// lastJobSojournTime = getTime() - jobInfo.getEnteringTime();
// lastJobSojournTimePerClass[c] = getTime() - jobInfo.getEnteringTime();
// }
//
// }
/* (non-Javadoc)
* @see jmt.engine.QueueNet.JobInfoList#removeFirst()
*/
......@@ -869,10 +891,14 @@ public class LinkedJobInfoList implements JobInfoList {
Measure m = responseTimePerClass[c];
if (m != null) {
m.update(getTime() - jobInfo.getEnteringTime(), 1.0);
System.out.println("Response Time: " + (getTime() - jobInfo.getEnteringTime()));
}
}
if (responseTime != null) {
responseTime.update(getTime() - jobInfo.getEnteringTime(), 1.0);
System.out.println("Response Time: " + (getTime() - jobInfo.getEnteringTime()));
}
}
......@@ -890,6 +916,7 @@ public class LinkedJobInfoList implements JobInfoList {
residenceTime.updateSampleJob(jobInfo.getJob());
residenceTime.update(getTime() - jobInfo.getEnteringTime(), 1.0);
}
}
protected void updateUtilization(JobInfo jobInfo) {
......@@ -992,10 +1019,13 @@ public class LinkedJobInfoList implements JobInfoList {
Measure m = retrialRatePerClass[c];
if (m != null) {
m.update(getTime() - getLastJobRetrialTimePerClass(jobClass), 1.0);
System.out.println(getTime() - getLastJobRetrialTimePerClass(jobClass));
}
}
if (retrialRate != null) {
retrialRate.update(getTime() - getLastJobRetrialTime(), 1.0);
System.out.println(getTime() - getLastJobRetrialTime());
}
}
......
......@@ -691,15 +691,15 @@ public class NetNode extends SimEntity {
* Helper function to remove job from the NodeJobsList
* @param data the jobInfo data looking to be removed.
*/
private boolean removeJobFromNodeJobsList(Job data, int event) {
Job job = data;
JobInfo jobInfo = jobsList.lookFor(job);
if (jobInfo != null) {
jobsList.remove(jobInfo, event);
return true;
}
return false;
}
// private boolean removeJobFromNodeJobsList(Job data, int event) {
// Job job = data;
// JobInfo jobInfo = jobsList.lookFor(job);
// if (jobInfo != null) {
// jobsList.remove(jobInfo, event);
// return true;
// }
// return false;
// }
......
......@@ -51,6 +51,7 @@ import jmt.gui.common.editors.GrayCellRenderer;
import jmt.gui.common.editors.ImagedComboBoxCellEditorFactory;
import jmt.gui.exact.table.DisabledCellRenderer;
import jmt.gui.exact.table.ExactCellEditor;
import jmt.gui.jsimwiz.panels.ClassesPanel;
/**
* Created by IntelliJ IDEA.
......@@ -451,28 +452,6 @@ public class InputSectionPanel extends WizardPanel implements CommonConstants {
};
}
// An action to bring up a new window to edit the distribution based on the selected impatience type
private AbstractAction editRetrialFullParameter() {
return new AbstractAction("Edit Retrial Full") {
private static final long serialVersionUID = 1L;
public void actionPerformed(ActionEvent e) {
int selectedRow = queueTable.getSelectedRow();
Object classKey = getClassKeyFromRow(selectedRow);
// Retrial retrial = data.getRetrialDistribution(stationKey, classKey);
// Distribution distribution = (Distribution) retrial.getDistribution();
//
// DistributionsEditor retrialEditor = DistributionsEditor.getInstance(InputSectionPanel.this.getParent(), distribution);
// retrialEditor.setTitle("Editing " + classData.getClassName(classKey) + " Retrial Rate");
// retrialEditor.show();
// distribution = retrialEditor.getResult();
// data.setRetrial(stationKey, classKey, distribution.getC());
queueTable.repaint();
}
};
}
/** This method:
* 1) Gets the corresponding editButtonRenderer based on the row parameter
* 2) Enables/disables the edit button depending on the selected impatience strategy for that row
......@@ -602,10 +581,12 @@ public class InputSectionPanel extends WizardPanel implements CommonConstants {
} else if (columnIndex == COLUMN_DROP_RULE) {
data.setDropRule(stationKey, classKey, (String) aValue);
if (aValue.toString().equals(FINITE_RETRIAL)) {
Distribution distribution = (Distribution) data.getRetrialDistribution(stationKey, classKey);
Distribution retrialDistribution = (Distribution) data.getRetrialDistribution(stationKey, classKey);
DistributionsEditor editor = DistributionsEditor.getInstance(InputSectionPanel.this.getParent(), retrialDistribution);
String className = classData.getClassName(classKey);
distribution = RetrialEditor.displayEditor(InputSectionPanel.this.getParent(), className, distribution);
data.setRetrialDistribution(stationKey, classKey, distribution);
editor.setTitle("Editing " + className + " Retrial Time Distribution...");
editor.show();
data.setRetrialDistribution(stationKey, classKey, editor.getResult());
queueTable.repaint();
}
} else if (columnIndex == COLUMN_SERVICE_WEIGHT) {
......
package jmt.gui.common.panels;
import java.awt.Container;
import jmt.gui.common.distributions.Distribution;
import jmt.gui.common.editors.BalkingStrategyEditor;
import jmt.gui.common.editors.DistributionsEditor;
import jmt.gui.common.serviceStrategies.LDStrategy;
public class RetrialEditor {
public static Distribution displayEditor(Container parent, String className, Distribution distribution) {
DistributionsEditor editor = DistributionsEditor.getInstance(parent, distribution);
// Sets editor window title
editor.setTitle(
"Editing " + className + " Retrial Time Distribution...");
// Shows editor window
editor.show();
return editor.getResult();
}
}
......@@ -134,6 +134,8 @@ public class XMLWriter implements CommonConstants, XMLConstantNames {
public static final String transitionUtilitiesSuffix = "TransitionUtilities.";
public static final String distributionContainerClasspath = "jmt.engine.random.DistributionContainer";
private static final String SERVICE_TIME_STRATEGY_PATH = strategiesClasspathBase + serviceStrategiesSuffix + "ServiceTimeStrategy";
public static void writeXML(String fileName, CommonModel model) {
writeToResult(new StreamResult(new File(fileName)), model, fileName);
}
......@@ -508,7 +510,7 @@ public class XMLWriter implements CommonConstants, XMLConstantNames {
distrParams[i] = DistributionWriter
.getDistributionParameter((Distribution) model
.getClassDistribution(currentClass), model,
currentClass, "ServiceTimeStrategy", strategiesClasspathBase + serviceStrategiesSuffix + "ServiceTimeStrategy");
currentClass, "ServiceTimeStrategy", SERVICE_TIME_STRATEGY_PATH);
} else {
// otherwise write a null parameter
String name = "ServiceTimeStrategy";
......@@ -562,26 +564,27 @@ public class XMLWriter implements CommonConstants, XMLConstantNames {
// ...and add it to queue element's children
//serverPreemptive.appendParameterElement(doc, queue); // uncomment this for serverPreemptive for LCFS-PR
// Drop policies. They are different for each customer class
// Drop policies and retrialDistribution. They are different for each customer class
Vector<Object> classes = model.getClassKeys();
XMLParameter[] dropStrategy = new XMLParameter[classes.size()];
XMLParameter dropStrategies = new XMLParameter("dropStrategies",
String.class.getName(), null, dropStrategy, false);
XMLParameter[] rd = new XMLParameter[classes.size()];
XMLParameter retrialDistributions = new XMLParameter("retrialDistributions",
strategiesClasspathBase + "ServiceStrategy",
null, rd, false);
for (int i = 0; i < dropStrategy.length; i++) {
String strategy = model.getDropRule(stationKey, classes.get(i));
dropStrategy[i] = new XMLParameter("dropStrategy",
String.class.getName(), model.getClassName(classes.get(i)),
DROP_RULES_MAPPING.get(strategy), true);
}
dropStrategies.appendParameterElement(doc, queue);
String distributionPath = Distribution.class.getCanonicalName();
XMLParameter[] retrialDistribution = new XMLParameter[classes.size()];
String.class.getName(), model.getClassName(classes.get(i)),
DROP_RULES_MAPPING.get(strategy), true);
XMLParameter retrialDistributions = new XMLParameter("retrialDistributions", strategiesClasspathBase + "ServiceStrategy",
null, retrialDistribution, false);
for (int i = 0; i < retrialDistribution.length; i++) {
retrialDistribution[i] = createRetrialParameter(model, stationKey, classes.get(i));
rd[i] = DistributionWriter
.getDistributionParameter((Distribution) model.getRetrialDistribution(stationKey, classes.get(i)),
model, classes.get(i), "ServiceTimeStrategy", SERVICE_TIME_STRATEGY_PATH);
}
dropStrategies.appendParameterElement(doc, queue);
retrialDistributions.appendParameterElement(doc, queue);
/*
......@@ -673,15 +676,6 @@ public class XMLWriter implements CommonConstants, XMLConstantNames {
.getDistributionParameter(renegingDistribution, model, classKey, renegingClassName, renegingPath);
}
private static XMLParameter createRetrialParameter(CommonModel model, Object stationKey, Object classKey) {
Object retrialDistribution = model.getRetrialDistribution(stationKey, classKey);
return DistributionWriter
.getDistributionParameter((Distribution) retrialDistribution, model, classKey,"ServiceTimeStrategy", strategiesClasspathBase + serviceStrategiesSuffix + "ServiceTimeStrategy");
}
private static XMLParameter createBalkingParameter(CommonModel model, Object stationKey,
Object classKey, int numOfClasses, int classIndex) {
String balkingClassName = Balking.class.getSimpleName();
......@@ -886,7 +880,7 @@ public class XMLWriter implements CommonConstants, XMLConstantNames {
distrParams[i] = DistributionWriter
.getDistributionParameter(
(Distribution) serviceDistribution, model,
currentClass, "ServiceTimeStrategy", strategiesClasspathBase + serviceStrategiesSuffix + "ServiceTimeStrategy");
currentClass, "ServiceTimeStrategy", SERVICE_TIME_STRATEGY_PATH);
} else if (serviceDistribution instanceof ZeroStrategy) {
// Zero Service Time Strategy
distrParams[i] = new XMLParameter("ZeroServiceTimeStrategy",
......
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