⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 userproperty.java

📁 实现网格环境下资源调度和分配的仿真
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
/* * Title:        Visual Modeler for GridSim Toolkit * Description:  This Visual Modeler enables the user to quickly create *               experiments on different Grid testbeds and generate the *               default Grid Broker source codes (in Java). * * $Id: UserProperty.java,v 1.18 2003/06/19 07:31:00 anthony Exp $ */package visualmodeler;// to handle loading XML. These packages exist since java 1.4import org.w3c.dom.*;import javax.swing.*;import javax.swing.event.*;import javax.swing.border.*;import java.awt.*;import java.awt.event.*;import java.util.*;/** * UserProperty stores the values needed for each grid user * * @author       Anthony Sulistio and Chee Shin Yeo * @version      1.1 * @invariant $none */public class UserProperty extends JDialog                          implements ActionListener, WindowListener{    // GUI part    // a hashtable to store the objects of JTextField, 20 so far.    private Hashtable hashText_;    private JButton ok_, cancel_;    private JComboBox combo_;    private JRadioButton radioFactor_, radioValue_;    private Toolkit toolkit_;    // Modal part that stores the user input values    private int hour_, min_, sec_;    private int gridSize_, lengthSize_, fileSize_, outputSize_;    private double gridMin_, gridMax_, lengthMin_, lengthMax_;    private double fileMin_, fileMax_, outputMin_, outputMax_;    private double baudRate_, delay_;    private double bNum_, dNum_;  // storing budget and deadline value    private int id_;    private String name_;    // attribute related to scheduling policy of an user    private int comboPolicy_;    private final String[] comboValue_ =                      { "No Optimisation",      "Optimise Cost",                        "Optimise Cost Plus",   "Optimise Cost and Time",                        "Optimise Time" };    // a flag to determine whether the GUI components has created or not    private boolean guiHasCreated_;    // true if prev select is for factor, false for deadline/budget value    private boolean curRadioFactor_;    // true if XML data have been populated    private boolean hasLoadXml_;    /**     * Allocates a new UserProperty object     * @param id        a grid user id     * @param name      a grid user name         * @param random    a flag to determine whether using random values to     *                  create a grid user's properties or not     * @param r         a Random object     * @pre id >= 0     * @pre name != null     * @pre r != null     * @post $none     */    public UserProperty(int id, String name, boolean random, Random r)    {        super.setModal(true);   // user can't open or use another window        super.setSize(500, 500);        super.setLocation(100, 100);        super.setTitle("User Property Dialog");        if (random == true) {            randomValue(r);        }        else {            defaultValue();        }        id_ = id;        name_ = name;        guiHasCreated_ = false;        hasLoadXml_ = false;        // init GUI components        cancel_ = null;        combo_ = null;        hashText_ = null;        ok_ = null;        radioFactor_ = null;        radioValue_ = null;        toolkit_ = null;    }    /**     * Gets the grid user name     * @return user name     * @pre $none     * @post $result != null     */    public String getUserName() {        return name_;    }    /**     * Performs a certain task when an action occurs     * @param   evt     an ActionEvent object     * @pre evt != null     * @post $none     */    public void actionPerformed(ActionEvent evt)    {        String cmd = evt.getActionCommand();        // for ok button        if (cmd.equalsIgnoreCase("ok") == true)        {            if (saveValue() == false) {                return;            }        }        // for cancel button        else {            resetValue();        }        removeListeners();        dispose();    }    /**     * Shows a grid user dialog     * @pre $none     * @post $none     */    public void showDialog()    {        if (guiHasCreated_ == false)        {            guiHasCreated_ = true;            this.addWindowListener(this);            initComponents();        }        ok_.addActionListener(this);        cancel_.addActionListener(this);        this.show();    }    /**     * Generates a Java code regarding to grid users properties     * @param indent    indentation     * @return a Java code in String object     * @pre indent != null     * @post $result != null     */    public String generateCode(String indent)    {        String seed = "seed*997*(1+" + id_ + ")+1";        final int VAL = 100;        // do the init        StringBuffer code = new StringBuffer(1000);        code.append("\n");        code.append(indent);        code.append("///////// Create ");        code.append(name_);        code.append("\n");        code.append(indent);        code.append("random = new Random(");        code.append(seed);        code.append(");\n");        code.append(indent);        code.append("glList = new GridletList();\n");        // Create the gridlets        code.append(indent);        code.append("count = (int) GridSimRandom.real(");        code.append(gridSize_);        code.append(", ");        code.append(gridMin_ / VAL);        code.append(", ");        code.append(gridMax_ / VAL);        code.append(", random.nextDouble());\n\n");        // loop to add one gridlet at the time to the linked-list        code.append(indent);        code.append("// A loop that creates new Gridlets\n");        code.append(indent);        code.append("for (int i = 0; i < count; i++) {\n");        code.append(indent);        code.append("    ");        code.append("double len = GridSimRandom.real(");        code.append(lengthSize_);        code.append(", ");        code.append(lengthMin_ / VAL);        code.append(", ");        code.append(lengthMax_ / VAL);        code.append(", random.nextDouble());\n\n");        code.append(indent);        code.append("    ");        code.append("long file = (long) GridSimRandom.real(");        code.append(fileSize_);        code.append(", ");        code.append(fileMin_ / VAL);        code.append(", ");        code.append(fileMax_ / VAL);        code.append(", random.nextDouble());\n\n");        code.append(indent);        code.append("    ");        code.append("long out = (long) GridSimRandom.real(");        code.append(outputSize_);        code.append(", ");        code.append(outputMin_ / VAL);        code.append(", ");        code.append(outputMax_ / VAL);        code.append(", random.nextDouble());\n\n");        code.append(indent);        code.append("    // Creates a new Gridlet entity \n");        code.append(indent);        code.append("    ");        code.append("Gridlet gl = new Gridlet(i, len, file, out);\n");        code.append(indent);        code.append("    glList.add(gl);   // Adds a new Gridlet into a list\n");        code.append(indent);        code.append("}\n\n");        // create the experiment        code.append(indent);        code.append("expt = new Experiment(");        code.append(id_);        code.append(", glList, ");        code.append(comboPolicy_);        code.append(", ");        code.append(curRadioFactor_);        code.append(", ");        code.append(dNum_);        code.append(", ");        code.append(bNum_);        code.append(",\n");        code.append(indent);        code.append("    \"report");        code.append(id_);        code.append(".txt\", resourceNameList);\n\n");        // create the user entity        code.append(indent);        code.append("userEntity = new UserEntity(\"User");        code.append(id_);        code.append("\", expt, ");        code.append(baudRate_);        code.append(", ");        code.append(seed);        code.append(",\n    ");        code.append(indent);        code.append(delay_);        code.append(", false);\n");        return code.toString();    }    /**     * Generates a XML code regarding to grid users properties     * @param spaces    number of spaces     * @return a XML code in String object     * @pre spaces != null     * @post $result != null     */    public String saveFile(String spaces)    {        final int VAL = 100;        String indent = spaces + "    ";        String tab = indent + "    ";        String doubleTab = tab + "    ";        // write the user header        StringBuffer xml = new StringBuffer(1000);        xml.append("\n\n");        xml.append(spaces);        xml.append("<user>\n");        // write the user id        xml.append(indent);        xml.append("<id> ");        xml.append(id_);        xml.append(" </id>\n");        // write the user name        xml.append(indent);        xml.append("<name> ");        xml.append(name_);        xml.append(" </name>\n");        // write the baud rate        xml.append(indent);        xml.append("<baudRate> ");        xml.append(baudRate_);        xml.append(" </baudRate>\n");        // write the time that consists of hour, minute and second        xml.append(indent);        xml.append("<time>\n");        xml.append(tab);        xml.append("<hour> ");        xml.append(hour_);        xml.append(" </hour>\n");        xml.append(tab);        xml.append("<minute> ");        xml.append(min_);        xml.append(" </minute>\n");        xml.append(tab);        xml.append("<second> ");        xml.append(sec_);        xml.append(" </second>\n");        xml.append(indent);        xml.append("</time>\n");        // write the delay        xml.append(indent);        xml.append("<delay> ");        xml.append(delay_);        xml.append(" </delay>\n");        // write scheduling strategy - choose one from the 5 options        xml.append(indent);        xml.append("<schedulingStrategy> ");        xml.append(comboValue_[comboPolicy_]);        xml.append(" </schedulingStrategy>\n");        // write the gridlet property        xml.append(indent);        xml.append("<gridletProperty>\n");        // write the gridlet size, min deviation and max deviation        xml.append(tab);        xml.append("<gridlet>\n");        xml.append(doubleTab);        xml.append("<size> ");        xml.append(gridSize_);        xml.append(" </size>\n");        xml.append(doubleTab);        xml.append("<minDeviation> ");        xml.append( gridMin_ / VAL );        xml.append(" </minDeviation>\n");        xml.append(doubleTab);        xml.append("<maxDeviation> ");        xml.append( gridMax_ / VAL );        xml.append(" </maxDeviation>\n");        xml.append(tab);        xml.append("</gridlet>\n");        // write the length size, min deviation and max deviation        xml.append(tab);        xml.append("<length>\n");        xml.append(doubleTab);        xml.append("<size> ");        xml.append(lengthSize_);        xml.append(" </size>\n");        xml.append(doubleTab);        xml.append("<minDeviation> ");        xml.append( lengthMin_ / VAL );        xml.append(" </minDeviation>\n");        xml.append(doubleTab);        xml.append("<maxDeviation> ");        xml.append( lengthMax_ / VAL );        xml.append(" </maxDeviation>\n");        xml.append(tab);        xml.append("</length>\n");        // write the file size, min deviation and max deviation        xml.append(tab);        xml.append("<file>\n");        xml.append(doubleTab);        xml.append("<size> ");        xml.append(fileSize_);        xml.append(" </size>\n");        xml.append(doubleTab);        xml.append("<minDeviation> ");        xml.append(fileMin_ / VAL);        xml.append(" </minDeviation>\n");

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -