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

📄 resourceproperty.java

📁 实现网格环境下资源调度和分配的仿真
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
     * @pre nodeList != null     * @post $none     */    public void loadXml(final NodeList nodeList) throws Exception    {        //hasLoadXml_ = true;        Node node;        String name, value;        final int LOAD = 10;        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("peakLoad") == true)            {                value = node.getFirstChild().getNodeValue();                // must trim the String otherwise get an exception                double num = Double.parseDouble(value.trim());                peakLoad_ = (int) (num * LOAD);            }            else if (name.equals("offPeakLoad") == true)            {                value = node.getFirstChild().getNodeValue();                // must trim the String otherwise get an exception                double num = Double.parseDouble(value.trim());                offLoad_ = (int) (num * LOAD);            }            else if (name.equals("holidayLoad") == true)            {                value = node.getFirstChild().getNodeValue();                // must trim the String otherwise get an exception                double num = Double.parseDouble(value.trim());                holidayLoad_ = (int) (num * LOAD);            }            else if (name.equals("resourceCharacteristics") == true)            {                // make another method to handle resource characteristics                loadXmlResourceCharacteristics( 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 ///////////////////////////    /**      * Creates a new grid resource with default values for its properties     * @pre $none     * @post $none     */    private void defaultValue()    {        peakLoad_ = 0;        offLoad_ = 0;        holidayLoad_ = 0;        baudRate_ = 100.0;        price_ = 100.0;        timeZone_ = 0;        comboPolicy_ = 0;        arch_ = "Intel";        os_ = "Red Hat Linux";        // create default machine        machine_.add(new ResourceMachine(0, false, null));        machineName_.add("Machine 0");        machine_.add(new ResourceMachine(1, false, null));        machineName_.add("Machine 1");    }    /**      * Creates grid resource properties with random values     * @param r   a Random object     * @pre r != null     * @post $none     */    private void randomValue(Random r)    {        int RANGE = 11;        // must multiply by 10 since the value of nextDouble() is [0, 0.99999]        baudRate_ = r.nextInt(1001);        // set into the range [0, 11), i.e. 0-10 not 11        peakLoad_ = r.nextInt(RANGE);        offLoad_ = r.nextInt(RANGE);        holidayLoad_ = r.nextInt(RANGE);        // there are only 2 options, but the index starts at 0        comboPolicy_ = r.nextInt(2);        // TODO: GMT +13 and -12, but below is always postive value        timeZone_ = r.nextInt(RANGE);        price_ = r.nextDouble() * 100;        int index = 0;        int MAX = 4;        String[][] list = {                 {"Compaq AlphaServer",  "OSF1"},    {"Sun Ultra", "Solaris"},                {"Intel Pentium", "Linux"},         {"SGI Origin", "Irix"}        };        index = r.nextInt(MAX);        arch_ = list[index][0];        os_   = list[index][1];                // create machines        index = r.nextInt(RANGE);        // machine must have at least two CPU or gridlet        if (index < 1) {            index = r.nextInt(RANGE);        }                for (int i = 0; i < index; i++)        {            machine_.add(new ResourceMachine(i, true, r));            machineName_.add("Machine " + i);        }    }    /**      * Initializes all the dialog components     * @pre $none     * @post $none     */    private void initComponents()    {        GridBagLayout gridbag = new GridBagLayout();        GridBagConstraints c = new GridBagConstraints();        JPanel panel = new JPanel(gridbag);        c.insets = new Insets(5, 3, 5, 3);        Font font = new Font(null, Font.PLAIN, 14);        int index = 0;        c.weighty = 0.5;        c.fill = GridBagConstraints.HORIZONTAL;        c.gridy = index++;        //////////////////        // Display the user name        JLabel label = new JLabel("Resource Name:");        label.setFont(font);        panel.add(label, c);        c.gridwidth = GridBagConstraints.REMAINDER;        resText_ = new JTextField(name_, 20);        panel.add(resText_, c);        ////////////////////        // Display the baud rate        c.gridwidth = 1;        c.gridy = index++;        label = new JLabel("Baud Rate:");        label.setFont(font);        panel.add(label, c);        baudText_ = new JTextField("" + baudRate_, 5);        panel.add(baudText_, c);        ///////////////////////        // Create a label to display the slider default value        c.gridy = index++;        c.weighty = 0.5;        c.fill = GridBagConstraints.HORIZONTAL;        double num = peakLoad_ / 10.0;        peakLabel_ = new JLabel("Peak Load:   " + num);        peakLabel_.setFont(font);        panel.add(peakLabel_, c);        // Create the slider with min value, max value and init value        peakSlider_ = new JSlider(0, 10, peakLoad_);        createSlider(panel, c, peakSlider_);        // Create a label to display the slider default value        c.gridy = index++;        num = offLoad_ / 10.0;        offLabel_ = new JLabel("Off-peak Load:   " + num);        offLabel_.setFont(font);        panel.add(offLabel_, c);        // Create the slider with min value, max value and init value        offSlider_ = new JSlider(0, 10, offLoad_);        createSlider(panel, c, offSlider_);        // Create a label to display the slider default value        c.gridy = index++;        num = holidayLoad_ / 10.0;        holidayLabel_ = new JLabel("Holiday Load:   " + num);        holidayLabel_.setFont(font);        panel.add(holidayLabel_, c);        // Create the slider with min value, max value and init value        holidaySlider_ = new JSlider(0, 10, holidayLoad_);        createSlider(panel, c, holidaySlider_);        //////////////////////////////////        // Add another panel for Resource Characteristics        charPanel_ = new JPanel(gridbag);        c.weighty = 1.0;   //request any extra vertical space        c.gridy = index++;        c.insets = new Insets(25, 0, 10, 0);  //top & bottom padding        c.gridwidth = GridBagConstraints.REMAINDER;        c.fill = GridBagConstraints.BOTH;        panel.add(charPanel_, c);        // Create another panel that contains an experiment value        initCharacteristic();        // Create an OK button        index += 2;        c.gridy = index++;        c.gridx = 1;        c.gridwidth = 1;        c.fill = GridBagConstraints.NONE;        ok_ = new JButton("OK");        panel.add(ok_, c);        // Create a Cancel button        c.gridwidth = GridBagConstraints.REMAINDER;        cancel_ = new JButton("Cancel");        panel.add(cancel_, c);        // Add panel to a scroll pane        int vert = ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED;        int horiz = ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED;        JScrollPane scroll = new JScrollPane(panel, vert, horiz);        getContentPane().add(scroll);    }    /**      * Initializes all components regarding to resouce characteristic      * properties     * @pre $none     * @post $none     */    private void initCharacteristic()    {        GridBagConstraints c = new GridBagConstraints();        c.insets = new Insets(10, 5, 5, 15);  // top - left - bottom - right        Font font = new Font(null, Font.PLAIN, 12);        TitledBorder title = BorderFactory.createTitledBorder("Characteristic");        title.setTitleFont(font.deriveFont(Font.BOLD, 18));        charPanel_.setBorder(title);        // init all the values        int index = 0;        c.weighty = 0.5;        c.fill = GridBagConstraints.HORIZONTAL;        // Display the architecture name        c.gridy = index++;        JLabel label = new JLabel("Architecture:");        label.setFont(font);        charPanel_.add(label, c);        c.gridwidth = GridBagConstraints.REMAINDER;        archText_ = new JTextField(arch_, 20);        charPanel_.add(archText_, c);        ////////////////////        // Display the OS        c.gridwidth = 1;        c.gridy = index++;        label = new JLabel("Operating System:");        label.setFont(font);        charPanel_.add(label, c);        //c.gridwidth = GridBagConstraints.REMAINDER;        osText_ = new JTextField(os_, 20);        charPanel_.add(osText_, c);        ////////////////////        // Display the time zone        c.gridwidth = 1;        c.gridy = index++;        label = new JLabel("Time Zone (GMT) :");        label.setFont(font);        charPanel_.add(label, c);        timeZoneText_ = new JTextField("" + timeZone_, 5);        charPanel_.add(timeZoneText_, c);        ////////////////////        // Display the cost per sec        c.gridwidth = 1;        c.gridy = index++;        label = new JLabel("Grid $ / application operation:  ");        label.setFont(font);        charPanel_.add(label, c);        priceText_ = new JTextField("" + price_, 5);        charPanel_.add(priceText_, c);        /////////////////        c.gridy = index++;        label = new JLabel("Allocation policy:");        label.setFont(font);        charPanel_.add(label, c);        // Create a combo box        combo_ = new JComboBox(comboValue_);        combo_.setSelectedIndex(comboPolicy_);  // default value is Random        c.gridwidth = GridBagConstraints.REMAINDER;        charPanel_.add(combo_, c);

⌨️ 快捷键说明

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