}
/*********************SIM DEFINITION MODEL*********************/
//Loads ExactModel and transforms it to CommonModel
ExactModel exact = new ExactModel();
XMLUtils xmlUtils = new XMLUtils();
Document inputDoc;
try {
inputDoc = xmlUtils.loadXML(input);
exact.loadDocument(inputDoc);
} catch (SAXException e1) {
logger.error("Cannot parse correctly input JMVA model: " + e1.getMessage());
return null;
} catch (IOException e1) {
logger.error("I/O error opening input JMVA model: " + e1.getMessage());
return null;
}
logger.debug("Input model opened correctly...");
CommonModel simModel = new CommonModel();
List<String> warnings = ModelConverter.convertJMVAtoJSIM(exact, simModel);
// Last element of warning is transform matrix
for (int i = 0; i < warnings.size(); i++) {
logger.warn("Warning during conversion: " + warnings.get(i));
}
// Removes all measures from classes with null service demands
removeNullMeasures(exact, simModel);
logger.debug("Removed null measures from simulator model");
Document modelDocument = XMLWriter.getDocument(simModel, outputModel);
logger.debug("Converted JMVA xml to JSIM one");
// Adds blocking region informations to model document
NodeList blockingList = inputDoc.getElementsByTagName(XMLConstantNames.XML_E_REGION);
// If model has one blocking region only, adds router to it (otherwise a job will exit from
// region when it's not requested
if (blockingList.getLength() == 1) {
Element region = (Element) blockingList.item(0);
Element router = inputDoc.createElement(XMLConstantNames.XML_E_REGIONNODE);
router.setAttribute(XMLConstantNames.XML_A_REGIONNODE_NAME, "Router");
region.insertBefore(router, region.getFirstChild());
}
Element root = modelDocument.getDocumentElement();
NodeList preload = root.getElementsByTagName(XMLConstantNames.XML_E_PRELOAD);
NodeList measures = root.getElementsByTagName(XMLConstantNames.XML_E_MEASURE);
Node lastMeasure = measures.getLength() > 0 ? measures.item(measures.getLength() - 1) : null;
for (int i = 0; i < blockingList.getLength(); i++) {
Element imported = (Element) modelDocument.importNode(blockingList.item(i), true);
String name = imported.getAttribute(XMLConstantNames.XML_A_REGION_NAME);
if (preload.getLength() > 0) {
root.insertBefore(imported, preload.item(0));
} else {
root.appendChild(imported);
}
// Adds blocking region measures
Element dropRate = (Element) lastMeasure.cloneNode(true);
dropRate.setAttribute(XMLConstantNames.XML_A_MEASURE_NODETYPE, XMLConstantNames.NODETYPE_REGION);
dropRate.setAttribute(XMLConstantNames.XML_A_MEASURE_STATION, name);
dropRate.setAttribute(XMLConstantNames.XML_A_MEASURE_TYPE, SimulationDefinition.MEASURE_DR);
// For each class add drop rate measure
for (int j = 0; j < exact.getClasses(); j++) {
Element cloned = (Element) dropRate.cloneNode(true);
cloned.setAttribute(XMLConstantNames.XML_A_MEASURE_CLASS, exact.getClassNames()[j]);
cloned.setAttribute(XMLConstantNames.XML_A_MEASURE_NAME, exact.getClassNames()[j] + "_" + name + "_Drop Rate");
root.insertBefore(cloned, lastMeasure);
lastMeasure = cloned;
}
}
logger.debug("Added finite capacity regions");