From: <sul...@us...> - 2007-08-29 01:01:32
|
Revision: 37 http://gridsim.svn.sourceforge.net/gridsim/?rev=37&view=rev Author: sulistio Date: 2007-08-28 18:01:34 -0700 (Tue, 28 Aug 2007) Log Message: ----------- remove gisID_ attribute, hence fix the constructors. then fix up the writing an event to a file part. Modified Paths: -------------- branches/gridsim4.0-branch1/source/gridsim/resFailure/RegionalGISWithFailure.java Modified: branches/gridsim4.0-branch1/source/gridsim/resFailure/RegionalGISWithFailure.java =================================================================== --- branches/gridsim4.0-branch1/source/gridsim/resFailure/RegionalGISWithFailure.java 2007-08-29 01:00:27 UTC (rev 36) +++ branches/gridsim4.0-branch1/source/gridsim/resFailure/RegionalGISWithFailure.java 2007-08-29 01:01:34 UTC (rev 37) @@ -4,7 +4,7 @@ * of Parallel and Distributed Systems such as Clusters and Grids * Licence: GPL - http://www.gnu.org/copyleft/gpl.html * - * Author: Agustin Caminero + * Author: Agustin Caminero and Anthony Sulistio * Organization: Universidad de Castilla La Mancha (UCLM), Spain. * Created on: Nov 2006. */ @@ -36,24 +36,15 @@ * this class and to override {@link #processOtherEvent(Sim_event)} * and/or {@link #registerOtherEntity()} method. * - * @author Agustin Caminero + * @author Agustin Caminero and Anthony Sulistio * @since GridSim Toolkit 4.1 * @see gridsim.index.RegionalGIS */ public class RegionalGISWithFailure extends AbstractGIS { - // for a RegionalGISWithFailure named "RegionalGIS_2", the gisID_ will be 2 - // This is also the number of the VO. - public int gisID_; // TODO: redundant ?? - - - /** This entity ID in <tt>Integer</tt> object. */ protected Integer myID_; - // denotes whether sim has just began or it has been running for some time - private boolean begining; - private ArrayList resList_; // all resources within this region private ArrayList arList_; // AR resources only within this region private ArrayList globalResList_; // all resources outside this region @@ -97,8 +88,11 @@ // a flag to denote whether to record events into a file or not private boolean record_ = false; + // denotes whether sim has just began or it has been running for some time + private boolean begining; + /** * Creates a new regional GIS entity * @param name this regional GIS name @@ -117,11 +111,10 @@ public RegionalGISWithFailure(String name, Link link, DiscreteGenerator failureNumResPattern, DiscreteGenerator failureTimePattern, - DiscreteGenerator failureLengthPattern, int gisID) + DiscreteGenerator failureLengthPattern) throws Exception { super(name, link); - gisID_ = gisID; if (setFailureGenerator(failureNumResPattern, failureTimePattern, failureLengthPattern)) init(); @@ -149,12 +142,10 @@ public RegionalGISWithFailure(String name, Link link, ContinuousGenerator failureNumResPattern, ContinuousGenerator failureTimePattern, - ContinuousGenerator failureLengthPattern, int gisID) + ContinuousGenerator failureLengthPattern) throws Exception { super(name, link); - gisID_ = gisID; - if (setFailureGenerator(failureNumResPattern, failureTimePattern, failureLengthPattern)) init(); @@ -180,13 +171,10 @@ * @post $none */ public RegionalGISWithFailure(String name, Link link, - Variate failureNumResPattern, - Variate failureTimePattern, - Variate failureLengthPattern, int gisID) - throws Exception + Variate failureNumResPattern, Variate failureTimePattern, + Variate failureLengthPattern) throws Exception { super(name, link); - gisID_ = gisID; if (setFailureGenerator(failureNumResPattern, failureTimePattern, failureLengthPattern)) init(); @@ -196,14 +184,19 @@ super.get_name() + " entity"); } - /** + /** * Asks this resource to record its activities. <br> - * NOTE: this method should be called <b>BEFORE</b> the ssimulation starts. + * NOTE: this method should be called <b>BEFORE</b> the simulation starts. + * If an existing file exists, the new activities will be appended at the + * end. The file name is this entity name. + * * @param trace <tt>true</tt> if you want to record this resource's * activities, <tt>false</tt> otherwise */ - public void setTrace(boolean trace) { + public void setTrace(boolean trace) + { record_ = trace; + initializeReportFile(); } /** @@ -563,13 +556,58 @@ /**********/ } + /** + * Initializes the results files (put headers over each column) + */ + private void initializeReportFile() + { + if (record_ == false) { + return; + } + + // Initialize the results file + FileWriter fwriter = null; + try { + fwriter = new FileWriter(super.get_name(), true); + } + catch (Exception ex) + { + ex.printStackTrace(); + System.out.println("Unwanted errors while opening file " + + super.get_name() + " or " + super.get_name() + "_Fin"); + } + + try { + fwriter.write("Event \t ResourceID \t Clock\n"); + } + catch (Exception ex) + { + ex.printStackTrace(); + System.out.println("Unwanted errors while writing on file " + + super.get_name() + " or " + super.get_name() + "_Fin"); + } + + try { + fwriter.close(); + } + catch (Exception ex) + { + ex.printStackTrace(); + System.out.println("Unwanted errors while closing file " + + super.get_name() + " or " + super.get_name() + "_Fin"); + } + } + /** - * Write some data into a results file. - * @param event Values: "Removing" or "Registering" a resource - * @param resID resource id - * @param clock Current time + * Write an event of this entity into a file. + * If an existing file exists, the new event will be appended at the end. + * The file name is this entity name. + * + * @param event Values: "Removing" or "Registering" a resource + * @param resID resource id + * @param clock Current time */ - private void write(String event, int resID, double clock) + protected void write(String event, int resID, double clock) { if (record_ == false) { return; @@ -580,7 +618,8 @@ try { fwriter = new FileWriter(super.get_name(), true); - } catch (Exception ex) + } + catch (Exception ex) { ex.printStackTrace(); System.out.println( @@ -589,9 +628,9 @@ try { - fwriter.write(super.get_name() + " \t " + event + "\t" + resID + - "\t" + clock + "\n"); - } catch (Exception ex) + fwriter.write(event + "\t" + resID + "\t" + clock + "\n"); + } + catch (Exception ex) { ex.printStackTrace(); System.out.println( @@ -601,13 +640,13 @@ try { fwriter.close(); - } catch (Exception ex) + } + catch (Exception ex) { ex.printStackTrace(); System.out.println( "Unwanted errors while closing file " + super.get_name()); } - } /** This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |