From: <mar...@us...> - 2007-10-19 00:52:09
|
Revision: 75 http://gridsim.svn.sourceforge.net/gridsim/?rev=75&view=rev Author: marcos_dias Date: 2007-10-18 17:52:11 -0700 (Thu, 18 Oct 2007) Log Message: ----------- This update is to allow the user to change the default Graphical User Interface used by GridSim and provide his/her own. Modified Paths: -------------- branches/gridsim4.0-branch3/source/gridsim/AllocPolicy.java branches/gridsim4.0-branch3/source/gridsim/GridSim.java branches/gridsim4.0-branch3/source/gridsim/gui/ResourceWindow.java branches/gridsim4.0-branch3/source/gridsim/turbo/ARParallelSpaceShared.java branches/gridsim4.0-branch3/source/gridsim/turbo/ParallelSpaceShared.java branches/gridsim4.0-branch3/source/gridsim/turbo/SSGridlet.java branches/gridsim4.0-branch3/source/gridsim/turbo/SSReservation.java branches/gridsim4.0-branch3/source/gridsim/turbo/ScheduleItem.java Added Paths: ----------- branches/gridsim4.0-branch3/source/gridsim/gui/DefaultGridSimVisualizer.java branches/gridsim4.0-branch3/source/gridsim/gui/GridSimVisualizer.java Modified: branches/gridsim4.0-branch3/source/gridsim/AllocPolicy.java =================================================================== --- branches/gridsim4.0-branch3/source/gridsim/AllocPolicy.java 2007-10-19 00:51:28 UTC (rev 74) +++ branches/gridsim4.0-branch3/source/gridsim/AllocPolicy.java 2007-10-19 00:52:11 UTC (rev 75) @@ -16,7 +16,7 @@ import eduni.simjava.Sim_event; import eduni.simjava.Sim_port; import gridsim.gui.AllocationAction; -import gridsim.gui.GridSimVisualizer; +import gridsim.gui.DefaultGridSimVisualizer; import gridsim.turbo.ScheduleItem; /** @@ -671,88 +671,5 @@ super.sim_schedule(myId_, time, tag, data); return true; } - - /** - * Notifies the listeners about the action performed - * @param allocationAction the action performed - * @param shouldPause indicates whether the simulation should be paused after - * notifying the listeners. <tt>true</tt> indicates that it should pause and - * <tt>false</tt> means that it should not. - * @param itemList the list of gridlets to provide to the listeners - * - * @see AllocationAction#ITEM_ARRIVED - * @see AllocationAction#ITEM_SCHEDULED - * @see AllocationAction#ITEM_CANCELLED - * @see AllocationAction#ITEM_COMPLETED - * @see AllocationAction#ITEM_STATUS_CHANGED - * @see AllocationAction#SCHEDULE_CHANGED - */ - protected void notifyListeners(int allocationAction, - boolean shouldPause, LinkedList itemList) { - - if(!GridSim.isDebugModeEnabled()) - return; - - AllocationAction action = new AllocationAction(allocationAction); - action.setSubject(this.get_id()); - action.setScheduleItems(itemList); - GridSimVisualizer.notifyListeners(action, shouldPause); - } - - /** - * Notifies the listeners about the action performed - * @param allocationAction the action performed - * @param shouldPause indicates whether the simulation should be paused after - * notifying the listeners. <tt>true</tt> indicates that it should pause and - * <tt>false</tt> means that it should not. - * @param item the gridlet to provide to the listeners - * - * @see AllocationAction#ITEM_ARRIVED - * @see AllocationAction#ITEM_SCHEDULED - * @see AllocationAction#ITEM_CANCELLED - * @see AllocationAction#ITEM_COMPLETED - * @see AllocationAction#ITEM_STATUS_CHANGED - * @see AllocationAction#SCHEDULE_CHANGED - */ - protected void notifyListeners(int allocationAction, boolean shouldPause, - ScheduleItem item) { - - if(!GridSim.isDebugModeEnabled()) - return; - - LinkedList<ScheduleItem> itemList = null; - if(item != null) { - itemList = new LinkedList<ScheduleItem>(); - itemList.add(item); - } - - notifyListeners(allocationAction, shouldPause, itemList); - } - - /** - * Notifies the listeners about the action performed - * @param allocationAction the action performed - * @param shouldPause indicates whether the simulation should be paused after - * notifying the listeners. <tt>true</tt> indicates that it should pause and - * <tt>false</tt> means that it should not. - * @param gridlet the gridlet to provide to the listeners - * - * @see AllocationAction#ITEM_ARRIVED - * @see AllocationAction#ITEM_SCHEDULED - * @see AllocationAction#ITEM_CANCELLED - * @see AllocationAction#ITEM_COMPLETED - * @see AllocationAction#ITEM_STATUS_CHANGED - * @see AllocationAction#SCHEDULE_CHANGED - */ - protected void notifyListeners(int allocationAction, boolean shouldPause) { - - if(!GridSim.isDebugModeEnabled()) - return; - - AllocationAction action = new AllocationAction(allocationAction); - action.setSubject(this.get_id()); - GridSimVisualizer.notifyListeners(action, shouldPause); - } - } // end class Modified: branches/gridsim4.0-branch3/source/gridsim/GridSim.java =================================================================== --- branches/gridsim4.0-branch3/source/gridsim/GridSim.java 2007-10-19 00:51:28 UTC (rev 74) +++ branches/gridsim4.0-branch3/source/gridsim/GridSim.java 2007-10-19 00:52:11 UTC (rev 75) @@ -17,8 +17,12 @@ import eduni.simjava.Sim_type_p; import gridsim.filter.FilterGridlet; import gridsim.filter.FilterResult; +import gridsim.gui.AllocationAction; +import gridsim.gui.AllocationListener; +import gridsim.gui.DefaultGridSimVisualizer; import gridsim.gui.GridSimVisualizer; import gridsim.net.Link; +import gridsim.turbo.ScheduleItem; import java.util.ArrayList; import java.util.Calendar; @@ -88,7 +92,8 @@ public static boolean debugMode_ = true; public static boolean slowMotionMode_ = false; public static boolean stepByStepMode_ = false; - + private static GridSimVisualizer visualizer_ = null; + /////////////////////////// STATIC variables //////////////////// /** @@ -448,7 +453,8 @@ } } - // METHODS TO SET THE SIMULATION MODES + // METHODS TO SET THE SIMULATION MODES AND NOTIFY THE GRAPHICAL + // USER INTERFACE ELEMENTS ABOUT ALLOCATION ACTIONS /** * Enables the debug mode (used by the GUI) @@ -509,8 +515,115 @@ public static void disableStepByStepMode() { stepByStepMode_ = false; } + + /** + * Sets the visualizer to be used by GridSim when the + * debug mode of simulation is enabled + * @param visualizer an object that implements {@link GridSimVisualizer} + * and is able to forward the allocation actions to the + * corresponding listeners + * @throws Exception is thrown if this method is called after the simulation + * has started. + */ + public static void setGridSimVisualizer(GridSimVisualizer visualizer) + throws Exception{ + + if(Sim_system.running()) { + throw new Exception("GridSim.setGridSimVisualizer(): Exception, it " + + "is not possible to change the visualizer once the simulation is running"); + } + else { + visualizer_ = visualizer; + } + } /** + * Notifies the listeners about the action performed + * @param subjectId the subject, or entity, that created the action + * @param allocationAction the action performed + * @param shouldPause indicates whether the simulation should be paused after + * notifying the listeners. <tt>true</tt> indicates that it should pause and + * <tt>false</tt> means that it should not. + * @param itemList the list of gridlets to provide to the listeners + * + * @see AllocationAction#ITEM_ARRIVED + * @see AllocationAction#ITEM_SCHEDULED + * @see AllocationAction#ITEM_CANCELLED + * @see AllocationAction#ITEM_COMPLETED + * @see AllocationAction#ITEM_STATUS_CHANGED + * @see AllocationAction#SCHEDULE_CHANGED + */ + public static void notifyListeners(int subjectId, int allocationAction, + boolean shouldPause, LinkedList itemList) { + + if(!GridSim.isDebugModeEnabled()) + return; + + AllocationAction action = new AllocationAction(allocationAction); + action.setSubject(subjectId); + action.setScheduleItems(itemList); + visualizer_.notifyListeners(action, shouldPause); + } + + /** + * Notifies the listeners about the action performed + * @param subjectId the subject, or entity, that created the action + * @param allocationAction the action performed + * @param shouldPause indicates whether the simulation should be paused after + * notifying the listeners. <tt>true</tt> indicates that it should pause and + * <tt>false</tt> means that it should not. + * @param item the gridlet to provide to the listeners + * + * @see AllocationAction#ITEM_ARRIVED + * @see AllocationAction#ITEM_SCHEDULED + * @see AllocationAction#ITEM_CANCELLED + * @see AllocationAction#ITEM_COMPLETED + * @see AllocationAction#ITEM_STATUS_CHANGED + * @see AllocationAction#SCHEDULE_CHANGED + */ + public static void notifyListeners(int subjectId, int allocationAction, + boolean shouldPause, ScheduleItem item) { + + if(!GridSim.isDebugModeEnabled()) + return; + + LinkedList<ScheduleItem> itemList = null; + if(item != null) { + itemList = new LinkedList<ScheduleItem>(); + itemList.add(item); + } + + notifyListeners(subjectId, allocationAction, shouldPause, itemList); + } + + /** + * Notifies the listeners about the action performed + * @param subjectId the subject, or entity, that created the action + * @param allocationAction the action performed + * @param shouldPause indicates whether the simulation should be paused after + * notifying the listeners. <tt>true</tt> indicates that it should pause and + * <tt>false</tt> means that it should not. + * @param gridlet the gridlet to provide to the listeners + * + * @see AllocationAction#ITEM_ARRIVED + * @see AllocationAction#ITEM_SCHEDULED + * @see AllocationAction#ITEM_CANCELLED + * @see AllocationAction#ITEM_COMPLETED + * @see AllocationAction#ITEM_STATUS_CHANGED + * @see AllocationAction#SCHEDULE_CHANGED + */ + public static void notifyListeners(int subjectId, int allocationAction, + boolean shouldPause) { + + if(!GridSim.isDebugModeEnabled()) + return; + + AllocationAction action = new AllocationAction(allocationAction); + action.setSubject(subjectId); + visualizer_.notifyListeners(action, shouldPause); + } + + /** * Returns <tt>true</tt> if the step by step mode is enabled * @return <tt>true</tt> if the step by step mode is enabled; * <tt>false<tt> otherwise @@ -623,32 +736,17 @@ public static void startGridSimulation(boolean debug) throws NullPointerException { System.out.println("Starting GridSim " + GRIDSIM_VERSION_STRING); - if(!debug){ + if(!debug) { startGridSimulation(); } - else{ + else { enableDebugMode(); disableSlowMotionMode(); disableStepByStepMode(); - // get a list of resource created by the user in order to pass - // it to the visualisation tool - ArrayList<GridResource> resources = new ArrayList<GridResource>(); - LinkedList<Sim_entity> entities = Sim_system.getEntityList(); - for(Sim_entity entity : entities){ - if(entity instanceof GridResource){ - resources.add((GridResource)entity); - } - } - try { - // create the visualisation tool - GridSimVisualizer visualizer = new GridSimVisualizer(resources); - visualizer.setVisible(true); - } - catch (ParameterException e) { - throw new NullPointerException("GridSim.startGridSimulation() :" + - " Error - the visualiser could not be initialised."); - } + // create the visualisation tool + if(visualizer_ == null) + visualizer_ = new DefaultGridSimVisualizer(); } } Copied: branches/gridsim4.0-branch3/source/gridsim/gui/DefaultGridSimVisualizer.java (from rev 73, branches/gridsim4.0-branch3/source/gridsim/gui/GridSimVisualizer.java) =================================================================== --- branches/gridsim4.0-branch3/source/gridsim/gui/DefaultGridSimVisualizer.java (rev 0) +++ branches/gridsim4.0-branch3/source/gridsim/gui/DefaultGridSimVisualizer.java 2007-10-19 00:52:11 UTC (rev 75) @@ -0,0 +1,415 @@ +/******************************************************************************* + * Copyright (C) 2005-2007 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + * + *****************************************************************************/ +package gridsim.gui; + +import eduni.simjava.Sim_entity; +import eduni.simjava.Sim_system; +import gridsim.GridResource; +import gridsim.GridSim; +import gridsim.ResourceCharacteristics; + +import java.awt.BorderLayout; +import java.awt.GridLayout; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Iterator; +import java.util.LinkedHashMap; +import java.util.LinkedList; + +import javax.swing.BorderFactory; +import javax.swing.DefaultListModel; +import javax.swing.JButton; +import javax.swing.JFrame; +import javax.swing.JList; +import javax.swing.JMenu; +import javax.swing.JMenuBar; +import javax.swing.JMenuItem; +import javax.swing.JPanel; +import javax.swing.JScrollPane; +import javax.swing.border.Border; +import javax.swing.border.EtchedBorder; +import javax.swing.border.TitledBorder; +import javax.swing.event.ListSelectionEvent; +import javax.swing.event.ListSelectionListener; + +/** + * {@link GridSimVisualiser} is the class that represents the main window. + * used by the visualisation tool. From this window it is possible to + * start the simulation, run step by step or run it in slow motion. <br> + * <b>NOTE:</b> This visualisation tool should be used for debugging + * purposes only. It is useful if you want to evaluate a new allocation + * policy for example. A real experiment is not meant to have any + * visualisation features. This interface was initially created for + * another simulator called PajFit available at <b>http://pajfit.sourceforge.net/</b>. + * + * @author Marco A. S. Netto (created this visualisation tool) + * @author Marcos Dias de Assuncao (modified this class to be + * used by GridSim.) + * @since GridSim Turbo Alpha 0.1 + * + * @see gridsim.GridSim#startGridSimulation(boolean) + * @see gridsim.GridSim#startGridSimulation() + * @see gridsim.turbo.ParallelSpaceShared + * @see gridsim.turbo.ARTParallelSpaceShared + */ +public class DefaultGridSimVisualizer extends JFrame + implements ActionListener, ListSelectionListener, GridSimVisualizer { + + private static final long serialVersionUID = 2059324063853260682L; + public static final int WINDOW_WIDTH = 400; + public static final int WINDOW_HEIGHT = 350; + + private JButton stepButton_; + private JButton runButton_; + private JButton slowMotionButton_; + private JList resourceJList_; + private JList resourceInfoJList_; + + // the thread responsible for starting the simulation. This is needed + // because we do not want to buttons to remain blocked during the whole + // simulation process + private Thread simThread_; + + // indicates whether this is the first time the user + // is clicking a button of the graphical user interface + private boolean firstButtonClick_; + + // a table containing references to the resource windows. That is, + // each resource has a window that displays the content of the + // scheduling queue and the allocation actions performed + private HashMap<String, ResourceWindow> resourceWindows_ = null; + private ArrayList<GridResource> resources_ = null; + + // a list of all the allocation listeners in the system + private static LinkedHashMap<Integer, AllocationListener> listeners_; + + // constants to indicate the time unit to be used for displaying + // information + public static final int TIME_UNIT_SECOND = 0; + public static final int TIME_UNIT_MINUTE = 1; + public static final int TIME_UNIT_HOUR = 2; + + static { + listeners_ = new LinkedHashMap<Integer, AllocationListener>(); + } + + /** + * Creates the main window of the visualiser. + */ + public DefaultGridSimVisualizer() { + + // get a list of resource created by the user in order to pass + // it to the visualisation tool + resources_ = new ArrayList<GridResource>(); + LinkedList<Sim_entity> entities = Sim_system.getEntityList(); + for(Sim_entity entity : entities){ + if(entity instanceof GridResource){ + resources_.add((GridResource)entity); + } + } + + resourceWindows_ = new HashMap<String,ResourceWindow>(); + initResourceWindows(); + + super.setSize(WINDOW_WIDTH, WINDOW_HEIGHT); + super.setLocation(10, 10); + super.setTitle("GridSim Turbo Alpha 0.1 Visualizer"); + + JPanel mainPanel = new JPanel(new GridLayout(0, 1)); + JPanel simulationPanel = new JPanel(new GridLayout(0, 2)); + + Border simulationBorder = BorderFactory.createTitledBorder( + BorderFactory.createEtchedBorder(EtchedBorder.RAISED), "Simulation"); + simulationPanel.setBorder(simulationBorder); + + JPanel executionPanel = new JPanel(new GridLayout(3,0)); + executionPanel.setBorder(new TitledBorder("Execution")); + + stepButton_ = new JButton("Step"); + runButton_ = new JButton("Run"); + slowMotionButton_ = new JButton("Slow Motion"); + + stepButton_.addActionListener(this); + runButton_.addActionListener(this); + slowMotionButton_.addActionListener(this); + + executionPanel.add(stepButton_); + executionPanel.add(runButton_); + executionPanel.add(slowMotionButton_); + + ArrayList<String> resourceNames = new ArrayList<String>(); + for(GridResource resource : resources_){ + resourceNames.add(resource.get_name()); + } + + resourceJList_ = new JList(); + resourceJList_.setListData(resourceNames.toArray()); + resourceJList_.setBackground(this.getBackground()); + resourceJList_.addListSelectionListener(this); + + JPanel resourcePanel = new JPanel(new GridLayout(0, 1)); + resourcePanel.setBorder(new TitledBorder("Resources")); + JScrollPane scrollResourcePanel = new JScrollPane(resourceJList_); + resourcePanel.add(scrollResourcePanel); + + simulationPanel.add(executionPanel); + simulationPanel.add(resourcePanel); + + resourceInfoJList_ = new JList(); + resourceInfoJList_.setBackground(this.getBackground()); + + JPanel resourceInfoPanel = new JPanel(new GridLayout(0, 1)); + resourceInfoPanel.setBorder(new TitledBorder("Resource Details")); + resourceInfoPanel.add(resourceInfoJList_); + + Border resourceInfoBorder = BorderFactory.createTitledBorder( + BorderFactory.createEtchedBorder(EtchedBorder.RAISED), "Resource Details"); + resourceInfoPanel.setBorder(resourceInfoBorder); + + mainPanel.add(simulationPanel); + mainPanel.add(resourceInfoPanel); + + createMenuBar(); + firstButtonClick_ = true; + + super.setLocation(0, 0); + super.getContentPane().add(mainPanel, BorderLayout.CENTER); + super.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + + // Creates a thread that will be responsible for starting the simulation + // I don't want to block the buttons during the whole simulation because + // they will be required for other things + simThread_ = new Thread(){ + public void run(){ + // here in fact, start the simulation + GridSim.startGridSimulation(); + } + }; + + super.setVisible(true); + } + + // ------------------------- PUBLIC METHODS ------------------------- + + /** + * Notifies a listener about the action performed + * @param action the action performed + * @param shouldPause indicates whether the simulation should be paused after + * notifying the listener. <tt>true</tt> indicates that it should pause and + * <tt>false</tt> means that it should not. + * @see AllocationAction#ITEM_ARRIVED + * @see AllocationAction#ITEM_SCHEDULED + * @see AllocationAction#ITEM_CANCELLED + * @see AllocationAction#ITEM_COMPLETED + * @see AllocationAction#ITEM_STATUS_CHANGED + * @see AllocationAction#SCHEDULE_CHANGED + */ + public void notifyListeners(AllocationAction action, boolean shouldPause) { + AllocationListener listener = listeners_.get(action.getSubject()); + if(listener != null) { + listener.allocationActionPerformed(action); + informListenersAboutTime(); + + if(shouldPause){ + if(GridSim.isStepByStepEnabled()){ + GridSim.pauseSimulation(); + } + else if(GridSim.isSlowMotionModeEnabled()){ + GridSim.smallPause(); + } + } + } + } + + /** + * Adds a listener to the list of listeners interested in the events + * generated by a given entity + * @param entityId the id of the entity in which the listener is interested + * @param listener the listener to be registered + * @return <tt>true</tt> if success or <tt>false</tt> otherwise + */ + public static boolean addAllocationListener(int entityId, + AllocationListener listener) { + if(listeners_.containsKey(entityId)) + return false; + + listeners_.put(entityId, listener); + return true; + } + + /** + * Unregisters a listener from the list of listeners + * @param listener the listener to be unregistered + * @return <tt>true</tt> if success or <tt>false</tt> otherwise + */ + public static boolean removeAllocationListener(AllocationListener listener) { + if(!listeners_.containsValue(listener)){ + return false; + } + listeners_.remove(listener); + return true; + } + + /** + * Handles events triggered by the list of resource + */ + public void valueChanged(ListSelectionEvent ev) { + String selectedResource = (String) resourceJList_.getSelectedValue(); + updateResourceDetails(selectedResource); + } + + /** + * Handles the option that the user selected. + */ + public void actionPerformed(ActionEvent e){ + String cmd = e.getActionCommand(); + + if(cmd.equals("Step")){ + GridSim.enableStepByStepMode(); + GridSim.disableSlowMotionMode(); + + checkFirstClick(); + GridSim.resumeSimulation(); + } + else if(cmd.equals("Run")){ + GridSim.disableStepByStepMode(); + GridSim.disableSlowMotionMode(); + + if(!checkFirstClick()) { + GridSim.resumeSimulation(); + } + } + else if(cmd.equals("Slow Motion")){ + GridSim.disableStepByStepMode(); + GridSim.enableSlowMotionMode(); + + if(!checkFirstClick()) { + GridSim.resumeSimulation(); + } + } + else if(cmd.equals("Exit") ){ + System.exit(0); + } + else { + String resourceName = cmd; + ResourceWindow window = resourceWindows_.get(resourceName); + window.setVisible(true); + } + } + + // ------------------------- PRIVATE METHODS ------------------------- + + /** + * Informs all the listeners about the change in the + * simulation time + */ + private static void informListenersAboutTime() { + Iterator<AllocationListener> iterListener = listeners_.values().iterator(); + while(iterListener.hasNext()) { + AllocationListener listener = iterListener.next(); + AllocationAction action = + new AllocationAction(AllocationAction.SIMULATION_TIME_CHANGED); + listener.allocationActionPerformed(action); + } + } + + /** + * This method initialises the resource windows + */ + private void initResourceWindows() { + int windowId = 0; + for(GridResource resource : resources_){ + GridResource tresource = (GridResource)resource; + ResourceWindow window = new ResourceWindow(resource, windowId); + resourceWindows_.put(resource.get_name(), window); + + // registers the window as an allocation listener + // of the allocation policy. This means that the window will be + // notified of the allocation actions performed by the resource + // allocation policy + listeners_.put(tresource.getAllocationPolicy().get_id(), window); + windowId++; + } + } + + /** + * Creates the menu bar of the main window + */ + private void createMenuBar() { + JMenuBar menuBar = new JMenuBar(); + JMenu menuCommand = new JMenu("Start"); + JMenuItem item; + + for(GridResource rs : resources_){ + item = new JMenuItem(rs.get_name()); + item.addActionListener(this); + menuCommand.add(item); + } + + menuCommand.addSeparator(); + item = new JMenuItem("Exit"); + item.addActionListener(this); + menuCommand.add(item); + menuBar.add(menuCommand); + setJMenuBar(menuBar); + } + + /** + * This method checks whether this is the first time that a + * button is clicked. If so, then the simulation has to be + * started. + * @return <tt>true</tt> if it was the first click or + * <tt>false</tt> otherwise. + */ + private boolean checkFirstClick() { + if(firstButtonClick_){ + firstButtonClick_ = false; + simThread_.start(); + return true; + } + return false; + } + + /** + * Updates the details about the resource + */ + private void updateResourceDetails(String resourceName) { + GridResource resource = null; + Iterator<GridResource> iterResources = resources_.iterator(); + while(iterResources.hasNext()) { + resource = iterResources.next(); + if(resource.get_name().equals(resourceName)) + break; + } + + if(resource == null) + return; + + DefaultListModel model = new DefaultListModel(); + ResourceCharacteristics charact = resource.getResourceCharacteristics(); + model.addElement("Resource ID: " + charact.getResourceID()); + model.addElement("Number of PEs: " + charact.getNumPE()); + model.addElement("Allocation Policy: " + charact.getResourceAllocationPolicyName()); + model.addElement("Time Zone: " + charact.getResourceTimeZone()); + model.addElement("Rating per PE: " + charact.getMIPSRatingOfOnePE() + " MIPS"); + resourceInfoJList_.setModel(model); + } +} Added: branches/gridsim4.0-branch3/source/gridsim/gui/GridSimVisualizer.java =================================================================== --- branches/gridsim4.0-branch3/source/gridsim/gui/GridSimVisualizer.java (rev 0) +++ branches/gridsim4.0-branch3/source/gridsim/gui/GridSimVisualizer.java 2007-10-19 00:52:11 UTC (rev 75) @@ -0,0 +1,26 @@ +/* + * Title: GridSim Toolkit + * 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 + */ + +package gridsim.gui; + +public interface GridSimVisualizer { + + /** + * Notifies a listener about the action performed + * @param action the action performed + * @param shouldPause indicates whether the simulation should be paused after + * notifying the listener. <tt>true</tt> indicates that it should pause and + * <tt>false</tt> means that it should not. + * @see AllocationAction#ITEM_ARRIVED + * @see AllocationAction#ITEM_SCHEDULED + * @see AllocationAction#ITEM_CANCELLED + * @see AllocationAction#ITEM_COMPLETED + * @see AllocationAction#ITEM_STATUS_CHANGED + * @see AllocationAction#SCHEDULE_CHANGED + */ + void notifyListeners(AllocationAction action, boolean shouldPause); +} Modified: branches/gridsim4.0-branch3/source/gridsim/gui/ResourceWindow.java =================================================================== --- branches/gridsim4.0-branch3/source/gridsim/gui/ResourceWindow.java 2007-10-19 00:51:28 UTC (rev 74) +++ branches/gridsim4.0-branch3/source/gridsim/gui/ResourceWindow.java 2007-10-19 00:52:11 UTC (rev 75) @@ -155,7 +155,7 @@ super.setSize(WINDOW_WIDTH, WINDOW_HEIGHT); drawID_ = true; - timeUnit_ = GridSimVisualizer.TIME_UNIT_SECOND; + timeUnit_ = DefaultGridSimVisualizer.TIME_UNIT_SECOND; // initialises the list of Gridlets scheduledItems_ = new ArrayList<ScheduleItem>(); @@ -164,7 +164,7 @@ initPanels(); super.addComponentListener(new ResizeFrame(this)); - super.setLocation(GridSimVisualizer.WINDOW_WIDTH, windowId * 200); + super.setLocation(DefaultGridSimVisualizer.WINDOW_WIDTH, windowId * 200); super.setTitle("Resource Information Window - " + resource_.getResourceCharacteristics().getResourceName()); } @@ -235,19 +235,19 @@ public void actionPerformed(ActionEvent e) { if (e.getSource() == secondButton_) { if(secondButton_.isSelected()) { - timeUnit_ = GridSimVisualizer.TIME_UNIT_SECOND; + timeUnit_ = DefaultGridSimVisualizer.TIME_UNIT_SECOND; itemPanel_.updatePanel(); } } else if (e.getSource() == minuteButton_) { if(minuteButton_.isSelected()) { - timeUnit_ = GridSimVisualizer.TIME_UNIT_MINUTE; + timeUnit_ = DefaultGridSimVisualizer.TIME_UNIT_MINUTE; itemPanel_.updatePanel(); } } else if (e.getSource() == hourButton_) { if(hourButton_.isSelected()) { - timeUnit_ = GridSimVisualizer.TIME_UNIT_HOUR; + timeUnit_ = DefaultGridSimVisualizer.TIME_UNIT_HOUR; itemPanel_.updatePanel(); } } @@ -402,10 +402,10 @@ * @return the time in the unit in use */ private double convertToUnitInUse(double time) { - if(timeUnit_ == GridSimVisualizer.TIME_UNIT_SECOND) { + if(timeUnit_ == DefaultGridSimVisualizer.TIME_UNIT_SECOND) { return time; } - else if(timeUnit_ == GridSimVisualizer.TIME_UNIT_MINUTE) { + else if(timeUnit_ == DefaultGridSimVisualizer.TIME_UNIT_MINUTE) { return time/60; } else { Modified: branches/gridsim4.0-branch3/source/gridsim/turbo/ARParallelSpaceShared.java =================================================================== --- branches/gridsim4.0-branch3/source/gridsim/turbo/ARParallelSpaceShared.java 2007-10-19 00:51:28 UTC (rev 74) +++ branches/gridsim4.0-branch3/source/gridsim/turbo/ARParallelSpaceShared.java 2007-10-19 00:52:11 UTC (rev 75) @@ -308,7 +308,7 @@ //-------------- FOR DEBUGGING PURPOSES ONLY -------------- // informs the listeners that a reservation request has arrived - super.notifyListeners(AllocationAction.ITEM_ARRIVED, true, sRes); + GridSim.notifyListeners(this.get_id(), AllocationAction.ITEM_ARRIVED, true, sRes); //---------------------------------------------------------- @@ -455,7 +455,7 @@ //-------------- FOR DEBUGGING PURPOSES ONLY -------------- // Informs the listeners about the reservation that has been created - super.notifyListeners(AllocationAction.ITEM_SCHEDULED, true, sRes); + GridSim.notifyListeners(this.get_id(), AllocationAction.ITEM_SCHEDULED, true, sRes); //---------------------------------------------------------- } @@ -522,7 +522,7 @@ //----------------- USED FOR DEBUGGING PURPOSES ONLY ------------------- // If a gridlet has been cancelled, then inform the listeners - super.notifyListeners(AllocationAction.ITEM_CANCELLED, true, sRes); + GridSim.notifyListeners(this.get_id(), AllocationAction.ITEM_CANCELLED, true, sRes); //---------------------------------------------------------------------- @@ -532,7 +532,7 @@ //----------------- USED FOR DEBUGGING PURPOSES ONLY ------------------- // Inform the listeners about the new schedule - super.notifyListeners(AllocationAction.SCHEDULE_CHANGED, true); + GridSim.notifyListeners(this.get_id(), AllocationAction.SCHEDULE_CHANGED, true); //---------------------------------------------------------------------- @@ -611,7 +611,7 @@ //-------------- FOR DEBUGGING PURPOSES ONLY -------------- - super.notifyListeners(AllocationAction.ITEM_STATUS_CHANGED, true, sRes); + GridSim.notifyListeners(this.get_id(), AllocationAction.ITEM_STATUS_CHANGED, true, sRes); //---------------------------------------------------------- } @@ -829,7 +829,7 @@ //----------------- USED FOR DEBUGGING PURPOSES ONLY ------------------- // If a gridlet has been cancelled, then inform the listeners - super.notifyListeners(AllocationAction.ITEM_CANCELLED, true, sgl); + GridSim.notifyListeners(this.get_id(), AllocationAction.ITEM_CANCELLED, true, sgl); //---------------------------------------------------------------------- @@ -842,7 +842,7 @@ //------------------- USED FOR DEBUGGING PURPOSES ONLY ----------------- // Inform the listeners about the new schedule - super.notifyListeners(AllocationAction.SCHEDULE_CHANGED, true); + GridSim.notifyListeners(this.get_id(), AllocationAction.SCHEDULE_CHANGED, true); //---------------------------------------------------------------------- @@ -1009,7 +1009,7 @@ //------------------ FOR DEBUGGING PURPOSES ONLY------------------------ - super.notifyListeners(AllocationAction.ITEM_ARRIVED, true, sgl); + GridSim.notifyListeners(this.get_id(), AllocationAction.ITEM_ARRIVED, true, sgl); //---------------------------------------------------------------------- @@ -1034,7 +1034,7 @@ // Notifies the listeners that a Gridlet has been either scheduled // to run immediately or put in the waiting queue - super.notifyListeners(AllocationAction.ITEM_SCHEDULED, true, sgl); + GridSim.notifyListeners(this.get_id(), AllocationAction.ITEM_SCHEDULED, true, sgl); //--------------------------------------------------------------- @@ -1072,7 +1072,7 @@ /////////////// FOR DEBUGGING PURPOSES ONLY //////// - super.notifyListeners(AllocationAction.ITEM_ARRIVED, true, sgl); + GridSim.notifyListeners(this.get_id(), AllocationAction.ITEM_ARRIVED, true, sgl); ///////////////////////////////////////////////////// @@ -1152,7 +1152,7 @@ // Notifies the listeners that a Gridlet has been either scheduled // to run immediately or put in the waiting queue - super.notifyListeners(AllocationAction.ITEM_SCHEDULED, true, sgl); + GridSim.notifyListeners(this.get_id(), AllocationAction.ITEM_SCHEDULED, true, sgl); //--------------------------------------------------------------- @@ -1314,7 +1314,7 @@ //---------------- USED FOR DEBUGGING PURPOSES ONLY ---------------- // If a gridlet has been cancelled, then inform the listeners - super.notifyListeners(AllocationAction.ITEM_CANCELLED, + GridSim.notifyListeners(this.get_id(), AllocationAction.ITEM_CANCELLED, false, removedGridlets); //------------------------------------------------------------------ @@ -1520,7 +1520,7 @@ //-------------- USED FOR DEBUGGING PURPOSES ONLY ----------------- // If a gridlet has been cancelled, then inform the listeners - super.notifyListeners(AllocationAction.ITEM_CANCELLED, true, removedRes); + GridSim.notifyListeners(this.get_id(), AllocationAction.ITEM_CANCELLED, true, removedRes); //----------------------------------------------------------------- @@ -1537,7 +1537,7 @@ // If a gridlet has started execution or one has finished, // then inform the listeners - super.notifyListeners(AllocationAction.SCHEDULE_CHANGED, true); + GridSim.notifyListeners(this.get_id(), AllocationAction.SCHEDULE_CHANGED, true); //----------------------------------------------------------------- } @@ -1597,7 +1597,7 @@ // If a gridlet has started execution or one has finished, // then inform the listeners if(gridletStarted > 0 || gridletFinished > 0){ - super.notifyListeners(AllocationAction.ITEM_COMPLETED, + GridSim.notifyListeners(this.get_id(), AllocationAction.ITEM_COMPLETED, true, grlsCompleted); } } @@ -1648,7 +1648,7 @@ //------------- USED FOR DEBUGGING PURPOSES ONLY ------------------ // notify the listeners - super.notifyListeners(AllocationAction.ITEM_STATUS_CHANGED, + GridSim.notifyListeners(this.get_id(), AllocationAction.ITEM_STATUS_CHANGED, true, startedReservations); //------------------------------------------------------------------ @@ -1659,7 +1659,7 @@ // If a gridlet has started execution or one has finished, // then inform the listeners - super.notifyListeners(AllocationAction.SCHEDULE_CHANGED, true); + GridSim.notifyListeners(this.get_id(), AllocationAction.SCHEDULE_CHANGED, true); //------------------------------------------------------------------ } @@ -1706,7 +1706,7 @@ // If a gridlet has started execution or one has finished, // then inform the listeners - super.notifyListeners(AllocationAction.SCHEDULE_CHANGED, true); + GridSim.notifyListeners(this.get_id(), AllocationAction.SCHEDULE_CHANGED, true); //----------------------------------------------------------------- } Modified: branches/gridsim4.0-branch3/source/gridsim/turbo/ParallelSpaceShared.java =================================================================== --- branches/gridsim4.0-branch3/source/gridsim/turbo/ParallelSpaceShared.java 2007-10-19 00:51:28 UTC (rev 74) +++ branches/gridsim4.0-branch3/source/gridsim/turbo/ParallelSpaceShared.java 2007-10-19 00:52:11 UTC (rev 75) @@ -234,7 +234,7 @@ //-------------- FOR DEBUGGING PURPOSES ONLY -------------- - super.notifyListeners(AllocationAction.ITEM_ARRIVED, true, sgl); + GridSim.notifyListeners(this.get_id(), AllocationAction.ITEM_ARRIVED, true, sgl); //---------------------------------------------------------- @@ -259,7 +259,7 @@ // Notifies the listeners that a Gridlet has been either scheduled // to run immediately or put in the waiting queue - super.notifyListeners(AllocationAction.ITEM_SCHEDULED, true, sgl); + GridSim.notifyListeners(this.get_id(), AllocationAction.ITEM_SCHEDULED, true, sgl); //--------------------------------------------------------------- @@ -397,7 +397,7 @@ //----------------- USED FOR DEBUGGING PURPOSES ONLY ------------------- // If a gridlet has been cancelled, then inform the listeners about it - super.notifyListeners(AllocationAction.ITEM_CANCELLED, true, sgl); + GridSim.notifyListeners(this.get_id(), AllocationAction.ITEM_CANCELLED, true, sgl); //---------------------------------------------------------------------- @@ -407,7 +407,7 @@ //----------------- USED FOR DEBUGGING PURPOSES ONLY ------------------- // Inform the listeners about the new schedule - super.notifyListeners(AllocationAction.SCHEDULE_CHANGED, true); + GridSim.notifyListeners(this.get_id(), AllocationAction.SCHEDULE_CHANGED, true); //---------------------------------------------------------------------- @@ -959,7 +959,7 @@ // If a gridlet has started execution or one has finished, // then inform the listeners if(gridletStarted > 0 || gridletFinished > 0){ - super.notifyListeners(AllocationAction.ITEM_COMPLETED, + GridSim.notifyListeners(this.get_id(), AllocationAction.ITEM_COMPLETED, true, grlsCompleted); } //---------------------------------------------------------------------- Modified: branches/gridsim4.0-branch3/source/gridsim/turbo/SSGridlet.java =================================================================== --- branches/gridsim4.0-branch3/source/gridsim/turbo/SSGridlet.java 2007-10-19 00:51:28 UTC (rev 74) +++ branches/gridsim4.0-branch3/source/gridsim/turbo/SSGridlet.java 2007-10-19 00:52:11 UTC (rev 75) @@ -11,7 +11,7 @@ import gridsim.GridSim; import gridsim.Gridlet; -import gridsim.gui.GridSimVisualizer; +import gridsim.gui.DefaultGridSimVisualizer; /** * GridSim @link{SSGridlet} represents a Gridlet submitted to @@ -436,9 +436,9 @@ * Creates a String representation of this Gridlet * for displaying purposes * @param timeUnit the time unit to be used - * @see GridSimVisualizer#TIME_UNIT_SECOND - * @see GridSimVisualizer#TIME_UNIT_MINUTE - * @see GridSimVisualizer#TIME_UNIT_HOUR + * @see DefaultGridSimVisualizer#TIME_UNIT_SECOND + * @see DefaultGridSimVisualizer#TIME_UNIT_MINUTE + * @see DefaultGridSimVisualizer#TIME_UNIT_HOUR */ public String toString(int timeUnit){ String unitDesc = getTimeUnitDescription(timeUnit); @@ -491,10 +491,10 @@ * @return the string containing the description */ private String getTimeUnitDescription(int timeUnit) { - if(timeUnit == GridSimVisualizer.TIME_UNIT_SECOND) { + if(timeUnit == DefaultGridSimVisualizer.TIME_UNIT_SECOND) { return "sec."; } - else if(timeUnit == GridSimVisualizer.TIME_UNIT_MINUTE) { + else if(timeUnit == DefaultGridSimVisualizer.TIME_UNIT_MINUTE) { return "min."; } else { @@ -508,10 +508,10 @@ * @return the time in the unit in use */ private double convertToUnitInUse(double time, int timeUnit) { - if(timeUnit == GridSimVisualizer.TIME_UNIT_SECOND) { + if(timeUnit == DefaultGridSimVisualizer.TIME_UNIT_SECOND) { return time; } - else if(timeUnit == GridSimVisualizer.TIME_UNIT_MINUTE) { + else if(timeUnit == DefaultGridSimVisualizer.TIME_UNIT_MINUTE) { return time/60; } else { Modified: branches/gridsim4.0-branch3/source/gridsim/turbo/SSReservation.java =================================================================== --- branches/gridsim4.0-branch3/source/gridsim/turbo/SSReservation.java 2007-10-19 00:51:28 UTC (rev 74) +++ branches/gridsim4.0-branch3/source/gridsim/turbo/SSReservation.java 2007-10-19 00:52:11 UTC (rev 75) @@ -7,7 +7,7 @@ package gridsim.turbo; -import gridsim.gui.GridSimVisualizer; +import gridsim.gui.DefaultGridSimVisualizer; import java.text.DecimalFormat; import java.util.Calendar; @@ -345,9 +345,9 @@ * for displaying purposes * @param timeUnit the time unit to be used * @return the string representation - * @see GridSimVisualizer#TIME_UNIT_SECOND - * @see GridSimVisualizer#TIME_UNIT_MINUTE - * @see GridSimVisualizer#TIME_UNIT_HOUR + * @see DefaultGridSimVisualizer#TIME_UNIT_SECOND + * @see DefaultGridSimVisualizer#TIME_UNIT_MINUTE + * @see DefaultGridSimVisualizer#TIME_UNIT_HOUR */ public String toString(int timeUnit) { String unitDesc = getTimeUnitDescription(timeUnit); @@ -372,7 +372,7 @@ * @return the string representation */ public String toString() { - return toString(GridSimVisualizer.TIME_UNIT_SECOND); + return toString(DefaultGridSimVisualizer.TIME_UNIT_SECOND); } /** @@ -382,10 +382,10 @@ * @return the string containing the description */ private static String getTimeUnitDescription(int timeUnit) { - if(timeUnit == GridSimVisualizer.TIME_UNIT_SECOND) { + if(timeUnit == DefaultGridSimVisualizer.TIME_UNIT_SECOND) { return "sec."; } - else if(timeUnit == GridSimVisualizer.TIME_UNIT_MINUTE) { + else if(timeUnit == DefaultGridSimVisualizer.TIME_UNIT_MINUTE) { return "min."; } else { @@ -399,10 +399,10 @@ * @return the time in the unit in use */ private static double convertToUnitInUse(double time, int timeUnit) { - if(timeUnit == GridSimVisualizer.TIME_UNIT_SECOND) { + if(timeUnit == DefaultGridSimVisualizer.TIME_UNIT_SECOND) { return time; } - else if(timeUnit == GridSimVisualizer.TIME_UNIT_MINUTE) { + else if(timeUnit == DefaultGridSimVisualizer.TIME_UNIT_MINUTE) { return time/60; } else { Modified: branches/gridsim4.0-branch3/source/gridsim/turbo/ScheduleItem.java =================================================================== --- branches/gridsim4.0-branch3/source/gridsim/turbo/ScheduleItem.java 2007-10-19 00:51:28 UTC (rev 74) +++ branches/gridsim4.0-branch3/source/gridsim/turbo/ScheduleItem.java 2007-10-19 00:52:11 UTC (rev 75) @@ -7,7 +7,7 @@ package gridsim.turbo; -import gridsim.gui.GridSimVisualizer; +import gridsim.gui.DefaultGridSimVisualizer; import gridsim.gui.ResourceWindow; /** @@ -98,9 +98,9 @@ * Creates a String representation of this item * for displaying purposes * @param timeUnit the time unit to be used - * @see GridSimVisualizer#TIME_UNIT_SECOND - * @see GridSimVisualizer#TIME_UNIT_MINUTE - * @see GridSimVisualizer#TIME_UNIT_HOUR + * @see DefaultGridSimVisualizer#TIME_UNIT_SECOND + * @see DefaultGridSimVisualizer#TIME_UNIT_MINUTE + * @see DefaultGridSimVisualizer#TIME_UNIT_HOUR */ public String toString(int timeUnit); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |