📄 gridstatistics.java
字号:
/* * Title: GridSim Toolkit * Date: May 2003 * Description: GridSim (Grid Simulation) Toolkit for Modeling and Simulation * of Parallel and Distributed Systems such as Clusters and Grids * Licence: GPL - http://www.gnu.org/copyleft/gpl.html * * $Id: GridStatistics.java,v 1.21 2004/11/01 02:52:35 anthony Exp $ */package gridsim;import java.util.*;import java.io.*;import eduni.simjava.*;import gridsim.GridSimTags;/** * Records statistical data reported by other entities. * <p> * It stores data objects * along with its arrival time and the ID of the machine and the PE * (Processing Element) allocated to it. It acts as a placeholder for * maintaining the amount of resource share allocated at various times for * simulating time-shared scheduling using internal events. * * @author Manzur Murshed and Rajkumar Buyya * @since GridSim Toolkit 1.0 * @invariant $none */public class GridStatistics extends Sim_entity{ private boolean active_; private PrintWriter outFile_; private LinkedList statList_; private LinkedList statSortByCategoryData_; private String[] excludeFromFile_; private String[] excludeFromProcessing_; /** * Allocates a new GridStatistics object * @param name the entity name * @throws Exception This happens when creating this entity before * initializing GridSim package or this entity name is * <tt>null</tt> or empty * @see gridsim.GridSim#init(int, Calendar, boolean, String[], String[], * String) * @pre name != null * @post $none */ public GridStatistics(String name) throws Exception { super(name); active_ = false; outFile_ = null; statList_ = null; statSortByCategoryData_ = null; excludeFromFile_ = null; excludeFromProcessing_ = null; } /** * Allocates a new GridStatistics object with a set of parameters * @param name the entity name * @param fileName the file name to be written into * @param append if it is true, then bytes will be written to the end * of the file rather than the beginning * @param excludeFromFile List of names to be excluded from * statistics * @param excludeFromProcessing List of names to be excluded from * writing into a file * @throws Exception This happens when creating this entity before * initializing GridSim package or this entity name is * <tt>null</tt> or empty * @see gridsim.GridSim#init(int, Calendar, boolean, String[], String[], * String) * @pre name != null * @pre fileName != null * @post $none */ public GridStatistics(String name, String fileName, boolean append, String[] excludeFromFile, String[] excludeFromProcessing) throws Exception { super(name); active_ = true; try { FileWriter fw = new FileWriter(fileName, append); BufferedWriter bw = new BufferedWriter(fw); outFile_ = new PrintWriter(bw); statList_ = new LinkedList(); excludeFromFile_ = excludeFromFile; excludeFromProcessing_ = excludeFromProcessing; statSortByCategoryData_ = null; } catch (IOException e) { System.out.println("GridStatistics() : Error - " + "unable to open " + fileName); } } ////////////////////////// INTERNAL CLASS ///////////////////////// /** * This class can be used to sort a LinkedList of Stat in ascending order * by the field categoryNameData * @invariant $none */ private class OrderByCategoryNameData implements Comparator { /** * Allocates a new OrderByCategoryNameData object * @pre $none * @post $none */ public OrderByCategoryNameData() { super(); } /** * Compares two objects * @param a the first Object to be compared * @param b the second Object to be compared * @return the value 0 if both Objects are equal; * a value less than 0 if the first Object is lexicographically * less than the second Object; * and a value greater than 0 if the first Object is * lexicographically greater than the second Object. * @throws ClassCastException <tt>a</tt> and <tt>b</tt> are expected * to be of type <tt>Stat</tt> * @see gridsim.Stat * @pre a != null * @pre b != null * @post $none */ public int compare(Object a, Object b) throws ClassCastException { String c1 = ((Stat) a).getCategory(); String c2 = ((Stat) b).getCategory(); // if both objects have the same category if ( c1.equals(c2) ) { String n1 = ((Stat) a).getName(); String n2 = ((Stat) b).getName(); // if both objects have the same name if ( n1.equals(n2) ) { String d1 = ((Stat) a).getData(); String d2 = ((Stat) b).getData(); return d1.compareTo(d2); } else { return n1.compareTo(n2); } } else { return c1.compareTo(c2); } } } // end internal class /** * This class can be used to sort a LinkedList of Stat in ascending order * by the field categoryFieldData * @invariant $none */ private class OrderByCategoryData implements Comparator { /** * Allocates a new OrderByCategoryData object * @pre $none * @post $none */ public OrderByCategoryData() { super(); } /** * Compares two objects * @param a the first Object to be compared * @param b the second Object to be compared * @return the value 0 if both Objects are equal; * a value less than 0 if the first Object is lexicographically * less than the second Object; * and a value greater than 0 if the first Object is * lexicographically greater than the second Object. * @throws ClassCastException <tt>a</tt> and <tt>b</tt> are expected * to be of type <tt>Stat</tt> * @see gridsim.Stat * @pre a != null * @pre b != null * @post $none */ public int compare(Object a, Object b) throws ClassCastException { String c1 = ((Stat) a).getCategory(); String c2 = ((Stat) b).getCategory(); if ( c1.equals(c2) ) { String d1 = ((Stat) a).getData(); String d2 = ((Stat) b).getData(); return d1.compareTo(d2); } else { return c1.compareTo(c2); } } } // end internal class /** * This class can be used to sort a LinkedList of Stat in ascending order * by the field categoryNameField * @invariant $none */ private class OrderByCategoryName implements Comparator { /** * Allocates a new OrderByCategoryName object * @pre $none * @post $none */ public OrderByCategoryName() { super(); } /** * Compares two objects * @param a the first Object to be compared * @param b the second Object to be compared * @return the value 0 if both Objects are equal; * a value less than 0 if the first Object is lexicographically * less than the second Object; * and a value greater than 0 if the first Object is * lexicographically greater than the second Object. * @throws ClassCastException <tt>a</tt> and <tt>b</tt> are expected * to be of type <tt>Stat</tt> * @see gridsim.Stat * @pre a != null * @pre b != null * @post $none */ public int compare(Object a, Object b) throws ClassCastException { String c1 = ((Stat) a).getCategory(); String c2 = ((Stat) b).getCategory(); if ( c1.equals(c2) ) { String n1 = ((Stat) a).getName(); String n2 = ((Stat) b).getName(); return n1.compareTo(n2); } else { return c1.compareTo(c2); } } } // end internal class /** * This class can be used to sort a LinkedList of Stat in ascending order * by the field categoryField * @invariant $none */ private class OrderByCategory implements Comparator { /** * Allocates a new OrderByCategory object * @pre $none * @post $none */ public OrderByCategory() { super(); } /** * Compares two objects * @param a the first Object to be compared * @param b the second Object to be compared * @return the value 0 if both Objects are equal; * a value less than 0 if the first Object is lexicographically * less than the second Object; * and a value greater than 0 if the first Object is * lexicographically greater than the second Object. * @throws ClassCastException <tt>a</tt> and <tt>b</tt> are expected * to be of type <tt>Stat</tt> * @see gridsim.Stat * @pre a != null * @pre b != null * @post $none */ public int compare(Object a, Object b) throws ClassCastException { String c1 = ((Stat) a).getCategory(); String c2 = ((Stat) b).getCategory(); return c1.compareTo(c2); } } // end internal class /** * This class is used to store a number associated with its index * @invariant $none */ private class Times { private int index_; private int val_; /** * Allocates a new Times object * @param index a reference number * @param val an integer value * @pre $none * @post $none */ public Times(int index, int val) { this.index_ = index; this.val_ = val; } /** * Gets the index number * @return index number * @pre $none * @post $none */ public int getIndex() { return index_; } /** * Gets the value * @return integer value * @pre $none * @post $none */ public int getValue() { return val_; } } // end internal class /** * This class sorts the order of Times object by its index value * @see gridsim.GridStatistics.Times * @invariant $none */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -