|
From: <mar...@us...> - 2007-10-18 06:20:05
|
Revision: 73
http://gridsim.svn.sourceforge.net/gridsim/?rev=73&view=rev
Author: marcos_dias
Date: 2007-10-17 23:20:07 -0700 (Wed, 17 Oct 2007)
Log Message:
-----------
A bug that prevents the current time from being updated pproperly in all resource windows has been fixed.
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/AllocationAction.java
branches/gridsim4.0-branch3/source/gridsim/gui/GridSimVisualizer.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/ARTGridResource.java
branches/gridsim4.0-branch3/source/gridsim/turbo/ParallelSpaceShared.java
branches/gridsim4.0-branch3/source/gridsim/turbo/ReservationRequester.java
branches/gridsim4.0-branch3/source/gridsim/turbo/TAllocPolicy.java
Removed Paths:
-------------
branches/gridsim4.0-branch3/source/gridsim/gui/AllocationSubject.java
Modified: branches/gridsim4.0-branch3/source/gridsim/AllocPolicy.java
===================================================================
--- branches/gridsim4.0-branch3/source/gridsim/AllocPolicy.java 2007-10-18 01:28:20 UTC (rev 72)
+++ branches/gridsim4.0-branch3/source/gridsim/AllocPolicy.java 2007-10-18 06:20:07 UTC (rev 73)
@@ -9,7 +9,6 @@
package gridsim;
-import java.util.ArrayList;
import java.util.Calendar;
import java.util.LinkedList;
@@ -17,8 +16,7 @@
import eduni.simjava.Sim_event;
import eduni.simjava.Sim_port;
import gridsim.gui.AllocationAction;
-import gridsim.gui.AllocationListener;
-import gridsim.gui.AllocationSubject;
+import gridsim.gui.GridSimVisualizer;
import gridsim.turbo.ScheduleItem;
/**
@@ -43,8 +41,7 @@
* @see gridsim.ResourceCharacteristics
* @invariant $none
*/
-public abstract class AllocPolicy extends Sim_entity
- implements AllocationSubject {
+public abstract class AllocPolicy extends Sim_entity {
/** The GridResource characteristics object, same as the one in
* GridResource class
@@ -87,10 +84,6 @@
private boolean endSimulation_; // denotes the end of simulation
private final int ARRAY_SIZE = 2; // [0] = gridlet id and [1] = result
- // FOR DEBUGGING PURPOSES ONLY
- private ArrayList<AllocationListener> listeners_; // the listeners interested in this policy
- private boolean hasListener_; // indicates whether there are listeners registered
-
///////////////////// ABSTRACT METHODS /////////////////////////////
/**
@@ -678,45 +671,6 @@
super.sim_schedule(myId_, time, tag, data);
return true;
}
-
- /**
- * Adds a listener to the list of listeners interested in the events
- * generated by this allocation policy
- * @param listener the listener to be registered
- * @return <tt>true</tt> if success or <tt>false</tt> otherwise
- */
- public boolean addAllocationListener(AllocationListener listener) {
- if(listeners_ == null){
- listeners_ = new ArrayList<AllocationListener>();
- listeners_.add(listener);
- }
- else{
- if(listeners_.contains(listener)){
- return false;
- }
- listeners_.add(listener);
- }
- hasListener_ = true;
- return true;
- }
-
-
- /**
- * Unregisters a listener from the list of listeners interested in
- * the events generated by this allocation policy
- * @param listener the listener to be unregistered
- * @return <tt>true</tt> if success or <tt>false</tt> otherwise
- */
- public boolean removeAllocationListener(AllocationListener listener) {
- if(listeners_ == null || !listeners_.contains(listener)){
- return false;
- }
- listeners_.remove(listener);
- if(listeners_.size() == 0) {
- hasListener_ = false;
- }
- return true;
- }
/**
* Notifies the listeners about the action performed
@@ -724,40 +678,25 @@
* @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 time the time when the action took place
* @param itemList the list of gridlets to provide to the listeners
*
- * @see AllocationAction#GRIDLET_ARRIVED
- * @see AllocationAction#GRIDLET_SCHEDULED
- * @see AllocationAction#GRIDLET_CANCELLED
- * @see AllocationAction#GRIDLET_COMPLETED
+ * @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,
- double time, LinkedList itemList){
+ protected void notifyListeners(int allocationAction,
+ boolean shouldPause, LinkedList itemList) {
- if(!GridSim.DEBUG_SIMULATION)
+ if(!GridSim.isDebugModeEnabled())
return;
- if(hasListener_){
- AllocationAction action = new AllocationAction(allocationAction, time);
-
- if(itemList != null)
- action.setScheduleItems(itemList);
-
- for(AllocationListener listener : listeners_){
- listener.allocationActionPerformed(action);
- }
-
- if(shouldPause){
- if(GridSim.STEP_BY_STEP_SIMULATION){
- GridSim.pauseSimulation();
- }
- else if(GridSim.SLOW_MOTION_SIMULATION){
- GridSim.smallPause();
- }
- }
- }
+ AllocationAction action = new AllocationAction(allocationAction);
+ action.setSubject(this.get_id());
+ action.setScheduleItems(itemList);
+ GridSimVisualizer.notifyListeners(action, shouldPause);
}
/**
@@ -766,19 +705,19 @@
* @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 time the time when the action took place
* @param item the gridlet to provide to the listeners
*
- * @see AllocationAction#GRIDLET_ARRIVED
- * @see AllocationAction#GRIDLET_SCHEDULED
- * @see AllocationAction#GRIDLET_CANCELLED
- * @see AllocationAction#GRIDLET_COMPLETED
+ * @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,
- double time, ScheduleItem item){
+ ScheduleItem item) {
- if(!GridSim.DEBUG_SIMULATION)
+ if(!GridSim.isDebugModeEnabled())
return;
LinkedList<ScheduleItem> itemList = null;
@@ -787,7 +726,7 @@
itemList.add(item);
}
- notifyListeners(allocationAction, shouldPause, time, itemList);
+ notifyListeners(allocationAction, shouldPause, itemList);
}
/**
@@ -796,36 +735,23 @@
* @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 time the time when the action took place
* @param gridlet the gridlet to provide to the listeners
*
- * @see AllocationAction#GRIDLET_ARRIVED
- * @see AllocationAction#GRIDLET_SCHEDULED
- * @see AllocationAction#GRIDLET_CANCELLED
- * @see AllocationAction#GRIDLET_COMPLETED
+ * @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, double time){
+ protected void notifyListeners(int allocationAction, boolean shouldPause) {
- if(!GridSim.DEBUG_SIMULATION)
+ if(!GridSim.isDebugModeEnabled())
return;
- if(hasListener_){
- AllocationAction action = new AllocationAction(allocationAction, time);
-
- for(AllocationListener listener : listeners_){
- listener.allocationActionPerformed(action);
- }
-
- if(shouldPause){
- if(GridSim.STEP_BY_STEP_SIMULATION){
- GridSim.pauseSimulation();
- }
- else if(GridSim.SLOW_MOTION_SIMULATION){
- GridSim.smallPause();
- }
- }
- }
+ 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-18 01:28:20 UTC (rev 72)
+++ branches/gridsim4.0-branch3/source/gridsim/GridSim.java 2007-10-18 06:20:07 UTC (rev 73)
@@ -83,10 +83,11 @@
private final int SIZE = 12; // Integer object size incl. overhead
private final int RESULT = 1; // array[0] = gridlet id, [1] = result
private final static String GRIDSIM_VERSION_STRING = "Turbo Alpha 0.1";
- public static boolean END_OF_SIMULATION = false;
- public static boolean DEBUG_SIMULATION = true;
- public static boolean SLOW_MOTION_SIMULATION = false;
- public static boolean STEP_BY_STEP_SIMULATION = false;
+
+ // These attributes are set to be used by the Graphical User Interface
+ public static boolean debugMode_ = true;
+ public static boolean slowMotionMode_ = false;
+ public static boolean stepByStepMode_ = false;
/////////////////////////// STATIC variables ////////////////////
@@ -446,6 +447,77 @@
System.out.println( e.getMessage() );
}
}
+
+ // METHODS TO SET THE SIMULATION MODES
+
+ /**
+ * Enables the debug mode (used by the GUI)
+ */
+ public static void enableDebugMode() {
+ debugMode_ = true;
+ }
+
+ /**
+ * Disables the debug mode (used by the GUI)
+ */
+ public static void disableDebugMode() {
+ debugMode_ = false;
+ }
+
+ /**
+ * Returns <tt>true</tt> if the debug mode is enabled
+ * @return <tt>true</tt> if the debug mode is enabled;
+ * <tt>false<tt> otherwise
+ */
+ public static boolean isDebugModeEnabled() {
+ return debugMode_;
+ }
+
+ /**
+ * Enables the slow motion mode (used by the GUI)
+ */
+ public static void enableSlowMotionMode() {
+ slowMotionMode_ = true;
+ }
+
+ /**
+ * Disables the slow motion mode (used by the GUI)
+ */
+ public static void disableSlowMotionMode() {
+ slowMotionMode_ = false;
+ }
+
+ /**
+ * Returns <tt>true</tt> if the slow motion mode is enabled
+ * @return <tt>true</tt> if the slow motion mode is enabled;
+ * <tt>false<tt> otherwise
+ */
+ public static boolean isSlowMotionModeEnabled() {
+ return slowMotionMode_;
+ }
+
+ /**
+ * Enables the step by step mode (used by the GUI)
+ */
+ public static void enableStepByStepMode() {
+ stepByStepMode_ = true;
+ }
+
+ /**
+ * Disables the step by step mode (used by the GUI)
+ */
+ public static void disableStepByStepMode() {
+ stepByStepMode_ = false;
+ }
+
+ /**
+ * 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
+ */
+ public static boolean isStepByStepEnabled() {
+ return stepByStepMode_;
+ }
/**
* Sets a <tt>GridInformationService</tt> (GIS) entity.
@@ -524,7 +596,6 @@
System.out.println("Starting GridSim " + GRIDSIM_VERSION_STRING);
try {
Sim_system.run();
- END_OF_SIMULATION = true;
}
catch (Sim_exception e) {
throw new NullPointerException("GridSim.startGridSimulation() :" +
@@ -556,9 +627,9 @@
startGridSimulation();
}
else{
- DEBUG_SIMULATION = true;
- SLOW_MOTION_SIMULATION = false;
- STEP_BY_STEP_SIMULATION = false;
+ enableDebugMode();
+ disableSlowMotionMode();
+ disableStepByStepMode();
// get a list of resource created by the user in order to pass
// it to the visualisation tool
Modified: branches/gridsim4.0-branch3/source/gridsim/gui/AllocationAction.java
===================================================================
--- branches/gridsim4.0-branch3/source/gridsim/gui/AllocationAction.java 2007-10-18 01:28:20 UTC (rev 72)
+++ branches/gridsim4.0-branch3/source/gridsim/gui/AllocationAction.java 2007-10-18 06:20:07 UTC (rev 73)
@@ -24,32 +24,26 @@
public class AllocationAction {
private LinkedList<ScheduleItem> items_;
+
+ // the id of the entity that generated this action
+ private int subject_;
private int actionType_;
- private double time_;
- /** Gridlet related actions */
- public static final int GRIDLET_ARRIVED = 0;
- public static final int GRIDLET_SCHEDULED = 1;
- public static final int GRIDLET_COMPLETED = 2;
- public static final int GRIDLET_CANCELLED = 3;
- public static final int SCHEDULE_CHANGED = 4;
+ /** Possible allocation actions */
+ public static final int ITEM_ARRIVED = 0;
+ public static final int ITEM_SCHEDULED = 1;
+ public static final int ITEM_COMPLETED = 2;
+ public static final int ITEM_CANCELLED = 3;
+ public static final int ITEM_STATUS_CHANGED = 4;
+ public static final int SCHEDULE_CHANGED = 5;
+ public static final int SIMULATION_TIME_CHANGED = 6;
- /** Advance reservation actions */
- public static final int RESERVATION_ARRIVED = 10;
- public static final int RESERVATION_SCHEDULED = 11;
- public static final int RESERVATION_COMMITED = 12;
- public static final int RESERVATION_STARTED = 13;
- public static final int RESERVATION_CANCELLED = 14;
- public static final int RESERVATION_FINISHED = 15;
-
/**
* Creates a new {@link AllocationAction} object.
* @param type the type of action performed
- * @param time the time when the action was performed
*/
- public AllocationAction(int type, double time){
+ public AllocationAction(int type){
actionType_ = type;
- time_ = time;
items_ = null;
}
@@ -92,18 +86,18 @@
}
/**
- * Gets the time associated with this action
- * @return the time
+ * Gets the id of the subject or entity that created this action
+ * @return the id of the subject or entity that created this action
*/
- public double getTime() {
- return time_;
+ public int getSubject() {
+ return subject_;
}
/**
- * Sets the time associated with this action
- * @param time the time
+ * Sets the id of the subject or entity that created this action
+ * @param subject the id of the subject or entity that created this action
*/
- public void setTime(double time) {
- this.time_ = time;
+ public void setSubject(int subject) {
+ subject_ = subject;
}
}
Deleted: branches/gridsim4.0-branch3/source/gridsim/gui/AllocationSubject.java
===================================================================
--- branches/gridsim4.0-branch3/source/gridsim/gui/AllocationSubject.java 2007-10-18 01:28:20 UTC (rev 72)
+++ branches/gridsim4.0-branch3/source/gridsim/gui/AllocationSubject.java 2007-10-18 06:20:07 UTC (rev 73)
@@ -1,41 +0,0 @@
-/*
- * Title: GridSim Toolkit
- * Description: GridSim (Grid Simulation) Toolkit for Modelling and Simulation
- * of Parallel and Distributed Systems such as Clusters and Grids
- * Licence: GPL - http://www.gnu.org/copyleft/gpl.html
- */
-
-package gridsim.gui;
-
-/**
- * This interface has to be implemented by classes with which the
- * allocation listeners can register. An {@link AllocationSubject} provides
- * information to listeners. This is mainly used by the visualisation tool
- * to display information about the scheduling queues.
- *
- * @author Marcos Dias de Assuncao
- * @since GridSim Turbo Alpha 0.1
- *
- * @see AllocationAction
- * @see AllocationListener
- */
-
-public interface AllocationSubject {
-
- /**
- * Registers an {@link AllocationListener}.
- * @param listener the allocation listener
- * @return <tt>true</tt> if it has been registered or
- * <tt>false</tt> otherwise
- */
- boolean addAllocationListener(AllocationListener listener);
-
- /**
- * Unregisters an {@link AllocationListener}.
- * @param listener the listener to be removed
- * @return <tt>true</tt> if the listener has been removed
- * or <tt>false</tt> otherwise
- */
- boolean removeAllocationListener(AllocationListener listener);
-
-}
Modified: branches/gridsim4.0-branch3/source/gridsim/gui/GridSimVisualizer.java
===================================================================
--- branches/gridsim4.0-branch3/source/gridsim/gui/GridSimVisualizer.java 2007-10-18 01:28:20 UTC (rev 72)
+++ branches/gridsim4.0-branch3/source/gridsim/gui/GridSimVisualizer.java 2007-10-18 06:20:07 UTC (rev 73)
@@ -30,6 +30,7 @@
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
+import java.util.LinkedHashMap;
import javax.swing.BorderFactory;
import javax.swing.DefaultListModel;
@@ -92,14 +93,21 @@
// 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 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.
@@ -192,6 +200,65 @@
}
// ------------------------- 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 static 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
@@ -208,23 +275,23 @@
String cmd = e.getActionCommand();
if(cmd.equals("Step")){
- GridSim.STEP_BY_STEP_SIMULATION = true;
- GridSim.SLOW_MOTION_SIMULATION = false;
+ GridSim.enableStepByStepMode();
+ GridSim.disableSlowMotionMode();
checkFirstClick();
GridSim.resumeSimulation();
}
else if(cmd.equals("Run")){
- GridSim.STEP_BY_STEP_SIMULATION = false;
- GridSim.SLOW_MOTION_SIMULATION = false;
+ GridSim.disableStepByStepMode();
+ GridSim.disableSlowMotionMode();
if(!checkFirstClick()) {
GridSim.resumeSimulation();
}
}
else if(cmd.equals("Slow Motion")){
- GridSim.STEP_BY_STEP_SIMULATION = false;
- GridSim.SLOW_MOTION_SIMULATION = true;
+ GridSim.disableStepByStepMode();
+ GridSim.enableSlowMotionMode();
if(!checkFirstClick()) {
GridSim.resumeSimulation();
@@ -241,11 +308,25 @@
}
// ------------------------- 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(){
+ private void initResourceWindows() {
int windowId = 0;
for(GridResource resource : resources_){
GridResource tresource = (GridResource)resource;
@@ -256,7 +337,7 @@
// of the allocation policy. This means that the window will be
// notified of the allocation actions performed by the resource
// allocation policy
- tresource.getAllocationPolicy().addAllocationListener(window);
+ listeners_.put(tresource.getAllocationPolicy().get_id(), window);
windowId++;
}
}
@@ -264,7 +345,7 @@
/**
* Creates the menu bar of the main window
*/
- private void createMenuBar(){
+ private void createMenuBar() {
JMenuBar menuBar = new JMenuBar();
JMenu menuCommand = new JMenu("Start");
JMenuItem item;
Modified: branches/gridsim4.0-branch3/source/gridsim/gui/ResourceWindow.java
===================================================================
--- branches/gridsim4.0-branch3/source/gridsim/gui/ResourceWindow.java 2007-10-18 01:28:20 UTC (rev 72)
+++ branches/gridsim4.0-branch3/source/gridsim/gui/ResourceWindow.java 2007-10-18 06:20:07 UTC (rev 73)
@@ -20,6 +20,7 @@
package gridsim.gui;
import gridsim.GridResource;
+import gridsim.GridSim;
import gridsim.Gridlet;
import gridsim.turbo.PERange;
import gridsim.turbo.PERangeList;
@@ -185,42 +186,45 @@
public boolean allocationActionPerformed(AllocationAction action) {
int type = action.getActionType();
LinkedList<ScheduleItem> list = action.getScheduleItems();
- currentTime_ = (long) action.getTime();
+ currentTime_ = (long) GridSim.clock();
switch(type){
- case AllocationAction.GRIDLET_ARRIVED:
- case AllocationAction.RESERVATION_STARTED:
- case AllocationAction.RESERVATION_COMMITED:
- case AllocationAction.RESERVATION_FINISHED:
- case AllocationAction.RESERVATION_ARRIVED:
+ case AllocationAction.ITEM_ARRIVED:
+ case AllocationAction.ITEM_STATUS_CHANGED:
for(ScheduleItem item : list){
itemPanel_.updateItem(item);
}
+ updateResourceWindow();
break;
- case AllocationAction.GRIDLET_SCHEDULED:
- case AllocationAction.RESERVATION_SCHEDULED:
+ case AllocationAction.ITEM_SCHEDULED:
for(ScheduleItem item : list){
scheduledItems_.add(item);
- updateTimeSpan(item);
+ double finishTime = item.getFinishTime();
+ updateTimeSpan(finishTime);
itemPanel_.updateItem(item);
}
+ updateResourceWindow();
break;
- case AllocationAction.RESERVATION_CANCELLED:
- case AllocationAction.GRIDLET_CANCELLED:
+ case AllocationAction.ITEM_CANCELLED:
for(ScheduleItem item : list){
itemPanel_.updateItem(item);
scheduledItems_.remove(item);
}
+ updateResourceWindow();
break;
+
+ case AllocationAction.SIMULATION_TIME_CHANGED:
+ if(updateTimeSpan(currentTime_))
+ updateResourceWindow();
+ break;
- case AllocationAction.GRIDLET_COMPLETED:
+ case AllocationAction.ITEM_COMPLETED:
case AllocationAction.SCHEDULE_CHANGED:
+ updateResourceWindow();
break;
}
-
- updateResourceWindow();
return true;
}
@@ -375,9 +379,14 @@
/**
* Updates the time span, that is, the time frame shown in the window
*/
- private void updateTimeSpan(ScheduleItem item){
- double finishTime = item.getFinishTime();
- timeSpan_ = (finishTime > timeSpan_) ? finishTime : timeSpan_;
+ private boolean updateTimeSpan(double time) {
+ if(time > timeSpan_) {
+ timeSpan_ = time;
+ return true;
+ }
+ else {
+ return false;
+ }
}
/**
Modified: branches/gridsim4.0-branch3/source/gridsim/turbo/ARParallelSpaceShared.java
===================================================================
--- branches/gridsim4.0-branch3/source/gridsim/turbo/ARParallelSpaceShared.java 2007-10-18 01:28:20 UTC (rev 72)
+++ branches/gridsim4.0-branch3/source/gridsim/turbo/ARParallelSpaceShared.java 2007-10-18 06:20:07 UTC (rev 73)
@@ -163,10 +163,6 @@
// last time the expiration of reservations was checked
private double lastCheckExpiryTime_;
- // FOR DEBUGGING PURPOSES ONLY
- // Keep the time of the last allocation action
- private double lastActionTime_;
-
/**
* Creates a new scheduler that handles advanced reservations. This
* scheduler uses First Come First Served (FCFS) algorithm with
@@ -295,10 +291,6 @@
public void handleCreateReservation(ARMessage message) {
double currentTime = GridSim.clock();
- // stores the last action time for debugging purposes
- // and for the graphical user interface
- lastActionTime_ = currentTime;
-
// gets the reservation object and extract some
// information from it
Reservation reservation = message.getReservation();
@@ -316,8 +308,7 @@
//-------------- FOR DEBUGGING PURPOSES ONLY --------------
// informs the listeners that a reservation request has arrived
- super.notifyListeners(AllocationAction.RESERVATION_ARRIVED,
- true, lastActionTime_, sRes);
+ super.notifyListeners(AllocationAction.ITEM_ARRIVED, true, sRes);
//----------------------------------------------------------
@@ -464,8 +455,7 @@
//-------------- FOR DEBUGGING PURPOSES ONLY --------------
// Informs the listeners about the reservation that has been created
- super.notifyListeners(AllocationAction.RESERVATION_SCHEDULED,
- true, lastActionTime_, sRes);
+ super.notifyListeners(AllocationAction.ITEM_SCHEDULED, true, sRes);
//----------------------------------------------------------
}
@@ -479,9 +469,6 @@
public void handleCancelReservation(ARMessage message) {
double currentTime = GridSim.clock();
- // stores the last action time for debugging purposes
- lastActionTime_ = currentTime;
-
// gets the reservation id of the message
int reservationId = message.getReservationID();
boolean success = true;
@@ -535,8 +522,7 @@
//----------------- USED FOR DEBUGGING PURPOSES ONLY -------------------
// If a gridlet has been cancelled, then inform the listeners
- super.notifyListeners(AllocationAction.RESERVATION_CANCELLED,
- true, lastActionTime_, sRes);
+ super.notifyListeners(AllocationAction.ITEM_CANCELLED, true, sRes);
//----------------------------------------------------------------------
@@ -546,8 +532,7 @@
//----------------- USED FOR DEBUGGING PURPOSES ONLY -------------------
// Inform the listeners about the new schedule
- super.notifyListeners(AllocationAction.SCHEDULE_CHANGED,
- true, lastActionTime_);
+ super.notifyListeners(AllocationAction.SCHEDULE_CHANGED, true);
//----------------------------------------------------------------------
@@ -563,9 +548,6 @@
double currentTime = GridSim.clock();
- // stores the last action time for debugging purposes
- lastActionTime_ = currentTime;
-
// gets the reservation id of the message
int reservationId = message.getReservationID();
SSReservation sRes = null;
@@ -629,8 +611,7 @@
//-------------- FOR DEBUGGING PURPOSES ONLY --------------
- super.notifyListeners(AllocationAction.RESERVATION_COMMITED,
- true, lastActionTime_, sRes);
+ super.notifyListeners(AllocationAction.ITEM_STATUS_CHANGED, true, sRes);
//----------------------------------------------------------
}
@@ -650,12 +631,7 @@
* @param message the advance reservation message received.
*/
public void handleQueryFreeTime(ARMessage message) {
-
- double currentTime = GridSim.clock();
- // stores the last action time for debugging purposes
- lastActionTime_ = currentTime;
-
// gets the reservation id of the message
Reservation reservation = message.getReservation();
@@ -681,11 +657,7 @@
* @param message the advance reservation message received.
*/
public void handleQueryReservation(ARMessage message) {
- double currentTime = GridSim.clock();
-
- // stores the last action time for debugging purposes
- lastActionTime_ = currentTime;
-
+
// gets the reservation id of the message
int reservationId = message.getReservationID();
@@ -800,8 +772,6 @@
public void gridletCancel(int gridletId, int userId) {
double currentTime = GridSim.clock();
- // set the time of the last allocation action
- lastActionTime_ = currentTime;
// stores the gridlet if found
SSGridlet sgl = null;
boolean found = false;
@@ -859,8 +829,7 @@
//----------------- USED FOR DEBUGGING PURPOSES ONLY -------------------
// If a gridlet has been cancelled, then inform the listeners
- super.notifyListeners(AllocationAction.GRIDLET_CANCELLED,
- true, lastActionTime_, sgl);
+ super.notifyListeners(AllocationAction.ITEM_CANCELLED, true, sgl);
//----------------------------------------------------------------------
@@ -873,8 +842,7 @@
//------------------- USED FOR DEBUGGING PURPOSES ONLY -----------------
// Inform the listeners about the new schedule
- super.notifyListeners(AllocationAction.SCHEDULE_CHANGED,
- true, lastActionTime_);
+ super.notifyListeners(AllocationAction.SCHEDULE_CHANGED, true);
//----------------------------------------------------------------------
@@ -999,7 +967,6 @@
reservTable_ = new LinkedHashMap<Integer, SSReservation>();
expiryTable_ = new LinkedHashMap<Integer, SSReservation>();
orderStartTime_ = new OrderGridletByStartTime();
- lastActionTime_ = -1;
lastScheduleUpdate_ = -1;
lastReservationStart_ = -1;
lastCheckExpiryTime_ = -1;
@@ -1016,8 +983,6 @@
*/
private void handleNonReservationGridlet(Gridlet gridlet, boolean ack) {
int reqPE = gridlet.getNumPE();
- double currentTime = GridSim.clock();
- lastActionTime_ = currentTime;
try{
// reject the Gridlet if it requires more PEs than the resource
@@ -1044,8 +1009,7 @@
//------------------ FOR DEBUGGING PURPOSES ONLY------------------------
- super.notifyListeners(AllocationAction.GRIDLET_ARRIVED,
- true, lastActionTime_, sgl);
+ super.notifyListeners(AllocationAction.ITEM_ARRIVED, true, sgl);
//----------------------------------------------------------------------
@@ -1070,8 +1034,7 @@
// Notifies the listeners that a Gridlet has been either scheduled
// to run immediately or put in the waiting queue
- super.notifyListeners(AllocationAction.GRIDLET_SCHEDULED,
- true, lastActionTime_, sgl);
+ super.notifyListeners(AllocationAction.ITEM_SCHEDULED, true, sgl);
//---------------------------------------------------------------
@@ -1095,10 +1058,6 @@
double currentTime = GridSim.clock();
- // stores the last action time for debugging purposes
- lastActionTime_ = currentTime;
-
-
int freePE;
int reqPE = gridlet.getNumPE();
// gets the advance reservation
@@ -1113,8 +1072,7 @@
/////////////// FOR DEBUGGING PURPOSES ONLY ////////
- super.notifyListeners(AllocationAction.GRIDLET_ARRIVED,
- true, lastActionTime_, sgl);
+ super.notifyListeners(AllocationAction.ITEM_ARRIVED, true, sgl);
/////////////////////////////////////////////////////
@@ -1194,8 +1152,7 @@
// Notifies the listeners that a Gridlet has been either scheduled
// to run immediately or put in the waiting queue
- super.notifyListeners(AllocationAction.GRIDLET_SCHEDULED,
- true, lastActionTime_, sgl);
+ super.notifyListeners(AllocationAction.ITEM_SCHEDULED, true, sgl);
//---------------------------------------------------------------
@@ -1227,8 +1184,6 @@
double currentTime = GridSim.clock() ;
// the Gridlet's expected finish time
double finishTime = currentTime + executionTime;
- // keep the time of the last allocation action
- lastActionTime_ = currentTime;
// check whether there are PEs available over the time interval requested
Object[] availObj =
@@ -1272,8 +1227,6 @@
// calculate the execution time of the Gridlet
double executionTime =
super.forecastExecutionTime(ratingPE_, sgl.getRemainingLength());
- // keep the time of the last allocation action
- lastActionTime_ = GridSim.clock();
double startTime = -1; // keep the potential start time of the gridlet
double finishTime = -1; // store the gridlet's expected finish time
@@ -1361,8 +1314,8 @@
//---------------- USED FOR DEBUGGING PURPOSES ONLY ----------------
// If a gridlet has been cancelled, then inform the listeners
- super.notifyListeners(AllocationAction.GRIDLET_CANCELLED,
- false, lastActionTime_, removedGridlets);
+ super.notifyListeners(AllocationAction.ITEM_CANCELLED,
+ false, removedGridlets);
//------------------------------------------------------------------
}
@@ -1529,7 +1482,6 @@
private void checkExpiryTime() {
double currentTime = GridSim.clock(); // get current time
- lastActionTime_ = currentTime;
// gridlets whose start time is larger than reference time
// will be shifted forwards when the compression of the
@@ -1568,8 +1520,7 @@
//-------------- USED FOR DEBUGGING PURPOSES ONLY -----------------
// If a gridlet has been cancelled, then inform the listeners
- super.notifyListeners(AllocationAction.RESERVATION_CANCELLED,
- true, lastActionTime_, removedRes);
+ super.notifyListeners(AllocationAction.ITEM_CANCELLED, true, removedRes);
//-----------------------------------------------------------------
@@ -1586,8 +1537,7 @@
// If a gridlet has started execution or one has finished,
// then inform the listeners
- super.notifyListeners(AllocationAction.SCHEDULE_CHANGED,
- true, lastActionTime_);
+ super.notifyListeners(AllocationAction.SCHEDULE_CHANGED, true);
//-----------------------------------------------------------------
}
@@ -1602,7 +1552,6 @@
private void updateSchedule(){
double currentTime = GridSim.clock();
- lastActionTime_ = currentTime;
int gridletFinished = 0;
int gridletStarted = 0;
boolean reserved;
@@ -1648,8 +1597,8 @@
// If a gridlet has started execution or one has finished,
// then inform the listeners
if(gridletStarted > 0 || gridletFinished > 0){
- super.notifyListeners(AllocationAction.GRIDLET_COMPLETED,
- true, lastActionTime_, grlsCompleted);
+ super.notifyListeners(AllocationAction.ITEM_COMPLETED,
+ true, grlsCompleted);
}
}
@@ -1660,7 +1609,6 @@
private void startReservation() {
double currentTime = GridSim.clock();
- lastActionTime_ = currentTime;
LinkedList<SSReservation> startedReservations = new LinkedList<SSReservation>();
PERangeList allocatedRanges = new PERangeList();
int numStartedRes = 0;
@@ -1700,8 +1648,8 @@
//------------- USED FOR DEBUGGING PURPOSES ONLY ------------------
// notify the listeners
- super.notifyListeners(AllocationAction.RESERVATION_STARTED,
- true, lastActionTime_, startedReservations);
+ super.notifyListeners(AllocationAction.ITEM_STATUS_CHANGED,
+ true, startedReservations);
//------------------------------------------------------------------
@@ -1711,8 +1659,7 @@
// If a gridlet has started execution or one has finished,
// then inform the listeners
- super.notifyListeners(AllocationAction.SCHEDULE_CHANGED,
- true, lastActionTime_);
+ super.notifyListeners(AllocationAction.SCHEDULE_CHANGED, true);
//------------------------------------------------------------------
}
@@ -1726,7 +1673,6 @@
private void finishReservation() {
double currentTime = GridSim.clock();
- lastActionTime_ = currentTime;
int reservationFinished = 0;
// remove all reservations that have already completed
@@ -1760,8 +1706,7 @@
// If a gridlet has started execution or one has finished,
// then inform the listeners
- super.notifyListeners(AllocationAction.SCHEDULE_CHANGED,
- true, lastActionTime_);
+ super.notifyListeners(AllocationAction.SCHEDULE_CHANGED, true);
//-----------------------------------------------------------------
}
Modified: branches/gridsim4.0-branch3/source/gridsim/turbo/ARTGridResource.java
===================================================================
--- branches/gridsim4.0-branch3/source/gridsim/turbo/ARTGridResource.java 2007-10-18 01:28:20 UTC (rev 72)
+++ branches/gridsim4.0-branch3/source/gridsim/turbo/ARTGridResource.java 2007-10-18 06:20:07 UTC (rev 73)
@@ -76,6 +76,9 @@
"a policy that supports advance reservation");
}
initARPolicy();
+
+ // sets the name of this thread for debugging purposes.
+ super.setName(super.get_name());
}
/**
@@ -115,6 +118,9 @@
"a policy that supports advance reservation");
}
initARPolicy();
+
+ // sets the name of this thread for debugging purposes.
+ super.setName(super.get_name());
}
/////////////////////// PROTECTED METHOD /////////////////////////////////
Modified: branches/gridsim4.0-branch3/source/gridsim/turbo/ParallelSpaceShared.java
===================================================================
--- branches/gridsim4.0-branch3/source/gridsim/turbo/ParallelSpaceShared.java 2007-10-18 01:28:20 UTC (rev 72)
+++ branches/gridsim4.0-branch3/source/gridsim/turbo/ParallelSpaceShared.java 2007-10-18 06:20:07 UTC (rev 73)
@@ -116,10 +116,6 @@
// to order gridlets by potential start time
private OrderGridletByStartTime orderStartTime_;
- // FOR DEBUGGING PURPOSES ONLY
- // Keep the time of the last allocation action
- private double lastActionTime_;
-
// the last time when the schedule updated was called
private double lastScheduleUpdate_;
@@ -151,7 +147,6 @@
queuedGridlets_ = new LinkedList<SSGridlet>();
availProfile_ = new AvailabilityProfile();
orderStartTime_ = new OrderGridletByStartTime();
- lastActionTime_ = 0.0D;
lastScheduleUpdate_ = 0.0D;
ratingPE_ = 0;
}
@@ -213,8 +208,6 @@
*/
public void gridletSubmit(Gridlet gridlet, boolean ack) {
int reqPE = gridlet.getNumPE();
- double currentTime = GridSim.clock();
- lastActionTime_ = currentTime;
try{
// reject the Gridlet if it requires more PEs than the resource
@@ -241,8 +234,7 @@
//-------------- FOR DEBUGGING PURPOSES ONLY --------------
- super.notifyListeners(AllocationAction.GRIDLET_ARRIVED,
- true, lastActionTime_, sgl);
+ super.notifyListeners(AllocationAction.ITEM_ARRIVED, true, sgl);
//----------------------------------------------------------
@@ -267,8 +259,7 @@
// Notifies the listeners that a Gridlet has been either scheduled
// to run immediately or put in the waiting queue
- super.notifyListeners(AllocationAction.GRIDLET_SCHEDULED,
- true, lastActionTime_, sgl);
+ super.notifyListeners(AllocationAction.ITEM_SCHEDULED, true, sgl);
//---------------------------------------------------------------
@@ -354,8 +345,6 @@
public void gridletCancel(int gridletId, int userId) {
double currentTime = GridSim.clock();
- // set the time of the last allocation action
- lastActionTime_ = currentTime;
// stores the gridlet if found
SSGridlet sgl = null;
boolean found = false;
@@ -408,8 +397,7 @@
//----------------- USED FOR DEBUGGING PURPOSES ONLY -------------------
// If a gridlet has been cancelled, then inform the listeners about it
- super.notifyListeners(AllocationAction.GRIDLET_CANCELLED,
- true, lastActionTime_, sgl);
+ super.notifyListeners(AllocationAction.ITEM_CANCELLED, true, sgl);
//----------------------------------------------------------------------
@@ -419,8 +407,7 @@
//----------------- USED FOR DEBUGGING PURPOSES ONLY -------------------
// Inform the listeners about the new schedule
- super.notifyListeners(AllocationAction.SCHEDULE_CHANGED,
- true, lastActionTime_);
+ super.notifyListeners(AllocationAction.SCHEDULE_CHANGED, true);
//----------------------------------------------------------------------
@@ -496,8 +483,6 @@
double currentTime = GridSim.clock() ;
// the Gridlet's expected finish time
double finishTime = currentTime + executionTime;
- // keep the time of the last allocation action
- lastActionTime_ = currentTime;
// check whether there are PEs available over the time interval requested
Object[] availObj =
@@ -541,8 +526,6 @@
// calculate the execution time of the Gridlet
double executionTime =
super.forecastExecutionTime(ratingPE_, sgl.getRemainingLength());
- // keep the time of the last allocation action
- lastActionTime_ = GridSim.clock();
double startTime = -1; // keep the potential start time of the gridlet
double finishTime = -1; // store the gridlet's expected finish time
@@ -909,7 +892,6 @@
private void updateSchedule(){
double currentTime = GridSim.clock();
- lastActionTime_ = currentTime;
int gridletFinished = 0;
int gridletStarted = 0;
@@ -977,8 +959,8 @@
// If a gridlet has started execution or one has finished,
// then inform the listeners
if(gridletStarted > 0 || gridletFinished > 0){
- super.notifyListeners(AllocationAction.GRIDLET_COMPLETED,
- true, lastActionTime_, grlsCompleted);
+ super.notifyListeners(AllocationAction.ITEM_COMPLETED,
+ true, grlsCompleted);
}
//----------------------------------------------------------------------
}
Modified: branches/gridsim4.0-branch3/source/gridsim/turbo/ReservationRequester.java
===================================================================
--- branches/gridsim4.0-branch3/source/gridsim/turbo/ReservationRequester.java 2007-10-18 01:28:20 UTC (rev 72)
+++ branches/gridsim4.0-branch3/source/gridsim/turbo/ReservationRequester.java 2007-10-18 06:20:07 UTC (rev 73)
@@ -496,6 +496,9 @@
*/
private void init() {
reservations_ = new HashMap<Integer,Reservation>();
+
+ // sets the name of this thread for debugging purposes.
+ super.setName(super.get_name());
}
/**
Modified: branches/gridsim4.0-branch3/source/gridsim/turbo/TAllocPolicy.java
===================================================================
--- branches/gridsim4.0-branch3/source/gridsim/turbo/TAllocPolicy.java 2007-10-18 01:28:20 UTC (rev 72)
+++ branches/gridsim4.0-branch3/source/gridsim/turbo/TAllocPolicy.java 2007-10-18 06:20:07 UTC (rev 73)
@@ -61,6 +61,9 @@
protected TAllocPolicy(String resourceName, String entityName)
throws Exception{
super(resourceName, entityName);
+
+ // sets the name of this thread for debugging purposes.
+ super.setName(super.get_name());
}
/**
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|