📄 regionalgiswithfailure.java
字号:
// UNTIL HERE*/ boolean result = sendListToSender(ev, resList_); if (result == false) { System.out.println(super.get_name() + ".processResourceList(): Warning - unable to send a list " + "of resource IDs to sender."); } } /** * Process an incoming request about getting a list of resource IDs * supporting Advanced Reservation that are registered to this regional GIS * entity. * * @param ev a Sim_event object (or an incoming event or request) * @pre ev != null * @post $none */ protected void processResourceARList(Sim_event ev) { boolean result = sendListToSender(ev, arList_); if (result == false) { System.out.println(super.get_name() + ".processResourceARList(): Warning - unable to send a list " + "of resource IDs to sender."); } } /** * Registers other information to {@link gridsim.GridInformationService} or * system GIS.<br> * NOTE: This method can be overridden by its subclasses, provided * that they call this method first. This is required, just in case * this method is not empty. * @pre $none * @post $none */ protected void registerOtherEntity() { double resTimeFail = getNextFailureTimeSample(); // the time when we will decide when a resource will fail // Now, schedule an event to this entity, so that when that event // happens, RegionalGISWithFailure will // initiate the process to decide when a res will fail, which resource // will fail and how long the failure will last. // Then, it will send the failure signal // to the resource. super.send(super.get_id(), resTimeFail, GridSimTags.GRIDRESOURCE_FAILURE); /**************/ if (record_ == true) { System.out.println(super.get_name() + ": sends an autogenerated GRIDRESOURCE_FAILURE to itself."+ " Clock(): " + GridSim.clock() + ". resTimeFail: " + resTimeFail + " seconds"); } /***************/ // Now, we have to start the polling functionality super.send(super.get_id(), GridSimTags.POLLING_TIME_GIS, GridSimTags.GRIDRESOURCE_POLLING); } /** * Informs the registered entities regarding to the end of a simulation.<br> * NOTE: This method can be overridden by its subclasses, provided * that they call this method first. This is required, just in case * this method is not empty. * @pre $none * @post $none */ protected void processEndSimulation() { resList_.clear(); arList_.clear(); if (regionalList_ != null) { regionalList_.clear(); } if (globalResList_ != null) { globalResList_.clear(); } if (globalResARList_ != null) { globalResARList_.clear(); } if (userList_ != null) { userList_.clear(); } if (userARList_ != null) { userARList_.clear(); } } /** * Sets failure generators for this entity. * @param failureNumResPattern to decide on how many resources will fail * @param failureTimePattern to decide on when the fail will be * @param failureLengthPattern to decide on how long the fail will be * @return <tt>true</tt> if successful, <tt>false</tt> otherwise */ public boolean setFailureGenerator(DiscreteGenerator failureNumResPattern, DiscreteGenerator failureTimePattern, DiscreteGenerator failureLengthPattern) { if ((failureNumResPattern == null) || (failureTimePattern == null) || (failureLengthPattern == null)) { return false; } failureNumResPatternDiscrete_ = failureNumResPattern; failureTimePatternDiscrete_ = failureTimePattern; failureLengthPatternDiscrete_ = failureLengthPattern; failureNumResPatternCont_ = null; failureTimePatternCont_ = null; failureLengthPatternCont_ = null; failureNumResPatternVariate_ = null; failureTimePatternVariate_ = null; failureLengthPatternVariate_ = null; return true; } /** * Sets failure generators for this entity. * @param failureNumResPattern to decide on how many resources will fail * @param failureTimePattern to decide on when the fail will be * @param failureLengthPattern to decide on how long the fail will be * @return <tt>true</tt> if successful, <tt>false</tt> otherwise */ public boolean setFailureGenerator(ContinuousGenerator failureNumResPattern, ContinuousGenerator failureTimePattern, ContinuousGenerator failureLengthPattern) { if ((failureNumResPattern == null) || (failureTimePattern == null) || (failureLengthPattern == null)) { return false; } failureNumResPatternDiscrete_ = null; failureTimePatternDiscrete_ = null; failureLengthPatternDiscrete_ = null; failureNumResPatternCont_ = failureNumResPattern; failureTimePatternCont_ = failureTimePattern; failureLengthPatternCont_ = failureLengthPattern; failureNumResPatternVariate_ = null; failureTimePatternVariate_ = null; failureLengthPatternVariate_ = null; return true; } /** * Sets failure generators for this entity. * @param failureNumResPattern to decide on how many resources will fail * @param failureTimePattern to decide on when the fail will be * @param failureLengthPattern to decide on how long the fail will be * @return <tt>true</tt> if successful, <tt>false</tt> otherwise */ public boolean setFailureGenerator(Variate failureNumResPattern, Variate failureTimePattern, Variate failureLengthPattern) { if ((failureNumResPattern == null) || (failureTimePattern == null) || (failureLengthPattern == null)) { return false; } failureNumResPatternDiscrete_ = null; failureTimePatternDiscrete_ = null; failureLengthPatternDiscrete_ = null; failureNumResPatternCont_ = null; failureTimePatternCont_ = null; failureLengthPatternCont_ = null; failureNumResPatternVariate_ = failureNumResPattern; failureTimePatternVariate_ = failureTimePattern; failureLengthPatternVariate_ = failureLengthPattern; return true; } /** * This function returns the next sample for the number of resources * which will fail. * We take into account whether the pattern for this value is * discrete or continuous. * @return the sample for the number of resources which will fail */ protected double getNextFailureNumResSample() { double sample; if (failureNumResPatternDiscrete_ != null) { sample = failureNumResPatternDiscrete_.sample(); return Math.abs(sample); } else if (failureNumResPatternCont_ != null) { sample = failureNumResPatternCont_.sample(); return Math.abs(sample); } else if (failureNumResPatternVariate_ != null) { sample = failureNumResPatternVariate_.gen(); return Math.abs(sample); } else return -1; } /** * This function returns the next sample for the time when resources * will fail. * We take into account whether the pattern for this value is * discrete or continuous. * @return the sample for the time when resources will fail */ protected double getNextFailureTimeSample() { double sample; if (failureTimePatternDiscrete_ != null) { sample = failureTimePatternDiscrete_.sample(); return Math.abs(sample); } else if (failureTimePatternCont_ != null) { sample = failureTimePatternCont_.sample(); return Math.abs(sample); } else if (failureTimePatternVariate_ != null) { sample = failureTimePatternVariate_.gen(); return Math.abs(sample); } else return -1; } /** * This function returns the following sample for the time * when resources will fail. * We take into account whether the pattern for this value is * discrete or continuous. * @return the sample for the time when resources will fail */ protected double getNextFailureLengthSample() { double sample; if (failureLengthPatternDiscrete_ != null) { sample = failureLengthPatternDiscrete_.sample(); return Math.abs(sample); } else if (failureLengthPatternCont_ != null) { sample = failureLengthPatternCont_.sample(); return Math.abs(sample); } else if (failureLengthPatternVariate_ != null) { sample = failureLengthPatternVariate_.gen(); return Math.abs(sample); } else return -1; } /** * This function returns the following sample for the number of * machines which will fail in a resource. * We reuse the same pattern used for the number of resources which * will fail. * We take into account whether the pattern for this value is * discrete or continuous. * @return the sample for the number of machines which will fail * in a resource */ protected double getNextNumMachinesFailedSample() { return getNextFailureNumResSample(); } /** * Gets a ResourceCharacteristics object for a given GridResource ID. <br> * NOTE: This method returns a reference of ResourceCharacteristics object, * NOT a copy of it. As a result, some of ResourceCharacteristics * attributes, such as {@link gridsim.PE} availability might * change over time. * Use {@link gridsim.GridSim#getNumFreePE(int)} * to determine number of free PE at the time of a request instead. * * This function is copied from {@link gridsim.GridSim} class. * * @param resourceID the resource ID * @return An object of ResourceCharacteristics or <tt>null</tt> if a * GridResource doesn't exist or an error occurs * @see gridsim.ResourceCharacteristics * @pre resourceID > 0 * @post $none */ private ResourceCharacteristics getResourceCharacteristics(int resourceID) { // Get Resource Characteristic Info: Send Request and Receive Event/Msg send(super.output, 0.0, GridSimTags.RESOURCE_CHARACTERISTICS, new IO_data( new Integer(super.get_id()), 12, resourceID) ); try { // waiting for a response from system GIS Sim_type_p tag=new Sim_type_p(GridSimTags.RESOURCE_CHARACTERISTICS); // only look for this type of ack Sim_event ev = new Sim_event(); super.sim_get_next(tag, ev); return (ResourceCharacteristics) ev.get_data(); } catch (Exception e) { System.out.println(super.get_name() + ".getResourceCharacteristics(): Exception error."); } return null; } /** * This function is to poll the resources in order to check whether * they are failed or not * @return true if everything works well */ protected boolean pollResource(int resID) { if (resID < 0) { System.out.println(super.get_name() + ".pollResource(): Error - " + "invalid entity ID or name."); return false; } AvailabilityInfo resAv = new AvailabilityInfo(resID, super.get_id()); // send this to the resource send(this.output, GridSimTags.SCHEDULE_NOW, GridSimTags.GRIDRESOURCE_FAILURE_INFO, new IO_data(resAv, Link.DEFAULT_MTU, resID)); return true; } /** * This function is to receive back the polls from the resources * @return a AvailabilityInfo object */ protected AvailabilityInfo pollReturn() { Sim_event ev = new Sim_event(); // waiting for a response from the GridResource Sim_type_p tag = new Sim_type_p(GridSimTags.GRIDRESOURCE_FAILURE_INFO); // only look for this type of ack super.sim_get_next(tag, ev); AvailabilityInfo resAv = null; try { resAv = (AvailabilityInfo) ev.get_data(); } catch (Sim_exception sim) { System.out.print(super.get_name() + ".pollReturn(): Error - "); System.out.println("exception occurs. See the below message:"); System.out.println(sim.getMessage()); resAv = null; } catch (Exception e) { System.out.print(super.get_name() + ".pollReturn(): Error - "); System.out.println("exception occurs. See the below message:"); System.out.println(e.getMessage()); resAv = null; } return resAv; }} // end class
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -