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

📄 userproperty.java

📁 实现网格环境下资源调度和分配的仿真
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
        xml.append(doubleTab);        xml.append("<maxDeviation> ");        xml.append(fileMax_ / VAL);        xml.append(" </maxDeviation>\n");        xml.append(tab);        xml.append("</file>\n");        // write the output size, min deviation and max deviation        xml.append(tab);        xml.append("<output>\n");        xml.append(doubleTab);        xml.append("<size> ");        xml.append(outputSize_);        xml.append(" </size>\n");        xml.append(doubleTab);        xml.append("<minDeviation> ");        xml.append(outputMin_ / VAL);        xml.append(" </minDeviation>\n");        xml.append(doubleTab);        xml.append("<maxDeviation> ");        xml.append(outputMax_ / VAL);        xml.append(" </maxDeviation>\n");        xml.append(tab);        xml.append("</output>\n");        xml.append(indent);        xml.append("</gridletProperty>\n");        // write the budget and deadline property        xml.append(indent);        xml.append("<budgetDeadlineProperty>\n");        // choose either it is a factor or a value        if (curRadioFactor_ == true)         {            xml.append(tab);            xml.append("<type> factor </type>\n");        }            else         {            xml.append(tab);            xml.append("<type> value </type>\n");        }            // write the budget and deadline. don't forget the closing tag        xml.append(tab);        xml.append("<budget> ");        xml.append(bNum_);        xml.append(" </budget>\n");        xml.append(tab);        xml.append("<deadline> ");        xml.append(dNum_);        xml.append(" </deadline>\n");        // don't forget the closing tags        xml.append(indent);        xml.append("</budgetDeadlineProperty>\n");        xml.append(spaces);        xml.append("</user>\n");                    return xml.toString();    }    /**     * Checks whether XML file has been loaded or not     * @return <tt>true</tt> if it has been loaded, <tt>false</tt> otherwise     * @pre $none     * @post $none     */    public boolean hasLoadXml() {        return hasLoadXml_;    }    /**     * Loads a XML code regarding to grid users     * @param nodeList  a NodeList object     * @pre nodeList != null     * @post $none     */    public void loadXml(final NodeList nodeList)    {        hasLoadXml_ = true;        Node node;        String name, value;        int length = nodeList.getLength();        for (int i = 0; i < length; i++)        {            node = nodeList.item(i);            // only element nodes that need to be take care,            // the rests are ignored            if (node.getNodeType() != Node.ELEMENT_NODE) {                continue;            }            name = node.getNodeName();            if (name.equals("id") == true)            {                value = node.getFirstChild().getNodeValue();                // must trim the String otherwise get an exception                int id = Integer.parseInt(value.trim());                id_ = id;            }            else if (name.equals("name") == true)            {                value = node.getFirstChild().getNodeValue();                name_ = value.trim();            }            else if (name.equals("baudRate") == true)            {                value = node.getFirstChild().getNodeValue();                // must trim the String otherwise get an exception                double num = Double.parseDouble(value.trim());                baudRate_ = num;            }            else if (name.equals("time") == true)            {                // make another method to handle time                loadXmlTime( node.getChildNodes() );            }            else if (name.equals("delay") == true)            {                value = node.getFirstChild().getNodeValue();                // must trim the String otherwise get an exception                double num = Double.parseDouble(value.trim());                delay_ = num;            }            else if (name.equals("schedulingStrategy") == true)            {                // make another method to handle scheduling strategy                value = node.getFirstChild().getNodeValue();                loadXmlPolicy( value.trim() );            }            else if (name.equals("budgetDeadlineProperty") == true)            {                // make another method to handle budget and deadline                loadXmlBudgetDeadline( node.getChildNodes() );            }            else if (name.equals("gridletProperty") == true)            {                // make another method to handle gridlet                loadXmlGridlet( node.getChildNodes() );            }        }    }    /**      * An event that occurs when the window dialog is closing     * @param evt   a WindowEvent object     * @pre evt != null     * @post $none     */    public void windowClosing(WindowEvent evt)    {        resetValue();        removeListeners();    }    /**      * An event that occurs when the window dialog is closed     * @param evt   a WindowEvent object     * @pre evt != null     * @post $none     */     public void windowClosed(WindowEvent evt) {        //empty - not needed but have to due to WindowListener interface    }    /**      * An event that occurs when the window dialog is opened     * @param evt   a WindowEvent object     * @pre evt != null     * @post $none     */    public void windowOpened(WindowEvent evt) {        //empty - not needed but have to due to WindowListener interface    }    /**      * An event that occurs when the window dialog is iconified     * @param evt   a WindowEvent object     * @pre evt != null     * @post $none     */    public void windowIconified(WindowEvent evt) {        //empty - not needed but have to due to WindowListener interface    }    /**      * An event that occurs when the window dialog is deiconified     * @param evt   a WindowEvent object     * @pre evt != null     * @post $none     */    public void windowDeiconified(WindowEvent evt) {        //empty - not needed but have to due to WindowListener interface    }    /**      * An event that occurs when the window dialog is activated     * @param evt   a WindowEvent object     * @pre evt != null     * @post $none     */    public void windowActivated(WindowEvent evt) {        //empty - not needed but have to due to WindowListener interface    }    /**      * An event that occurs when the window dialog is deactivated     * @param evt   a WindowEvent object     * @pre evt != null     * @post $none     */    public void windowDeactivated(WindowEvent evt) {        //empty - not needed but have to due to WindowListener interface    }    //////////////////////////////////// PRIVATE METHODS ////////////////////    /**     * Allocates all grid user properties with default value     * @pre $none     * @post $none     */    private void defaultValue()    {        delay_ = comboPolicy_ = hour_ = min_ = sec_ = 0;        gridSize_ = lengthSize_ = outputSize_ = fileSize_ = 0;        gridMin_ = gridMax_ = lengthMin_ = lengthMax_ = 0.0;        fileMin_ = fileMax_ = outputMin_ = outputMax_ = 0.0;        curRadioFactor_ = false;        baudRate_ = bNum_ = dNum_ = 100.0;    }    /**     * Allocates all grid user properties with random values     * @param r     a Random object     * @pre r != null     * @post $none     */    private void randomValue(Random r)    {        // Maximum value. Note: if MAX changed, pls modify bNum_ and dNum_        final int MAX = 101;        final double DIVIDER = 10.0;        // with Random.nextInt(MAX) == Random.nextInt(100) if MAX = 101        baudRate_ = r.nextInt(MAX*6);        delay_ = r.nextInt(MAX);        hour_ = r.nextInt(MAX);        min_ = r.nextInt(MAX);        sec_ = r.nextInt(MAX);        gridSize_ = r.nextInt(MAX);        gridMin_ = r.nextInt(MAX) / DIVIDER;        gridMax_ = r.nextInt(MAX) / DIVIDER;        lengthSize_ = r.nextInt(MAX*MAX);        lengthMin_ = r.nextInt(MAX) / DIVIDER;        lengthMax_ = r.nextInt(MAX) / DIVIDER;        fileSize_ = r.nextInt(MAX);        fileMin_ = r.nextInt(MAX) / DIVIDER;        fileMax_ = r.nextInt(MAX) / DIVIDER;        outputSize_ = r.nextInt(MAX);        outputMin_ = r.nextInt(MAX) / DIVIDER;        outputMax_ = r.nextInt(MAX) / DIVIDER;        // for budget and deadline value        // if it is false, then it's deadline and budget value.        curRadioFactor_ = false;        // if it is b-factor and d-factor, then the range is [0.0, 1.0]        if (curRadioFactor_ == true)        {            // get integer value up to MAX = 100, then divide by 100            bNum_ = r.nextInt(MAX) / (DIVIDER * DIVIDER);            dNum_ = r.nextInt(MAX) / (DIVIDER * DIVIDER);        }        else        {            bNum_ = r.nextInt(MAX*MAX);            dNum_ = r.nextInt(MAX*MAX);        }        // there are only 5 options, but the index starts at 0        comboPolicy_ = r.nextInt(comboValue_.length);    }    /**     * Initializes all GUI component for grid user dialog     * @pre $none     * @post $none     */    private void initComponents()    {        hashText_ = new Hashtable();        toolkit_ = Toolkit.getDefaultToolkit();        GridBagLayout gridbag = new GridBagLayout();        GridBagConstraints c = new GridBagConstraints();        Font font = new Font(null, Font.PLAIN, 14);        JPanel panel = new JPanel(gridbag);        int index = 0;        c.insets = new Insets(10, 3, 10, 2);  // top, left, buttom, right        c.weighty = 0.5;        c.fill = GridBagConstraints.HORIZONTAL;        c.gridy = index++;        //////////////////        // Display the user name        JLabel label1 = new JLabel("User Name:");        label1.setFont(font);        panel.add(label1, c);        c.gridwidth = GridBagConstraints.REMAINDER;        JTextField text = new JTextField("" + name_, 20);        panel.add(text, c);        hashText_.put("user", text);        ////////////////////        // Display the baud rate        c.gridwidth = 1;        c.gridy = index++;        JLabel label2 = new JLabel("Baud Rate:");        label2.setFont(font);        panel.add(label2, c);        text = new JTextField("" + baudRate_, 4);        panel.add(text, c);        hashText_.put("baud", text);        ///////////////////////        // Display the max. simulation time        c.gridy = index++;        JLabel label3 = new JLabel("Max. simulation time:");        label3.setFont(font);        panel.add(label3, c);        c.ipadx = 5;        text = new JTextField("" + hour_, 3);        panel.add(text, c);        hashText_.put("hour", text);        panel.add(new JLabel(" hour"), c);        text = new JTextField("" + min_, 3);        panel.add(text, c);        hashText_.put("min", text);        panel.add(new JLabel(" minute"), c);        text = new JTextField("" + sec_, 3);        panel.add(text, c);        hashText_.put("sec", text);        panel.add(new JLabel(" second"), c);        /////////////////////////        // Display the delay        c.gridy = index++;        c.ipadx = 0;        JLabel label4 = new JLabel("Successive experiment delay: ");        label4.setFont(font);        panel.add(label4, c);        text = new JTextField("" + delay_, 4);        panel.add(text, c);        hashText_.put("delay", text);        panel.add(new JLabel("second"), c);        ////////////        c.gridy = index++;        JLabel label = new JLabel("Scheduling strategy:");        label.setFont(font);        panel.add(label, c);        // Create a combo box        combo_ = new JComboBox(comboValue_);        combo_.setSelectedIndex(comboPolicy_);  // default value is Random        c.gridwidth = 4;        panel.add(combo_, c);        //////////////        c.weighty = 1.0;   //request any extra vertical space        c.gridy = index++;

⌨️ 快捷键说明

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