Main init() { // Create a chart to monitor the infection progress rate final XYLineChart chart = new XYLineChart("Infection Rate", 5.0, "Infected Nodes (%)", "time(s)"); chart.setYRange(false, 0, 100); chart.setSeriesLinesAndShapes("s0", true, true); Gui.setFrameRectangle("MainFrame", 0, 0, 480, 480); Gui.setFrameRectangle("Infection Rate", 484, 0, 480, 480); // Create the simulation nodes for (int i = 0; i < TOTAL_NODES; i++) new Node(); // Initialize the simulation nodes for (Node i : NodeDB.nodes()) i.init(); NodeDB.randomNode().infect(); // Sets up a periodic task that, at one second intervals, computes and shows the percentage of // infected nodes in the system // Stops the simulation when it detects that every node is infected... new PeriodicTask(1.0) { public void run() { double T = 0, N = 0; for (Node n : NodeDB.nodes()) { if (n.infected) T++; N++; } chart.getSeries("s0").add(Simulation.currentTime(), 100.0 * T / N); if (N == T) stop(); }; }; // From time to time, select a random node to go fail and go offline... new Task(0) { public void run() { NodeDB.randomNode().crash(); reSchedule(0.5 + 0.5 * rg.nextDouble()); // schedules a new execution of this task... } }; // From time to time, create a new node. If the rate of births and deaths is the same, // the size of the system should stay constant on average. new Task(0) { public void run() { new Node().init(); reSchedule(0.5 + 0.5 * rg.nextDouble()); // schedules a new execution of this task... } }; super.setSimulationMaxTimeWarp(2.0); return this; }
public static void printType(NodeType type) { if (type instanceof NodeSynonym) { System.out.println("NodeSynonym: " + ((NodeSynonym) type).getID()); } // System.out.println("NodeSynonym: " + ((NodeSynonym)type).getType()); else if (type instanceof NodePLType) { System.out.println("PLType: " + ((NodePLType) type).getType()); } else if (type instanceof NodePointer) { System.out.println("Puntero a"); System.out.print(" "); printType(((NodePointer) type).getType()); } else if (type instanceof NodeArray) { System.out.print("Arreglo de tamaño " + ((NodeArray) type).getSize() + " de tipo: "); printType(((NodeArray) type).getType()); } else if (type instanceof NodeStructure) { NodeStructure structure = (NodeStructure) type; // List<NodeElement> elements = record.getElements(); CHANGE List<NodeElement> elements = structure.getElements(); Iterator<NodeElement> iter = elements.iterator(); // System.out.println("Estructura: " + "Nombre: " + record.getName()); CHANGE System.out.println("Estructura: " + "Nombre: " + structure.getName()); int i = 1; NodeElement element; while (iter.hasNext()) { element = iter.next(); System.out.println("Campo " + i + ": "); i++; // System.out.println("Nombre: " + (element.getName())); CHANGE System.out.println("Nombre: " + (element.getID())); System.out.print("Tipo: "); printType(element.getType()); } } else if (type instanceof NodeList) { NodeList list = (NodeList) type; // List<NodeField> fields = list.getFields(); CHANGE List<NodeElement> fields = list.getFields(); // Iterator<NodeField> iter = fields.iterator(); CHANGE Iterator<NodeElement> iter = fields.iterator(); System.out.println("Lista"); System.out.println("Nombre: " + list.getName()); System.out.println("LinkType: " + list.getLinkType()); System.out.println("LinkNexName: " + list.getLinkNextName()); if (list.getLinkPrevName() != null) { System.out.println("LinkPrevName: " + list.getLinkPrevName()); } int i = 1; NodeElement field; while (iter.hasNext()) { field = iter.next(); System.out.println("Campo " + i + ":"); i++; // System.out.println("Nombre: " + (field.getName())); CHANGE System.out.println("Nombre: " + (field.getID())); System.out.print("Tipo: "); printType(field.getType()); } // if (list.getMemalloc() != null ) CHANGE if (list.getMemAlloc() != null) { System.out.println("MemallocFunction: "); // System.out.println(list.getMemalloc()); CHANGE System.out.println(list.getMemAlloc()); } } else if (type instanceof NodeFile) { NodeFile file = (NodeFile) type; System.out.println("Archivo"); System.out.println("Nombre: " + file.getName()); System.out.println("Ruta: " + file.getPath()); System.out.println("Delimitador: " + file.getDelimiter()); if (file.getEof() != null) { System.out.println("EOF: " + file.getEof()); } if (file.getEol() != null) { System.out.println("EOL: " + file.getEol()); } if (file.getStructure() != null) { System.out.println("Estructura: " + file.getStructure()); } } else if (type instanceof NodeDB) { NodeDB db = (NodeDB) type; List<NodeDBColumn> regs = db.getColumns(); Iterator<NodeDBColumn> iter = regs.iterator(); System.out.println("Base de Datos"); System.out.println("DBMS: " + db.getDBMSID()); // System.out.println("connectionID " + db.getConnID()); CHANGE System.out.println("connectionID " + db.getConnectionID()); // System.out.println("Table name: " + db.getTable()); CHANGE System.out.println("Table name: " + db.getTableName()); System.out.println("Registros:"); int i = 1; while (iter.hasNext()) { NodeDBColumn rec = iter.next(); System.out.println( "Registro " + i + ": " + rec.getColType() + " tipo: " + rec.getColType()); i++; } } }