1. /*
  2. * Title: CloudSim Toolkit
  3. * Description: CloudSim (Cloud Simulation) Toolkit for Modeling and Simulation of Clouds
  4. * Licence: GPL - http://www.gnu.org/copyleft/gpl.html
  5. *
  6. * Copyright (c) 2009-2010, The University of Melbourne, Australia
  7. */
  8.  
  9. package org.cloudbus.cloudsim;
  10.  
  11. import java.text.DecimalFormat;//小数的 十进制的
  12. import java.util.ArrayList;//数组
  13. import java.util.LinkedList;//链接表
  14. import java.util.List;//java.util集合框架、遗留的 collection 类、事件模型、日期和时间设施、国际化和各种实用工具类
  15.  
  16. import org.cloudbus.cloudsim.core.CloudSim;
  17.  
  18. /**
  19. * Cloudlet is an extension to the cloudlet. It stores, despite all the information
  20. * encapsulated in the Cloudlet, the ID of the VM running it.
  21. *
  22. * @author Rodrigo N. Calheiros
  23. * @author Anton Beloglazov
  24. * @since CloudSim Toolkit 1.0
  25. */
  26. public class Cloudlet {
  27.  
  28. // the User or Broker ID. It is advisable that broker set this ID
  29. // with its own ID, so that CloudResource returns to it after the execution
  30. /** The user id. */ //用户ID
  31. private int userId;
  32.  
  33. // the size of this Cloudlet to be executed in a CloudResource (unit: in MI)
  34. /** The cloudlet length. */ //云任务长度 单位:MI
  35. private long cloudletLength;
  36.  
  37. // the input file size of this Cloudlet before execution (unit: in byte)
  38. /** The cloudlet file size. */ //云任务文件大小 单位:字节
  39. private final long cloudletFileSize; // in byte = program + input data size //字节=程序+输入数据大小
  40.  
  41. // the output file size of this Cloudlet after execution (unit: in byte)
  42. /** The cloudlet output size. */ //云任务输出文件大小
  43. private final long cloudletOutputSize;
  44.  
  45. /** The pes number. *///执行任务请求的PE数
  46. private int pesNumber; // num of Pe required to execute this job
  47.  
  48. /** The cloudlet id. */ //云任务ID
  49. private final int cloudletId; // this Cloudlet ID
  50.  
  51. /** The status. */ //云任务状态
  52. private int status; // status of this Cloudlet
  53.  
  54. /** The num. */ //十进制格式
  55. private DecimalFormat num; // to format the decimal number
  56.  
  57. /** The finish time. */ //云任务完成时间
  58. private double finishTime; // the time where this Cloudlet completes
  59.  
  60. // start time of executing this Cloudlet.
  61. // With new functionalities, such as CANCEL, PAUSED and RESUMED, this
  62. // attribute only stores the latest execution time. Previous execution time
  63. // are ignored.
  64. /** The exec start time. */ //执行仿真开始时间
  65. private double execStartTime; // in simulation time
  66.  
  67. /** The reservation id. */ //云任务预约ID 资源的ID?(预约资源)
  68. private int reservationId = -1; // the ID of a reservation made for this cloudlet
  69.  
  70. // records the transaction history for this Cloudlet //记录云任务的交易历史
  71. /** The record. */ //是否记录?
  72. private final boolean record; // record a history or not
  73.  
  74. /** The newline. */ //换行?
  75. private String newline;
  76.  
  77. /** The history. */ //交易历史  String类是字符串常量,是不可更改的常量。而StringBuffer是字符串变量,它的对象是可以扩充和修改的
  78. private StringBuffer history;
  79.  
  80. /** The res list. */ //资源列表?
  81. private final List<Resource> resList;
  82.  
  83. /** The index. */ //索引
  84. private int index;
  85.  
  86. // differentiated service 不同的服务
  87. /** The class type. */ //云任务类别
  88. private int classType; // class type of Cloudlet for resource scheduling
  89.  
  90. /** The net to s. */ //TOS(terms of service)服务条款 ?
  91. private int netToS; // ToS for sending Cloudlet over the network
  92.  
  93. //私有访问控制符private 只能被该类自身所访问和修改,而且不能被任何其他类(包括该类的子类)来获取和引用。private修饰符用来声明那些类的私有成员,它提供了最高的保护级别
  94. ////////////////////////////////////////////
  95. // Below are CONSTANTS attributes 以下是常量属性
  96. /** The Cloudlet has been created and added to the CloudletList object. */
  97. public static final int CREATED = 0;//云任务创建并加入云任务列表对象
  98.  
  99. /** The Cloudlet has been assigned to a CloudResource object as planned. */
  100. public static final int READY = 1; //云任务按照计划分配给资源
  101.  
  102. /** The Cloudlet has moved to a Cloud node. */
  103. public static final int QUEUED = 2; //云任务提交给一个【云节点】 虚拟机吗??
  104.  
  105. /** The Cloudlet is in execution in a Cloud node. */
  106. public static final int INEXEC = 3; //云任务执行
  107.  
  108. /** The Cloudlet has been executed successfully. */
  109. public static final int SUCCESS = 4; //云任务成功执行
  110.  
  111. /** The Cloudlet is failed. */
  112. public static final int FAILED = 5; //执行失败
  113.  
  114. /** The Cloudlet has been canceled. */
  115. public static final int CANCELED = 6; //云任务被取消
  116.  
  117. /** The Cloudlet has been paused. It can be resumed by changing the status into <tt>RESUMED</tt>. */
  118. public static final int PAUSED = 7; //云任务执行暂停
  119.  
  120. /** The Cloudlet has been resumed from <tt>PAUSED</tt> state. */
  121. public static final int RESUMED = 8; //重启执行云任务
  122.  
  123. /** The cloudlet has failed due to a resource failure. */
  124. public static final int FAILED_RESOURCE_UNAVAILABLE = 9;//由于资源失败 云任务失败
  125.  
  126. //公有访问控制符public Java的类是通过包的概念来组织的,包是类的一个松散的集合。具有了被其他包中的类访问的可能性,只要这些其他包中的类在程序中使用import语句引入public类,就可以访问和引用这个类
  127. /** The vm id. */ //虚拟机编号
  128. protected int vmId;
  129.  
  130. /** The cost per bw. */ //带宽费用
  131. protected double costPerBw;
  132.  
  133. /** The accumulated bw cost. */ //累计的带宽费用
  134. protected double accumulatedBwCost;
  135.  
  136. //protected 被三种类所引用:该类自身、与它在同一个包中的其它类、在其他包中的该类的子类。使用protected修饰符的主要作用是允许其他包中该类的子类来访问父类的特定属性。
  137.  
  138. // Utilization 【利用率】
  139.  
  140. /** The utilization of cpu model. */ //CPU利用模型
  141. private UtilizationModel utilizationModelCpu;
  142.  
  143. /** The utilization of memory model. */ //memory利用模型
  144. private UtilizationModel utilizationModelRam;
  145.  
  146. /** The utilization of bw model. */ //BW利用模型
  147. private UtilizationModel utilizationModelBw;
  148.  
  149. // Data cloudlet 数据 云任务 ???
  150. /** The required files. */ //请求的文件
  151. private List<String> requiredFiles = null; // list of required filenames
  152.  
  153. /**【分配一个新的云任务对象】
  154. * Allocates a new Cloudlet object. The Cloudlet length, input and output
  155. * file sizes should be greater than or equal to 1.
  156. * By default this constructor sets the history of this object.
  157. *
  158. * @param cloudletId the unique ID of this Cloudlet
  159. * @param cloudletLength the length or size (in MI) of this cloudlet
  160. * to be executed in a PowerDatacenter
  161. * @param cloudletFileSize the file size (in byte) of this cloudlet
  162. * <tt>BEFORE</tt> submitting to a PowerDatacenter
  163. * @param cloudletOutputSize the file size (in byte) of this cloudlet
  164. * <tt>AFTER</tt> finish executing by
  165. * a PowerDatacenter
  166. * @param pesNumber the pes number
  167. * @param utilizationModelCpu the utilization model cpu
  168. * @param utilizationModelRam the utilization model ram
  169. * @param utilizationModelBw the utilization model bw
  170. *
  171. * @pre cloudletID >= 0
  172. * @pre cloudletLength >= 0.0
  173. * @pre cloudletFileSize >= 1
  174. * @pre cloudletOutputSize >= 1
  175. * @post $none
  176. */
  177. public Cloudlet(
  178. final int cloudletId, //加了一个final表示不能修改传入的参数的值
  179. final long cloudletLength,
  180. final int pesNumber,
  181. final long cloudletFileSize,
  182. final long cloudletOutputSize,
  183. final UtilizationModel utilizationModelCpu,
  184. final UtilizationModel utilizationModelRam,
  185. final UtilizationModel utilizationModelBw) {
  186. this(cloudletId, cloudletLength, pesNumber, cloudletFileSize, cloudletOutputSize, utilizationModelCpu, utilizationModelRam, utilizationModelBw, true);
  187. this.vmId=-1;
  188. this.accumulatedBwCost=0.0;
  189. this.costPerBw=0.0;
  190.  
  191. this.requiredFiles = new LinkedList<String>();
  192. }//this通常指当前对象 引用当前对象的某种东西,比如当前对象的某个方法,或当前对象的某个成员,你便可以利用this来实现这个目的,this的另一个用途是调用当前对象的另一个构造函数
  193.  
  194. /**
  195. * Allocates a new Cloudlet object. The Cloudlet length, input and output
  196. * file sizes should be greater than or equal to 1.
  197. *
  198. * @param cloudletId the unique ID of this cloudlet
  199. * @param cloudletLength the length or size (in MI) of this cloudlet
  200. * to be executed in a PowerDatacenter
  201. * @param cloudletFileSize the file size (in byte) of this cloudlet
  202. * <tt>BEFORE</tt> submitting to a PowerDatacenter
  203. * @param cloudletOutputSize the file size (in byte) of this cloudlet
  204. * <tt>AFTER</tt> finish executing by
  205. * a PowerDatacenter
  206. * @param record record the history of this object or not
  207. * @param fileList list of files required by this cloudlet
  208. * @param pesNumber the pes number
  209. * @param utilizationModelCpu the utilization model cpu
  210. * @param utilizationModelRam the utilization model ram
  211. * @param utilizationModelBw the utilization model bw
  212. *
  213. * @pre cloudletID >= 0
  214. * @pre cloudletLength >= 0.0
  215. * @pre cloudletFileSize >= 1
  216. * @pre cloudletOutputSize >= 1
  217. * @post $none
  218. */
  219. public Cloudlet(
  220. final int cloudletId,
  221. final long cloudletLength,
  222. final int pesNumber,
  223. final long cloudletFileSize,
  224. final long cloudletOutputSize,
  225. final UtilizationModel utilizationModelCpu,
  226. final UtilizationModel utilizationModelRam,
  227. final UtilizationModel utilizationModelBw,
  228. final boolean record,
  229. final List<String> fileList) {
  230. this(cloudletId, cloudletLength, pesNumber, cloudletFileSize, cloudletOutputSize, utilizationModelCpu, utilizationModelRam, utilizationModelBw, record);
  231. this.vmId=-1;
  232. this.accumulatedBwCost=0.0;//统计的带宽费用
  233. this.costPerBw=0.0;
  234.  
  235. this.requiredFiles = fileList;
  236. } //与上一个对象大部分一样!
  237.  
  238. /**
  239. * Allocates a new Cloudlet object. The Cloudlet length, input and output
  240. * file sizes should be greater than or equal to 1.
  241. * By default this constructor sets the history of this object.
  242. *
  243. * @param cloudletId the unique ID of this Cloudlet
  244. * @param cloudletLength the length or size (in MI) of this cloudlet
  245. * to be executed in a PowerDatacenter
  246. * @param cloudletFileSize the file size (in byte) of this cloudlet
  247. * <tt>BEFORE</tt> submitting to a PowerDatacenter
  248. * @param cloudletOutputSize the file size (in byte) of this cloudlet
  249. * <tt>AFTER</tt> finish executing by
  250. * a PowerDatacenter
  251. * @param fileList list of files required by this cloudlet
  252. * @param pesNumber the pes number
  253. * @param utilizationModelCpu the utilization model cpu
  254. * @param utilizationModelRam the utilization model ram
  255. * @param utilizationModelBw the utilization model bw
  256. *
  257. * @pre cloudletID >= 0
  258. * @pre cloudletLength >= 0.0
  259. * @pre cloudletFileSize >= 1
  260. * @pre cloudletOutputSize >= 1
  261. * @post $none
  262. */
  263. public Cloudlet(
  264. final int cloudletId,
  265. final long cloudletLength,
  266. final int pesNumber,
  267. final long cloudletFileSize,
  268. final long cloudletOutputSize,
  269. final UtilizationModel utilizationModelCpu,
  270. final UtilizationModel utilizationModelRam,
  271. final UtilizationModel utilizationModelBw,
  272. final List<String> fileList) {
  273. this(cloudletId, cloudletLength, pesNumber, cloudletFileSize, cloudletOutputSize, utilizationModelCpu, utilizationModelRam, utilizationModelBw, true);
  274. this.vmId=-1;
  275. this.accumulatedBwCost=0.0;
  276. this.costPerBw=0.0;
  277.  
  278. this.requiredFiles = fileList;
  279. }
  280.  
  281. /**
  282. * Allocates a new Cloudlet object. The Cloudlet length, input and output
  283. * file sizes should be greater than or equal to 1.
  284. *
  285. * @param cloudletId the unique ID of this cloudlet
  286. * @param cloudletLength the length or size (in MI) of this cloudlet
  287. * to be executed in a PowerDatacenter
  288. * @param cloudletFileSize the file size (in byte) of this cloudlet
  289. * <tt>BEFORE</tt> submitting to a PowerDatacenter
  290. * @param cloudletOutputSize the file size (in byte) of this cloudlet
  291. * <tt>AFTER</tt> finish executing by
  292. * a PowerDatacenter
  293. * @param record record the history of this object or not
  294. * @param pesNumber the pes number
  295. * @param utilizationModelCpu the utilization model cpu
  296. * @param utilizationModelRam the utilization model ram
  297. * @param utilizationModelBw the utilization model bw
  298. *
  299. * @pre cloudletID >= 0
  300. * @pre cloudletLength >= 0.0
  301. * @pre cloudletFileSize >= 1
  302. * @pre cloudletOutputSize >= 1
  303. * @post $none
  304. */
  305. public Cloudlet(
  306. final int cloudletId,
  307. final long cloudletLength,
  308. final int pesNumber,
  309. final long cloudletFileSize,
  310. final long cloudletOutputSize,
  311. final UtilizationModel utilizationModelCpu,
  312. final UtilizationModel utilizationModelRam,
  313. final UtilizationModel utilizationModelBw,
  314. final boolean record) {
  315. this.userId = -1; // 代理或用户设置 to be set by a Broker or user
  316. this.status = CREATED; //任务状态
  317. this.cloudletId = cloudletId;
  318. this.pesNumber = pesNumber;
  319. this.execStartTime = 0.0;
  320. this.finishTime = -1.0; // 任务还没还没完成 meaning this Cloudlet hasn't finished yet
  321. this.classType = 0; //类别
  322. this.netToS = 0;
  323.  
  324. // Cloudlet length, Input and Output size should be at least 1 byte.至少一个字节
  325. this.cloudletLength = Math.max(1, cloudletLength);
  326. this.cloudletFileSize = Math.max(1, cloudletFileSize);
  327. this.cloudletOutputSize = Math.max(1, cloudletOutputSize);
  328.  
  329. // Normally, a Cloudlet is only executed on a resource without being
  330. // migrated to others. Hence, to reduce memory consumption, set the
  331. // size of this ArrayList to be less than the default one.设置内存大小数组列表小于默认值
  332. this.resList = new ArrayList<Resource>(2);
  333. this.index = -1;
  334. this.record = record;
  335.  
  336. this.vmId = -1;
  337. this.accumulatedBwCost = 0.0;
  338. this.costPerBw = 0.0;
  339.  
  340. this.requiredFiles = new LinkedList<String>();
  341.  
  342. setUtilizationModelCpu(utilizationModelCpu);
  343. setUtilizationModelRam(utilizationModelRam);
  344. setUtilizationModelBw(utilizationModelBw);
  345. }
  346.  
  347. //【内部类】
  348. //////////////////////// INTERNAL CLASS ///////////////////////////////////
  349.  
  350. /**
  351. * Internal class that keeps track Cloudlet's movement in different
  352. * CloudResources.(不同的资源中登记云任务动向)
  353. */
  354. private static class Resource {
  355.  
  356. /** Cloudlet's submission time to a CloudResource. */
  357. public double submissionTime = 0.0;//云任务的提交时间
  358.  
  359. /** The time of this Cloudlet resides in a CloudResource (from arrival time until departure time). */
  360. public double wallClockTime = 0.0; //云任务从到达到撤离时间
  361.  
  362. /** The total execution time of this Cloudlet in a CloudResource. */
  363. public double actualCPUTime = 0.0;//云任务执行时间
  364.  
  365. /** Cost per second a CloudResource charge to execute this Cloudlet. */
  366. public double costPerSec = 0.0;//云资源每秒费用
  367.  
  368. /** Cloudlet's length finished so far. */
  369. public long finishedSoFar = 0; //已完成的云任务长度
  370.  
  371. /** a CloudResource id. */
  372. public int resourceId = -1;//云资源ID
  373.  
  374. /** a CloudResource name. */
  375. public String resourceName = null;//云资源名
  376.  
  377. } // end of internal class
  378. //【结束内部类】
  379. //////////////////////// End of Internal Class //////////////////////////
  380.  
  381. /**设置预约ID
  382. * Sets the id of the reservation made for this cloudlet.
  383. *
  384. * @param resId the reservation ID
  385. *
  386. * @return <tt>true</tt> if the ID has successfully been set or
  387. * <tt>false</tt> otherwise.
  388. */
  389. public boolean setReservationId(final int resId) {//预约的ID是资源的ID?
  390. if(resId <= 0) {
  391. return false;
  392. }
  393. reservationId = resId;
  394. return true;
  395. }
  396.  
  397. /**获取预约ID
  398. * Gets the reservation ID that owns this Cloudlet.
  399. *
  400. * @return a reservation ID
  401. *
  402. * @pre $none
  403. * @post $none
  404. */
  405. public int getReservationId() {
  406. return reservationId;
  407. }
  408.  
  409. /**云任务是否通过预约来提交
  410. * Checks whether this Cloudlet is submitted by reserving or not.
  411. *
  412. * @return <tt>true</tt> if this Cloudlet has reserved before,
  413. * <tt>false</tt> otherwise
  414. */
  415. public boolean hasReserved() {
  416. if (reservationId == -1) {
  417. return false;
  418. }
  419. return true;
  420. }
  421.  
  422. /**设置云任务长度
  423. * Sets the length or size (in MI) of this Cloudlet
  424. * to be executed in a CloudResource.
  425. * This Cloudlet length is calculated for 1 Pe only <tt>not</tt> the total
  426. * length.
  427. *
  428. * @param cloudletLength the length or size (in MI) of this Cloudlet
  429. * to be executed in a CloudResource
  430. *
  431. * @return <tt>true</tt> if it is successful, <tt>false</tt> otherwise
  432. *
  433. * @pre cloudletLength > 0
  434. * @post $none
  435. */
  436. public boolean setCloudletLength(final long cloudletLength) {
  437. if (cloudletLength <= 0) {
  438. return false;
  439. }
  440.  
  441. this.cloudletLength = cloudletLength;
  442. return true;
  443. }
  444.  
  445. /**设置服务等级【可以尝试】
  446. * Sets the network service level for sending this cloudlet over a network.
  447. *
  448. * @param netServiceLevel determines the kind of service this cloudlet
  449. * receives in the network (applicable to
  450. * selected PacketScheduler class only)
  451. *
  452. * @return <code>true</code> if successful.
  453. *
  454. * @pre netServiceLevel >= 0
  455. * @post $none
  456. */
  457. public boolean setNetServiceLevel(final int netServiceLevel) {
  458. boolean success = false;
  459. if (netServiceLevel > 0) {
  460. netToS = netServiceLevel;
  461. success = true;
  462. }
  463.  
  464. return success;
  465. }
  466.  
  467. /**获取服务等级
  468. * Gets the network service level for sending this cloudlet over a network.
  469. *
  470. * @return the network service level
  471. *
  472. * @pre $none
  473. * @post $none
  474. */
  475. public int getNetServiceLevel() {
  476. return netToS;
  477. }
  478.  
  479. /**获取云任务等待时间
  480. * Gets the waiting time of this cloudlet executed on a resource.
  481. *
  482. * @return the waiting time
  483. *
  484. * @pre $none
  485. * @post $none
  486. */
  487. public double getWaitingTime() {
  488. if (index == -1) {
  489. return 0;
  490. }
  491.  
  492. // use the latest resource submission time
  493. final double subTime = resList.get(index).submissionTime;
  494. return execStartTime - subTime;//执行开始时间-提交时间
  495. }
  496.  
  497. /**任务类别(优先权)【尝试扩展使用】
  498. * Sets the classType or priority of this Cloudlet for scheduling on a
  499. * resource.
  500. *
  501. * @param classType classType of this Cloudlet
  502. *
  503. * @return <tt>true</tt> if it is successful, <tt>false</tt> otherwise
  504. *
  505. * @pre classType > 0
  506. * @post $none
  507. */
  508. public boolean setClassType(final int classType) {
  509. boolean success = false;
  510. if (classType > 0) {
  511. this.classType = classType;
  512. success = true;
  513. }
  514.  
  515. return success;
  516. }
  517.  
  518. /**获取任务类别(优先权)
  519. * Gets the classtype or priority of this Cloudlet for scheduling on a
  520. * resource.
  521. *
  522. * @return classtype of this cloudlet
  523. *
  524. * @pre $none
  525. * @post $none
  526. */
  527. public int getClassType() {
  528. return classType;
  529. }
  530.  
  531. /**任务请求的PE
  532. * Sets the number of PEs required to run this Cloudlet. <br>
  533. * NOTE: The Cloudlet length is computed only for 1 Pe for simplicity. <br>
  534. * For example, this Cloudlet has a length of 500 MI and requires 2 PEs.
  535. * This means each Pe will execute 500 MI of this Cloudlet.每个PE都执行500 不是各分担250???
  536. *
  537. * @param pesNumber number of Pe
  538. *
  539. * @return <tt>true</tt> if it is successful, <tt>false</tt> otherwise
  540. *
  541. * @pre numPE > 0
  542. * @post $none
  543. */
  544. public boolean setPesNumber(final int pesNumber) {
  545. if (pesNumber > 0) {
  546. this.pesNumber = pesNumber;
  547. return true;
  548. }
  549. return false;
  550. }
  551.  
  552. /**
  553. * Gets the number of PEs required to run this Cloudlet.
  554. *
  555. * @return number of PEs
  556. *
  557. * @pre $none
  558. * @post $none
  559. */
  560. public int getPesNumber() {
  561. return pesNumber;
  562. }
  563.  
  564. /**云任务历史记录
  565. * Gets the history of this Cloudlet. The layout of this history is in a
  566. * readable table column with <tt>time</tt> and <tt>description</tt>
  567. * as headers.
  568. *
  569. * @return a String containing the history of this Cloudlet object.
  570. *
  571. * @pre $none
  572. * @post $result != null
  573. */
  574. public String getCloudletHistory() {
  575. String msg = null;
  576. if (history == null) {
  577. msg = "No history is recorded for Cloudlet #" + cloudletId;
  578. } else {
  579. msg = history.toString();
  580. }
  581.  
  582. return msg;
  583. }
  584.  
  585. /**任务已执行长度(适合 迁移任务或取消)
  586. * Gets the length of this Cloudlet that has been executed so far
  587. * from the latest CloudResource. This
  588. * method is useful when trying to move this Cloudlet into different
  589. * CloudResources or to cancel it.
  590. *
  591. * @return the length of a partially executed Cloudlet or the full Cloudlet
  592. * length if it is completed
  593. *
  594. * @pre $none
  595. * @post $result >= 0.0
  596. */
  597. public long getCloudletFinishedSoFar() {
  598. if (index == -1) {
  599. return cloudletLength;
  600. }
  601.  
  602. final long finish = resList.get(index).finishedSoFar;//resList 资源列表?
  603. if (finish > cloudletLength) {
  604. return cloudletLength;
  605. }
  606.  
  607. return finish;
  608. }
  609.  
  610. /**检验云任务是否执行完毕
  611. * Checks whether this Cloudlet has finished execution or not.
  612. *
  613. * @return <tt>true</tt> if this Cloudlet has finished execution,
  614. * <tt>false</tt> otherwise
  615. *
  616. * @pre $none
  617. * @post $none
  618. */
  619. public boolean isFinished() {
  620. if (index == -1) {
  621. return false;
  622. }
  623.  
  624. boolean completed = false;
  625.  
  626. // if result is 0 or -ve then this Cloudlet has finished
  627. final long finish = resList.get(index).finishedSoFar;
  628. final long result = cloudletLength - finish;
  629. if (result <= 0.0) {
  630. completed = true;
  631. }
  632.  
  633. return completed;
  634. }
  635.  
  636. /**设置任务执行长度
  637. * Sets the length of this Cloudlet that has been executed so far.
  638. * This method is used by ResCloudlet class when an application
  639. * is decided to cancel or to move this Cloudlet into different
  640. * CloudResources.
  641. *
  642. * @param length length of this Cloudlet
  643. *
  644. * @see gridsim.AllocPolicy
  645. * @see gridsim.ResCloudlet
  646. * @pre length >= 0.0
  647. * @post $none
  648. */
  649. public void setCloudletFinishedSoFar(final long length) {
  650. // if length is -ve then ignore
  651. if (length < 0.0 || index < 0) {
  652. return;
  653. }
  654.  
  655. final Resource res = resList.get(index);
  656. res.finishedSoFar = length;
  657.  
  658. if (record) {
  659. write("Sets the length's finished so far to " + length);
  660. }
  661. }
  662.  
  663. /**设置用户ID
  664. * Sets the user or owner ID of this Cloudlet. It is <tt>VERY</tt> important
  665. * to set the user ID, otherwise this Cloudlet will not be executed in a
  666. * CloudResource.
  667. *
  668. * @param id the user ID
  669. *
  670. * @pre id >= 0
  671. * @post $none
  672. */
  673. public void setUserId(final int id) {
  674. userId = id;
  675. if (record) {
  676. write("Assigns the Cloudlet to " + CloudSim.getEntityName(id) + " (ID #" + id + ")");
  677. }
  678. }
  679.  
  680. /**
  681. * Gets the user or owner ID of this Cloudlet.
  682. *
  683. * @return the user ID or <tt>-1</tt> if the user ID has not been set before
  684. *
  685. * @pre $none
  686. * @post $result >= -1
  687. */
  688. public int getUserId() {
  689. return userId;
  690. }
  691.  
  692. /**资源ID
  693. * Gets the latest resource ID that processes this Cloudlet.
  694. *
  695. * @return the resource ID or <tt>-1</tt> if none
  696. *
  697. * @pre $none
  698. * @post $result >= -1
  699. */
  700. public int getResourceId() {
  701. if (index == -1) {
  702. return -1;
  703. }
  704. return resList.get(index).resourceId;
  705. }
  706.  
  707. /**获取输入文件大小
  708. * Gets the input file size of this Cloudlet <tt>BEFORE</tt>
  709. * submitting to a CloudResource.
  710. *
  711. * @return the input file size of this Cloudlet
  712. *
  713. * @pre $none
  714. * @post $result >= 1
  715. */
  716. public long getCloudletFileSize() {
  717. return cloudletFileSize;
  718. }
  719.  
  720. /**获取输出文件大小
  721. * Gets the output size of this Cloudlet <tt>AFTER</tt> submitting and
  722. * executing to a CloudResource.
  723. *
  724. * @return the Cloudlet output file size
  725. *
  726. * @pre $none
  727. * @post $result >= 1
  728. */
  729. public long getCloudletOutputSize() {
  730. return cloudletOutputSize;
  731. }
  732.  
  733. /**通过资源实体设置资源参数
  734. * Sets the resource parameters for which this Cloudlet is going to be
  735. * executed. <br>
  736. * NOTE: This method <tt>should</tt> be called only by a 【resource entity】,
  737. * not the user or owner of this Cloudlet.
  738. *
  739. * @param resourceID the CloudResource ID
  740. * @param cost the cost running this CloudResource per second
  741. *
  742. * @pre resourceID >= 0
  743. * @pre cost > 0.0
  744. * @post $none
  745. */
  746. public void setResourceParameter(final int resourceID, final double cost) {
  747. final Resource res = new Resource();
  748. res.resourceId = resourceID;
  749. res.costPerSec = cost;
  750. res.resourceName = CloudSim.getEntityName(resourceID);
  751.  
  752. // add into a list if moving to a new grid resource
  753. resList.add(res);
  754.  
  755. if (index == -1 && record) {
  756. write("Allocates this Cloudlet to " + res.resourceName + " (ID #" + resourceID + ") with cost = $" + cost + "/sec");
  757. } else if (record) {
  758. final int id = resList.get(index).resourceId;
  759. final String name = resList.get(index).resourceName;
  760. write("Moves Cloudlet from " + name + " (ID #" + id + ") to " +
  761. res.resourceName + " (ID #" + resourceID +
  762. ") with cost = $" + cost + "/sec");
  763. }
  764.  
  765. index++; // initially, index = -1
  766. }
  767.  
  768. /**设置 提交 到达 时间
  769. * Sets the submission or arrival time of this Cloudlet into a CloudResource.
  770. *
  771. * @param clockTime 提交时间 the submission time
  772. *
  773. * @pre clockTime >= 0.0
  774. * @post $none
  775. */
  776. public void setSubmissionTime(final double clockTime) {
  777. if (clockTime < 0.0 || index < 0) {
  778. return;
  779. }
  780.  
  781. final Resource res = resList.get(index);
  782. res.submissionTime = clockTime;
  783.  
  784. if (record) {
  785. write( "Sets the submission time to " + num.format(clockTime) );
  786. }
  787. }
  788.  
  789. /**
  790. * Gets the submission or arrival time of this Cloudlet from
  791. * the latest CloudResource.
  792. *
  793. * @return the submission time or <tt>0.0</tt> if none
  794. *
  795. * @pre $none
  796. * @post $result >= 0.0
  797. */
  798. public double getSubmissionTime() {
  799. if (index == -1) {
  800. return 0.0;
  801. }
  802. return resList.get(index).submissionTime;
  803. }
  804.  
  805. /**设置执行开始时间 (取消 暂停 重启)
  806. * Sets the execution start time of this Cloudlet inside a CloudResource.
  807. * <b>NOTE:</b> With new functionalities, such as being able to cancel /
  808. * to pause / to resume this Cloudlet, the execution start time only holds
  809. * the latest one. Meaning, all previous execution start time are ignored.
  810. *
  811. * @param clockTime the latest execution start time
  812. *
  813. * @pre clockTime >= 0.0
  814. * @post $none
  815. */
  816. public void setExecStartTime(final double clockTime) {
  817. execStartTime = clockTime;
  818. if (record) {
  819. write("Sets the execution start time to " + num.format(clockTime));
  820. }
  821. }
  822.  
  823. /**
  824. * Gets the latest execution start time.
  825. *
  826. * @return the latest execution start time
  827. *
  828. * @pre $none
  829. * @post $result >= 0.0
  830. */
  831. public double getExecStartTime() {
  832. return execStartTime;
  833. }
  834.  
  835. /**云任务执行参数设置
  836. * Sets this Cloudlet's execution parameters. These parameters are set by
  837. * the CloudResource before departure or sending back to the original
  838. * Cloudlet's owner.
  839. *
  840. * @param wallTime (云任务停留时间) the time of this Cloudlet resides in
  841. * a CloudResource (from arrival time until
  842. * departure time).
  843. * @param actualTime (执行时间) the total execution time of this Cloudlet in a
  844. * CloudResource.
  845. *
  846. * @pre wallTime >= 0.0
  847. * @pre actualTime >= 0.0
  848. * @post $none
  849. */
  850. public void setExecParam(final double wallTime, final double actualTime) {
  851. if (wallTime < 0.0 || actualTime < 0.0 || index < 0) {
  852. return;
  853. }
  854.  
  855. final Resource res = resList.get(index);
  856. res.wallClockTime = wallTime;
  857. res.actualCPUTime = actualTime;
  858.  
  859. if (record) {
  860. write("Sets the wall clock time to "+ num.format(wallTime)+
  861. " and the actual CPU time to " + num.format(actualTime));
  862. }
  863. }
  864.  
  865. /**云任务状态设置
  866. * Sets the status code of this Cloudlet.
  867. *
  868. * @param newStatus the status code of this Cloudlet
  869. *
  870. * @throws Exception Invalid range of Cloudlet status
  871. *
  872. * @pre newStatus >= 0 && newStatus <= 8
  873. * @post $none
  874. */
  875. public void setCloudletStatus(final int newStatus) throws Exception {
  876. // if the new status is same as current one, then ignore the rest
  877. if (status == newStatus) {
  878. return;
  879. }
  880.  
  881. // throws an exception if the new status is outside the range
  882. if (newStatus < Cloudlet.CREATED || newStatus > Cloudlet.FAILED_RESOURCE_UNAVAILABLE) {
  883. throw new Exception("Cloudlet.setCloudletStatus() : Error - Invalid integer range for Cloudlet status.");
  884. }//newStatus Cloudlet.CREATED 有可比性
  885.  
  886. if (newStatus == Cloudlet.SUCCESS) {
  887. finishTime = CloudSim.clock();
  888. }
  889.  
  890. if (record) {
  891. write("Sets Cloudlet status from " + getCloudletStatusString() + " to " + Cloudlet.getStatusString(newStatus));
  892. }
  893.  
  894. this.status = newStatus;
  895. }
  896.  
  897. /**
  898. * Gets the status code of this Cloudlet.
  899. *
  900. * @return the status code of this Cloudlet
  901. *
  902. * @pre $none
  903. * @post $result >= 0
  904. */
  905. public int getCloudletStatus() {
  906. return status;
  907. }
  908.  
  909. /**代表此刻云任务状态
  910. * Gets the string representation of the current Cloudlet status code.
  911. *
  912. * @return the Cloudlet status code as a string or <tt>null</tt> if the
  913. * status code is unknown
  914. *
  915. * @pre $none
  916. * @post $none
  917. */
  918. public String getCloudletStatusString() {
  919. return Cloudlet.getStatusString(status);
  920. }
  921.  
  922. /**
  923. * Gets the string representation of the given Cloudlet status code.
  924. *
  925. * @param status the Cloudlet status code
  926. *
  927. * @return the Cloudlet status code as a string or <tt>null</tt> if the
  928. * status code is unknown
  929. *
  930. * @pre $none
  931. * @post $none
  932. */
  933. public static String getStatusString(final int status) {
  934. String statusString = null;
  935. switch (status)
  936. {
  937. case Cloudlet.CREATED://创建
  938. statusString = "Created";
  939. break;
  940.  
  941. case Cloudlet.READY://准备
  942. statusString = "Ready";
  943. break;
  944.  
  945. case Cloudlet.INEXEC://执行
  946. statusString = "InExec";
  947. break;
  948.  
  949. case Cloudlet.SUCCESS://成功
  950. statusString = "Success";
  951. break;
  952.  
  953. case Cloudlet.QUEUED://排队等候
  954. statusString = "Queued";
  955. break;
  956.  
  957. case Cloudlet.FAILED://失败
  958. statusString = "Failed";
  959. break;
  960.  
  961. case Cloudlet.CANCELED://取消
  962. statusString = "Canceled";
  963. break;
  964.  
  965. case Cloudlet.PAUSED://暂停
  966. statusString = "Paused";
  967. break;
  968.  
  969. case Cloudlet.RESUMED://重启
  970. statusString = "Resumed";
  971. break;
  972.  
  973. case Cloudlet.FAILED_RESOURCE_UNAVAILABLE ://无可用资源
  974. statusString = "Failed_resource_unavailable";
  975. break;
  976.  
  977. default:
  978. break;
  979. }
  980.  
  981. return statusString;
  982. }
  983.  
  984. /**获取云任务长度
  985. * Gets the length of this Cloudlet.
  986. *
  987. * @return the length of this Cloudlet
  988. *
  989. * @pre $none
  990. * @post $result >= 0.0
  991. */
  992. public long getCloudletLength() {
  993. return cloudletLength;
  994. }
  995.  
  996. /**获取任务总长度
  997. * Gets the total length (across all PEs) of this Cloudlet.
  998. *
  999. * @return the total length of this Cloudlet
  1000. *
  1001. * @pre $none
  1002. * @post $result >= 0.0
  1003. */
  1004. public long getCloudletTotalLength() {
  1005. return getCloudletLength() * getPesNumber();//为什么乘以PE数
  1006. }
  1007.  
  1008. /**云资源上的执行费用
  1009. * Gets the cost running this Cloudlet in the latest CloudResource.
  1010. *
  1011. * @return the cost associated with running this Cloudlet
  1012. * or <tt>0.0</tt> if none
  1013. *
  1014. * @pre $none
  1015. * @post $result >= 0.0
  1016. */
  1017. public double getCostPerSec() {
  1018. if (index == -1) {
  1019. return 0.0;
  1020. }
  1021. return resList.get(index).costPerSec;
  1022. }
  1023.  
  1024. /**云任务停留时间在最近的云资源上 (云资源 是指 虚拟机??)
  1025. * Gets the time of this Cloudlet resides in the latest CloudResource
  1026. * (from arrival time until departure time).
  1027. *
  1028. * @return the time of this Cloudlet resides in a CloudResource
  1029. *
  1030. * @pre $none
  1031. * @post $result >= 0.0
  1032. */
  1033. public double getWallClockTime() {
  1034. if (index == -1) {
  1035. return 0.0;
  1036. }
  1037. return resList.get(index).wallClockTime;
  1038. }
  1039.  
  1040. /**执行云任务的所有资源名称
  1041. * Gets all the CloudResource names that executed this Cloudlet.
  1042. *
  1043. * @return an array of CloudResource names or <tt>null</tt> if it has none
  1044. *
  1045. * @pre $none
  1046. * @post $none
  1047. */
  1048. public String[] getAllResourceName() {
  1049. final int size = resList.size();
  1050. String[] data = null;
  1051.  
  1052. if (size > 0) {
  1053. data = new String[size];
  1054. for (int i = 0; i < size; i++) {
  1055. data[i] = resList.get(i).resourceName;
  1056. }
  1057. }
  1058.  
  1059. return data;
  1060. }
  1061.  
  1062. /**执行云任务的所有资源ID号
  1063. * Gets all the CloudResource IDs that executed this Cloudlet.
  1064. *
  1065. * @return an array of CloudResource IDs or <tt>null</tt> if it has none
  1066. *
  1067. * @pre $none
  1068. * @post $none
  1069. */
  1070. public int[] getAllResourceId() {
  1071. final int size = resList.size();
  1072. int[] data = null;
  1073.  
  1074. if (size > 0) {
  1075. data = new int[size];
  1076. for (int i = 0; i < size; i++) {
  1077. data[i] = resList.get(i).resourceId;
  1078. }
  1079. }
  1080.  
  1081. return data;
  1082. }
  1083.  
  1084. /**云任务执行的总时间
  1085. * Gets the total execution time of this Cloudlet in a given CloudResource ID.
  1086. *
  1087. * @param resId a CloudResource entity ID
  1088. *
  1089. * @return the total execution time of this Cloudlet in a CloudResource
  1090. * or <tt>0.0</tt> if not found
  1091. *
  1092. * @pre resId >= 0
  1093. * @post $result >= 0.0
  1094. */
  1095. public double getActualCPUTime(final int resId) {
  1096. Resource resource = getResourceById(resId);
  1097. if (resource != null) {
  1098. return resource.actualCPUTime;
  1099. }
  1100. return 0.0;
  1101. }
  1102.  
  1103. /**指定的资源上运行云任务的费用
  1104. * Gets the cost running this Cloudlet in a given CloudResource ID.
  1105. *
  1106. * @param resId a CloudResource entity ID
  1107. *
  1108. * @return the cost associated with running this Cloudlet
  1109. * or <tt>0.0</tt> if not found
  1110. *
  1111. * @pre resId >= 0
  1112. * @post $result >= 0.0
  1113. */
  1114. public double getCostPerSec(final int resId) {
  1115. Resource resource = getResourceById(resId);
  1116. if (resource != null) {
  1117. return resource.costPerSec;
  1118. }
  1119. return 0.0;
  1120. }
  1121.  
  1122. /**指定的资源上获取云任务已执行的长度 (取消 或 移动任务至不同的云资源)
  1123. * Gets the length of this Cloudlet that has been executed so far in a given
  1124. * CloudResource ID. This method is useful when trying to move this Cloudlet
  1125. * into different CloudResources or to cancel it.
  1126. *
  1127. * @param resId a CloudResource entity ID
  1128. *
  1129. * @return the length of a partially executed Cloudlet or the full Cloudlet
  1130. * length if it is completed or <tt>0.0</tt> if not found
  1131. *
  1132. * @pre resId >= 0
  1133. * @post $result >= 0.0
  1134. */
  1135. public long getCloudletFinishedSoFar(final int resId) {
  1136. Resource resource = getResourceById(resId);
  1137. if (resource != null) {
  1138. return resource.finishedSoFar;
  1139. }
  1140. return 0;
  1141. }
  1142.  
  1143. /**指定的资源上获取云任务提交 到达时间
  1144. * Gets the submission or arrival time of this Cloudlet in the
  1145. * given CloudResource ID.
  1146. *
  1147. * @param resId a CloudResource entity ID
  1148. *
  1149. * @return the submission time or <tt>0.0</tt> if not found
  1150. *
  1151. * @pre resId >= 0
  1152. * @post $result >= 0.0
  1153. */
  1154. public double getSubmissionTime(final int resId) {
  1155. Resource resource = getResourceById(resId);
  1156. if (resource != null) {
  1157. return resource.submissionTime;
  1158. }
  1159. return 0.0;
  1160. }
  1161.  
  1162. /**指定的资源上云任务停留的时间
  1163. * Gets the time of this Cloudlet resides in a given CloudResource ID
  1164. * (from arrival time until departure time).
  1165. *
  1166. * @param resId a CloudResource entity ID
  1167. *
  1168. * @return the time of this Cloudlet resides in the CloudResource
  1169. * or <tt>0.0</tt> if not found
  1170. *
  1171. * @pre resId >= 0
  1172. * @post $result >= 0.0
  1173. */
  1174. public double getWallClockTime(final int resId) {
  1175. Resource resource = getResourceById(resId);
  1176. if (resource != null) {
  1177. return resource.wallClockTime;
  1178. }
  1179. return 0.0;
  1180. }
  1181.  
  1182. /**在ID基础上获取云资源名
  1183. * Gets the CloudResource name based on its ID.
  1184. *
  1185. * @param resId a CloudResource entity ID
  1186. *
  1187. * @return the CloudResource name or <tt>null</tt> if not found
  1188. *
  1189. * @pre resId >= 0
  1190. * @post $none
  1191. */
  1192. public String getResourceName(final int resId) {
  1193. Resource resource = getResourceById(resId);
  1194. if (resource != null) {
  1195. return resource.resourceName;
  1196. }
  1197. return null;
  1198. }
  1199.  
  1200. /**由ID获取资源
  1201. * Gets the resource by id.
  1202. *
  1203. * @param resourceId the resource id
  1204. *
  1205. * @return the resource by id
  1206. */
  1207. public Resource getResourceById(final int resourceId) {
  1208. for (Resource resource : resList) {
  1209. if (resource.resourceId == resourceId) {
  1210. return resource;
  1211. }
  1212. }
  1213. return null;
  1214. }
  1215.  
  1216. /**获取云任务在资源中完成时间
  1217. * Gets the finish time of this Cloudlet in a CloudResource.
  1218. *
  1219. * @return the finish or completion time of this Cloudlet or <tt>-1</tt> if
  1220. * not finished yet.
  1221. *
  1222. * @pre $none
  1223. * @post $result >= -1
  1224. */
  1225. public double getFinishTime() {
  1226. return finishTime;
  1227. }
  1228.  
  1229. ////////////////////////// PROTECTED METHODS //////////////////////////////
  1230.  
  1231. /**记录云任务特别交易历史
  1232. * Writes this particular history transaction of this Cloudlet into a log.
  1233. *
  1234. * @param str a history transaction of this Cloudlet
  1235. *
  1236. * @pre str != null
  1237. * @post $none
  1238. */
  1239. protected void write(final String str) {
  1240. if (!record) {
  1241. return;
  1242. }
  1243.  
  1244. if (num == null || history == null) { // Creates the history or transactions of this Cloudlet
  1245. newline = System.getProperty("line.separator");
  1246. num = new DecimalFormat("#0.00#"); // with 3 decimal spaces
  1247. history = new StringBuffer(1000);
  1248. history.append("Time below denotes the simulation time.");
  1249. history.append( System.getProperty("line.separator") );
  1250. history.append("Time (sec) Description Cloudlet #"+cloudletId);
  1251. history.append( System.getProperty("line.separator") );
  1252. history.append("------------------------------------------");
  1253. history.append( System.getProperty("line.separator") );
  1254. history.append( num.format(CloudSim.clock()) );
  1255. history.append(" Creates Cloudlet ID #" + cloudletId);
  1256. history.append( System.getProperty("line.separator") );
  1257. }
  1258.  
  1259. history.append(num.format(CloudSim.clock()));
  1260. history.append(" " + str + newline);
  1261. }
  1262.  
  1263. /**云任务状态
  1264. * Get the status of the Cloudlet.
  1265. *
  1266. * @return status of the Cloudlet
  1267. *
  1268. * @pre $none
  1269. * @post $none
  1270. */
  1271. public int getStatus(){
  1272. return getCloudletStatus();
  1273. }
  1274.  
  1275. /**获取任务ID
  1276. * Gets the ID of this Cloudlet.
  1277. *
  1278. * @return Cloudlet Id
  1279. *
  1280. * @pre $none
  1281. * @post $none
  1282. */
  1283. public int getCloudletId() {
  1284. return this.cloudletId;
  1285. }
  1286.  
  1287. /**获取运行云任务的虚拟机ID
  1288. * Gets the ID of the VM that will run this Cloudlet.
  1289. *
  1290. * @return VM Id, -1 if the Cloudlet was not assigned to a VM
  1291. *
  1292. * @pre $none
  1293. * @post $none
  1294. */
  1295. public int getVmId() {
  1296. return vmId;
  1297. }
  1298.  
  1299. /**设置虚拟机ID
  1300. * Sets the ID of the VM that will run this Cloudlet.
  1301. *
  1302. * @param vmId the vm id
  1303. *
  1304. * @pre id >= 0
  1305. * @post $none
  1306. */
  1307. public void setVmId(final int vmId) {
  1308. this.vmId = vmId;
  1309. }
  1310.  
  1311. /**
  1312. * Returns the time the Cloudlet actually run.
  1313. *
  1314. * @return time in which the Cloudlet was running
  1315. *
  1316. * @pre $none
  1317. * @post $none
  1318. */
  1319. public double getActualCPUTime(){
  1320. return getFinishTime() - getExecStartTime();
  1321. }
  1322.  
  1323. /**设置资源参数
  1324. * Sets the resource parameters for which this Cloudlet is going to be
  1325. * executed. <br>
  1326. * NOTE: This method <tt>should</tt> be called only by a resource entity,
  1327. * not the user or owner of this Cloudlet.
  1328. *
  1329. * @param resourceID the CloudResource ID
  1330. * @param costPerCPU the cost running this Cloudlet per second
  1331. * @param costPerBw the cost of data transfer to this PowerDatacenter
  1332. *
  1333. * @pre resourceID >= 0
  1334. * @pre cost > 0.0
  1335. * @post $none
  1336. */
  1337. public void setResourceParameter(final int resourceID, final double costPerCPU, final double costPerBw) {
  1338. setResourceParameter(resourceID, costPerCPU);
  1339. this.costPerBw = costPerBw;
  1340. this.accumulatedBwCost = costPerBw * getCloudletFileSize();
  1341.  
  1342. }
  1343.  
  1344. /**执行云任务总费用
  1345. * Gets the total cost of processing or executing this Cloudlet
  1346. * <tt>Processing Cost = input data transfer + processing cost + output transfer cost</tt>.
  1347. *
  1348. * @return the total cost of processing Cloudlet
  1349. *
  1350. * @pre $none
  1351. * @post $result >= 0.0
  1352. */
  1353. public double getProcessingCost() {
  1354. //cloudlet cost: execution cost...
  1355. //double cost = getProcessingCost();//处理费用
  1356. double cost = 0;
  1357. //...plus input data transfer cost...//数据传送费用
  1358. cost += this.accumulatedBwCost;
  1359. //...plus output cost输出费用
  1360. cost += this.costPerBw * getCloudletOutputSize();
  1361. return cost;
  1362. }
  1363.  
  1364. // Data cloudlet
  1365.  
  1366. /**
  1367. * Gets the required files.
  1368. *
  1369. * @return the required files
  1370. */
  1371. public List<String> getRequiredFiles() {
  1372. return requiredFiles;
  1373. }
  1374.  
  1375. /**设置请求文件 (是指什么呢???)
  1376. * Sets the required files.
  1377. *
  1378. * @param requiredFiles the new required files
  1379. */
  1380. protected void setRequiredFiles(final List<String> requiredFiles) {
  1381. this.requiredFiles = requiredFiles;
  1382. }
  1383.  
  1384. /**
  1385. * Adds the required filename to the list.
  1386. *
  1387. * @param fileName the required filename
  1388. *
  1389. * @return <tt>true</tt> if succesful, <tt>false</tt> otherwise
  1390. */
  1391. public boolean addRequiredFile(final String fileName) {
  1392. // if the list is empty
  1393. if (getRequiredFiles() == null) {
  1394. setRequiredFiles(new LinkedList<String>());
  1395. }
  1396.  
  1397. // then check whether filename already exists or not
  1398. boolean result = false;
  1399. for (int i = 0; i < getRequiredFiles().size(); i++) {
  1400. final String temp = getRequiredFiles().get(i);
  1401. if (temp.equals(fileName)) {
  1402. result = true;
  1403. break;
  1404. }
  1405. }
  1406.  
  1407. if (!result) {
  1408. getRequiredFiles().add(fileName);
  1409. }
  1410.  
  1411. return result;
  1412. }
  1413.  
  1414. /**删除给出的问就爱你名
  1415. * Deletes the given filename from the list.
  1416. *
  1417. * @param filename the given filename to be deleted
  1418. *
  1419. * @return <tt>true</tt> if succesful, <tt>false</tt> otherwise
  1420. */
  1421. public boolean deleteRequiredFile(final String filename) {
  1422. boolean result = false;
  1423. if (getRequiredFiles() == null) {
  1424. return result;
  1425. }
  1426.  
  1427. for (int i = 0; i < getRequiredFiles().size(); i++) {
  1428. final String temp = getRequiredFiles().get(i);
  1429.  
  1430. if (temp.equals(filename)) {
  1431. getRequiredFiles().remove(i);
  1432. result = true;
  1433.  
  1434. break;
  1435. }
  1436. }
  1437.  
  1438. return result;
  1439. }
  1440.  
  1441. /**
  1442. * Checks whether this cloudlet requires any files or not.
  1443. *
  1444. * @return <tt>true</tt> if required, <tt>false</tt> otherwise
  1445. */
  1446. public boolean requiresFiles() {
  1447. boolean result = false;
  1448. if (getRequiredFiles() != null && getRequiredFiles().size() > 0) {
  1449. result = true;
  1450. }
  1451.  
  1452. return result;
  1453. }
  1454.  
  1455. //【设置 cpu ram bw 利用率】
  1456. /**
  1457. * Gets the utilization model cpu.
  1458. *
  1459. * @return the utilization model cpu
  1460. */
  1461. public UtilizationModel getUtilizationModelCpu() {
  1462. return utilizationModelCpu;
  1463. }
  1464.  
  1465. /**
  1466. * Sets the utilization model cpu.
  1467. *
  1468. * @param utilizationModelCpu the new utilization model cpu
  1469. */
  1470. public void setUtilizationModelCpu(final UtilizationModel utilizationModelCpu) {
  1471. this.utilizationModelCpu = utilizationModelCpu;
  1472. }
  1473.  
  1474. /**
  1475. * Gets the utilization model ram.
  1476. *
  1477. * @return the utilization model ram
  1478. */
  1479. public UtilizationModel getUtilizationModelRam() {
  1480. return utilizationModelRam;
  1481. }
  1482.  
  1483. /**
  1484. * Sets the utilization model ram.
  1485. *
  1486. * @param utilizationModelRam the new utilization model ram
  1487. */
  1488. public void setUtilizationModelRam(final UtilizationModel utilizationModelRam) {
  1489. this.utilizationModelRam = utilizationModelRam;
  1490. }
  1491.  
  1492. /**
  1493. * Gets the utilization model bw.
  1494. *
  1495. * @return the utilization model bw
  1496. */
  1497. public UtilizationModel getUtilizationModelBw() {
  1498. return utilizationModelBw;
  1499. }
  1500.  
  1501. /**
  1502. * Sets the utilization model bw.
  1503. *
  1504. * @param utilizationModelBw the new utilization model bw
  1505. */
  1506. public void setUtilizationModelBw(final UtilizationModel utilizationModelBw) {
  1507. this.utilizationModelBw = utilizationModelBw;
  1508. }
  1509.  
  1510. /**
  1511. * Gets the total utilization of cpu.
  1512. *
  1513. * @param time the time
  1514. *
  1515. * @return the utilization of cpu
  1516. */
  1517. public double getUtilizationOfCpu(final double time) {
  1518. return getUtilizationModelCpu().getUtilization(time);
  1519. }
  1520.  
  1521. /**
  1522. * Gets the utilization of memory.
  1523. *
  1524. * @param time the time
  1525. *
  1526. * @return the utilization of memory
  1527. */
  1528. public double getUtilizationOfRam(final double time) {
  1529. return getUtilizationModelRam().getUtilization(time);
  1530. }
  1531.  
  1532. /**
  1533. * Gets the utilization of bw.
  1534. *
  1535. * @param time the time
  1536. *
  1537. * @return the utilization of bw
  1538. */
  1539. public double getUtilizationOfBw(final double time) {
  1540. return getUtilizationModelBw().getUtilization(time);
  1541. }
  1542.  
  1543. }

/*

* Title:        CloudSim Toolkit

* Description:  CloudSim (Cloud Simulation) Toolkit for Modeling and Simulation of Clouds

* Licence:      GPL - http://www.gnu.org/copyleft/gpl.html

*

* Copyright (c) 2009-2010, The University of Melbourne, Australia

*/

package org.cloudbus.cloudsim;

import java.text.DecimalFormat;//小数的  十进制的

import java.util.ArrayList;//数组

import java.util.LinkedList;//链接表

import java.util.List;//java.util集合框架、遗留的 collection 类、事件模型、日期和时间设施、国际化和各种实用工具类

import org.cloudbus.cloudsim.core.CloudSim;

/**

* Cloudlet is an extension to the cloudlet. It stores, despite all the information

* encapsulated in the Cloudlet, the ID of the VM running it.

*

* @authorRodrigo N. Calheiros

* @authorAnton Beloglazov

* @sinceCloudSim Toolkit 1.0

*/

public class Cloudlet {

// the User or Broker ID. It is advisable that broker set this ID

// with its own ID, so that CloudResource returns to it after the execution

/** The user id. */ //用户ID

private int userId;

// the size of this Cloudlet to be executed in a CloudResource (unit: in MI)

/** The cloudlet length. */ //云任务长度   单位:MI

private long cloudletLength;

// the input file size of this Cloudlet before execution (unit: in byte)

/** The cloudlet file size. */ //云任务文件大小  单位:字节

private final long cloudletFileSize;   // in byte = program + input data size //字节=程序+输入数据大小

// the output file size of this Cloudlet after execution (unit: in byte)

/** The cloudlet output size. */ //云任务输出文件大小

private final long cloudletOutputSize;

/** The pes number. *///执行任务请求的PE数

private int pesNumber;              // num of Pe required to execute this job

/** The cloudlet id. */ //云任务ID

private final int cloudletId;          // this Cloudlet ID

/** The status. */ //云任务状态

private int status;             // status of this Cloudlet

/** The num. */ //十进制格式

private DecimalFormat num;      // to format the decimal number

/** The finish time. */ //云任务完成时间

private double finishTime;      // the time where this Cloudlet completes

// start time of executing this Cloudlet.

// With new functionalities, such as CANCEL, PAUSED and RESUMED, this

// attribute only stores the latest execution time. Previous execution time

// are ignored.

/** The exec start time. */ //执行仿真开始时间

private double execStartTime;   // in simulation time

/** The reservation id. */  //云任务预约ID  资源的ID?(预约资源)

private int reservationId = -1; // the ID of a reservation made for this cloudlet

// records the transaction history for this Cloudlet //记录云任务的交易历史

/** The record. */ //是否记录?

private final boolean record;         // record a history or not

/** The newline. */ //换行?

private String newline;

/** The history. */ //交易历史   String类是字符串常量,是不可更改的常量。而StringBuffer是字符串变量,它的对象是可以扩充和修改的

private StringBuffer history;

/** The res list. */ //资源列表?

private final List<Resource> resList;

/** The index. */ //索引

private int index;

// differentiated service 不同的服务

/** The class type. */ //云任务类别

private int classType;    // class type of Cloudlet for resource scheduling

/** The net to s. */ //TOS(terms of service)服务条款 ?

private int netToS;       // ToS for sending Cloudlet over the network

//私有访问控制符private 只能被该类自身所访问和修改,而且不能被任何其他类(包括该类的子类)来获取和引用。private修饰符用来声明那些类的私有成员,它提供了最高的保护级别

////////////////////////////////////////////

// Below are CONSTANTS attributes 以下是常量属性

/** The Cloudlet has been created and added to the CloudletList object. */

public static final int CREATED = 0;//云任务创建并加入云任务列表对象

/** The Cloudlet has been assigned to a CloudResource object as planned. */

public static final int READY = 1; //云任务按照计划分配给资源

/** The Cloudlet has moved to a Cloud node. */

public static final int QUEUED = 2; //云任务提交给一个【云节点】 虚拟机吗??

/** The Cloudlet is in execution in a Cloud node. */

public static final int INEXEC = 3; //云任务执行

/** The Cloudlet has been executed successfully. */

public static final int SUCCESS = 4; //云任务成功执行

/** The Cloudlet is failed. */

public static final int FAILED = 5; //执行失败

/** The Cloudlet has been canceled. */

public static final int CANCELED = 6; //云任务被取消

/** The Cloudlet has been paused. It can be resumed by changing the status into <tt>RESUMED</tt>. */

public static final int PAUSED = 7; //云任务执行暂停

/** The Cloudlet has been resumed from <tt>PAUSED</tt> state. */

public static final int RESUMED = 8; //重启执行云任务

/** The cloudlet has failed due to a resource failure. */

public static final int FAILED_RESOURCE_UNAVAILABLE = 9;//由于资源失败 云任务失败

//公有访问控制符public  Java的类是通过包的概念来组织的,包是类的一个松散的集合。具有了被其他包中的类访问的可能性,只要这些其他包中的类在程序中使用import语句引入public类,就可以访问和引用这个类

/** The vm id. */ //虚拟机编号

protected int vmId;

/** The cost per bw. */ //带宽费用

protected double costPerBw;

/** The accumulated bw cost. */ //累计的带宽费用

protected double accumulatedBwCost;

//protected 被三种类所引用:该类自身、与它在同一个包中的其它类、在其他包中的该类的子类。使用protected修饰符的主要作用是允许其他包中该类的子类来访问父类的特定属性。

// Utilization 【利用率】

/** The utilization of cpu model. */ //CPU利用模型

private UtilizationModel utilizationModelCpu;

/** The utilization of memory model. */ //memory利用模型

private UtilizationModel utilizationModelRam;

/** The utilization of bw model. */ //BW利用模型

private UtilizationModel utilizationModelBw;

// Data cloudlet 数据 云任务 ???

/** The required files. */ //请求的文件

private List<String> requiredFiles = null;   // list of required filenames

/**【分配一个新的云任务对象】

* Allocates a new Cloudlet object. The Cloudlet length, input and output

* file sizes should be greater than or equal to 1.

* By default this constructor sets the history of this object.

*

* @param cloudletId            the unique ID of this Cloudlet

* @param cloudletLength        the length or size (in MI) of this cloudlet

* to be executed in a PowerDatacenter

* @param cloudletFileSize      the file size (in byte) of this cloudlet

* <tt>BEFORE</tt> submitting to a PowerDatacenter

* @param cloudletOutputSize    the file size (in byte) of this cloudlet

* <tt>AFTER</tt> finish executing by

* a PowerDatacenter

* @param pesNumber the pes number

* @param utilizationModelCpu the utilization model cpu

* @param utilizationModelRam the utilization model ram

* @param utilizationModelBw the utilization model bw

*

* @pre cloudletID >= 0

* @pre cloudletLength >= 0.0

* @pre cloudletFileSize >= 1

* @pre cloudletOutputSize >= 1

* @post $none

*/

public Cloudlet(

final int cloudletId, //加了一个final表示不能修改传入的参数的值

final long cloudletLength,

final int pesNumber,

final long cloudletFileSize,

final long cloudletOutputSize,

final UtilizationModel utilizationModelCpu,

final UtilizationModel utilizationModelRam,

final UtilizationModel utilizationModelBw) {

this(cloudletId, cloudletLength, pesNumber, cloudletFileSize, cloudletOutputSize, utilizationModelCpu, utilizationModelRam, utilizationModelBw, true);

this.vmId=-1;

this.accumulatedBwCost=0.0;

this.costPerBw=0.0;

this.requiredFiles = new LinkedList<String>();

}//this通常指当前对象 引用当前对象的某种东西,比如当前对象的某个方法,或当前对象的某个成员,你便可以利用this来实现这个目的,this的另一个用途是调用当前对象的另一个构造函数

/**

* Allocates a new Cloudlet object. The Cloudlet length, input and output

* file sizes should be greater than or equal to 1.

*

* @param cloudletId            the unique ID of this cloudlet

* @param cloudletLength        the length or size (in MI) of this cloudlet

* to be executed in a PowerDatacenter

* @param cloudletFileSize      the file size (in byte) of this cloudlet

* <tt>BEFORE</tt> submitting to a PowerDatacenter

* @param cloudletOutputSize    the file size (in byte) of this cloudlet

* <tt>AFTER</tt> finish executing by

* a PowerDatacenter

* @param record               record the history of this object or not

* @param fileList    list of files required by this cloudlet

* @param pesNumber the pes number

* @param utilizationModelCpu the utilization model cpu

* @param utilizationModelRam the utilization model ram

* @param utilizationModelBw the utilization model bw

*

* @pre cloudletID >= 0

* @pre cloudletLength >= 0.0

* @pre cloudletFileSize >= 1

* @pre cloudletOutputSize >= 1

* @post $none

*/

public Cloudlet(

final int cloudletId,

final long cloudletLength,

final int pesNumber,

final long cloudletFileSize,

final long cloudletOutputSize,

final UtilizationModel utilizationModelCpu,

final UtilizationModel utilizationModelRam,

final UtilizationModel utilizationModelBw,

final boolean record,

final List<String> fileList) {

this(cloudletId, cloudletLength, pesNumber, cloudletFileSize, cloudletOutputSize, utilizationModelCpu, utilizationModelRam, utilizationModelBw, record);

this.vmId=-1;

this.accumulatedBwCost=0.0;//统计的带宽费用

this.costPerBw=0.0;

this.requiredFiles = fileList;

}  //与上一个对象大部分一样!

/**

* Allocates a new Cloudlet object. The Cloudlet length, input and output

* file sizes should be greater than or equal to 1.

* By default this constructor sets the history of this object.

*

* @param cloudletId            the unique ID of this Cloudlet

* @param cloudletLength        the length or size (in MI) of this cloudlet

* to be executed in a PowerDatacenter

* @param cloudletFileSize      the file size (in byte) of this cloudlet

* <tt>BEFORE</tt> submitting to a PowerDatacenter

* @param cloudletOutputSize    the file size (in byte) of this cloudlet

* <tt>AFTER</tt> finish executing by

* a PowerDatacenter

* @param fileList    list of files required by this cloudlet

* @param pesNumber the pes number

* @param utilizationModelCpu the utilization model cpu

* @param utilizationModelRam the utilization model ram

* @param utilizationModelBw the utilization model bw

*

* @pre cloudletID >= 0

* @pre cloudletLength >= 0.0

* @pre cloudletFileSize >= 1

* @pre cloudletOutputSize >= 1

* @post $none

*/

public Cloudlet(

final int cloudletId,

final long cloudletLength,

final int pesNumber,

final long cloudletFileSize,

final long cloudletOutputSize,

final UtilizationModel utilizationModelCpu,

final UtilizationModel utilizationModelRam,

final UtilizationModel utilizationModelBw,

final List<String> fileList) {

this(cloudletId, cloudletLength, pesNumber, cloudletFileSize, cloudletOutputSize, utilizationModelCpu, utilizationModelRam, utilizationModelBw, true);

this.vmId=-1;

this.accumulatedBwCost=0.0;

this.costPerBw=0.0;

this.requiredFiles = fileList;

}

/**

* Allocates a new Cloudlet object. The Cloudlet length, input and output

* file sizes should be greater than or equal to 1.

*

* @param cloudletId            the unique ID of this cloudlet

* @param cloudletLength        the length or size (in MI) of this cloudlet

* to be executed in a PowerDatacenter

* @param cloudletFileSize      the file size (in byte) of this cloudlet

* <tt>BEFORE</tt> submitting to a PowerDatacenter

* @param cloudletOutputSize    the file size (in byte) of this cloudlet

* <tt>AFTER</tt> finish executing by

* a PowerDatacenter

* @param record               record the history of this object or not

* @param pesNumber the pes number

* @param utilizationModelCpu the utilization model cpu

* @param utilizationModelRam the utilization model ram

* @param utilizationModelBw the utilization model bw

*

* @pre cloudletID >= 0

* @pre cloudletLength >= 0.0

* @pre cloudletFileSize >= 1

* @pre cloudletOutputSize >= 1

* @post $none

*/

public Cloudlet(

final int cloudletId,

final long cloudletLength,

final int pesNumber,

final long cloudletFileSize,

final long cloudletOutputSize,

final UtilizationModel utilizationModelCpu,

final UtilizationModel utilizationModelRam,

final UtilizationModel utilizationModelBw,

final boolean record) {

this.userId = -1;          // 代理或用户设置 to be set by a Broker or user

this.status = CREATED; //任务状态

this.cloudletId = cloudletId;

this.pesNumber = pesNumber;

this.execStartTime = 0.0;

this.finishTime = -1.0;    // 任务还没还没完成 meaning this Cloudlet hasn't finished yet

this.classType = 0; //类别

this.netToS = 0;

// Cloudlet length, Input and Output size should be at least 1 byte.至少一个字节

this.cloudletLength = Math.max(1, cloudletLength);

this.cloudletFileSize = Math.max(1, cloudletFileSize);

this.cloudletOutputSize = Math.max(1, cloudletOutputSize);

// Normally, a Cloudlet is only executed on a resource without being

// migrated to others. Hence, to reduce memory consumption, set the

// size of this ArrayList to be less than the default one.设置内存大小数组列表小于默认值

this.resList = new ArrayList<Resource>(2);

this.index = -1;

this.record = record;

this.vmId = -1;

this.accumulatedBwCost = 0.0;

this.costPerBw = 0.0;

this.requiredFiles = new LinkedList<String>();

setUtilizationModelCpu(utilizationModelCpu);

setUtilizationModelRam(utilizationModelRam);

setUtilizationModelBw(utilizationModelBw);

}

//【内部类】

//////////////////////// INTERNAL CLASS ///////////////////////////////////

/**

* Internal class that keeps track Cloudlet's movement in different

* CloudResources.(不同的资源中登记云任务动向)

*/

private static class Resource {

/** Cloudlet's submission time to a CloudResource. */

public double submissionTime = 0.0;//云任务的提交时间

/** The time of this Cloudlet resides in a CloudResource (from arrival time until departure time). */

public double wallClockTime = 0.0; //云任务从到达到撤离时间

/** The total execution time of this Cloudlet in a CloudResource. */

public double actualCPUTime = 0.0;//云任务执行时间

/** Cost per second a CloudResource charge to execute this Cloudlet. */

public double costPerSec = 0.0;//云资源每秒费用

/** Cloudlet's length finished so far. */

public long finishedSoFar = 0; //已完成的云任务长度

/** a CloudResource id. */

public int resourceId = -1;//云资源ID

/** a CloudResource name. */

public String resourceName = null;//云资源名

} // end of internal class

//【结束内部类】

//////////////////////// End of Internal Class //////////////////////////

/**设置预约ID

* Sets the id of the reservation made for this cloudlet.

*

* @param resId the reservation ID

*

* @return <tt>true</tt> if the ID has successfully been set or

* <tt>false</tt> otherwise.

*/

public boolean setReservationId(final int resId) {//预约的ID是资源的ID?

if(resId <= 0) {

return false;

}

reservationId = resId;

return true;

}

/**获取预约ID

* Gets the reservation ID that owns this Cloudlet.

*

* @return a reservation ID

*

* @pre $none

* @post $none

*/

public int getReservationId() {

return reservationId;

}

/**云任务是否通过预约来提交

* Checks whether this Cloudlet is submitted by reserving or not.

*

* @return <tt>true</tt> if this Cloudlet has reserved before,

* <tt>false</tt> otherwise

*/

public boolean hasReserved() {

if (reservationId == -1) {

return false;

}

return true;

}

/**设置云任务长度

* Sets the length or size (in MI) of this Cloudlet

* to be executed in a CloudResource.

* This Cloudlet length is calculated for 1 Pe only <tt>not</tt> the total

* length.

*

* @param cloudletLength     the length or size (in MI) of this Cloudlet

* to be executed in a CloudResource

*

* @return <tt>true</tt> if it is successful, <tt>false</tt> otherwise

*

* @pre cloudletLength > 0

* @post $none

*/

public boolean setCloudletLength(final long cloudletLength) {

if (cloudletLength <= 0) {

return false;

}

this.cloudletLength = cloudletLength;

return true;

}

/**设置服务等级【可以尝试】

* Sets the network service level for sending this cloudlet over a network.

*

* @param netServiceLevel   determines the kind of service this cloudlet

* receives in the network (applicable to

* selected PacketScheduler class only)

*

* @return <code>true</code> if successful.

*

* @pre netServiceLevel >= 0

* @post $none

*/

public boolean setNetServiceLevel(final int netServiceLevel) {

boolean success = false;

if (netServiceLevel > 0)  {

netToS = netServiceLevel;

success = true;

}

return success;

}

/**获取服务等级

* Gets the network service level for sending this cloudlet over a network.

*

* @return the network service level

*

* @pre $none

* @post $none

*/

public int getNetServiceLevel() {

return netToS;

}

/**获取云任务等待时间

* Gets the waiting time of this cloudlet executed on a resource.

*

* @return the waiting time

*

* @pre $none

* @post $none

*/

public double getWaitingTime() {

if (index == -1) {

return 0;

}

// use the latest resource submission time

final double subTime = resList.get(index).submissionTime;

return execStartTime - subTime;//执行开始时间-提交时间

}

/**任务类别(优先权)【尝试扩展使用】

* Sets the classType or priority of this Cloudlet for scheduling on a

* resource.

*

* @param classType classType of this Cloudlet

*

* @return <tt>true</tt> if it is successful, <tt>false</tt> otherwise

*

* @pre classType > 0

* @post $none

*/

public boolean setClassType(final int classType) {

boolean success = false;

if (classType > 0) {

this.classType = classType;

success = true;

}

return success;

}

/**获取任务类别(优先权)

* Gets the classtype or priority of this Cloudlet for scheduling on a

* resource.

*

* @return classtype of this cloudlet

*

* @pre $none

* @post $none

*/

public int getClassType() {

return classType;

}

/**任务请求的PE

* Sets the number of PEs required to run this Cloudlet. <br>

* NOTE: The Cloudlet length is computed only for 1 Pe for simplicity. <br>

* For example, this Cloudlet has a length of 500 MI and requires 2 PEs.

* This means each Pe will execute 500 MI of this Cloudlet.每个PE都执行500 不是各分担250???

*

* @param pesNumber     number of Pe

*

* @return <tt>true</tt> if it is successful, <tt>false</tt> otherwise

*

* @pre numPE > 0

* @post $none

*/

public boolean setPesNumber(final int pesNumber) {

if (pesNumber > 0) {

this.pesNumber = pesNumber;

return true;

}

return false;

}

/**

* Gets the number of PEs required to run this Cloudlet.

*

* @return number of PEs

*

* @pre $none

* @post $none

*/

public int getPesNumber() {

return pesNumber;

}

/**云任务历史记录

* Gets the history of this Cloudlet. The layout of this history is in a

* readable table column with <tt>time</tt> and <tt>description</tt>

* as headers.

*

* @return a String containing the history of this Cloudlet object.

*

* @pre $none

* @post $result != null

*/

public String getCloudletHistory() {

String msg = null;

if (history == null) {

msg = "No history is recorded for Cloudlet #" + cloudletId;

} else {

msg = history.toString();

}

return msg;

}

/**任务已执行长度(适合 迁移任务或取消)

* Gets the length of this Cloudlet that has been executed so far

* from the latest CloudResource. This

* method is useful when trying to move this Cloudlet into different

* CloudResources or to cancel it.

*

* @return the length of a partially executed Cloudlet or the full Cloudlet

* length if it is completed

*

* @pre $none

* @post $result >= 0.0

*/

public long getCloudletFinishedSoFar() {

if (index == -1) {

return cloudletLength;

}

final long finish = resList.get(index).finishedSoFar;//resList 资源列表?

if (finish > cloudletLength) {

return cloudletLength;

}

return finish;

}

/**检验云任务是否执行完毕

* Checks whether this Cloudlet has finished execution or not.

*

* @return <tt>true</tt> if this Cloudlet has finished execution,

* <tt>false</tt> otherwise

*

* @pre $none

* @post $none

*/

public boolean isFinished() {

if (index == -1) {

return false;

}

boolean completed = false;

// if result is 0 or -ve then this Cloudlet has finished

final long finish = resList.get(index).finishedSoFar;

final long result = cloudletLength - finish;

if (result <= 0.0) {

completed = true;

}

return completed;

}

/**设置任务执行长度

* Sets the length of this Cloudlet that has been executed so far.

* This method is used by ResCloudlet class when an application

* is decided to cancel or to move this Cloudlet into different

* CloudResources.

*

* @param length    length of this Cloudlet

*

* @see gridsim.AllocPolicy

* @see gridsim.ResCloudlet

* @pre length >= 0.0

* @post $none

*/

public void setCloudletFinishedSoFar(final long length) {

// if length is -ve then ignore

if (length < 0.0 || index < 0) {

return;

}

final Resource res = resList.get(index);

res.finishedSoFar = length;

if (record) {

write("Sets the length's finished so far to " + length);

}

}

/**设置用户ID

* Sets the user or owner ID of this Cloudlet. It is <tt>VERY</tt> important

* to set the user ID, otherwise this Cloudlet will not be executed in a

* CloudResource.

*

* @param id  the user ID

*

* @pre id >= 0

* @post $none

*/

public void setUserId(final int id) {

userId = id;

if (record) {

write("Assigns the Cloudlet to " + CloudSim.getEntityName(id) + " (ID #" + id + ")");

}

}

/**

* Gets the user or owner ID of this Cloudlet.

*

* @return the user ID or <tt>-1</tt> if the user ID has not been set before

*

* @pre $none

* @post $result >= -1

*/

public int getUserId() {

return userId;

}

/**资源ID

* Gets the latest resource ID that processes this Cloudlet.

*

* @return the resource ID or <tt>-1</tt> if none

*

* @pre $none

* @post $result >= -1

*/

public int getResourceId() {

if (index == -1) {

return -1;

}

return resList.get(index).resourceId;

}

/**获取输入文件大小

* Gets the input file size of this Cloudlet <tt>BEFORE</tt>

* submitting to a CloudResource.

*

* @return the input file size of this Cloudlet

*

* @pre $none

* @post $result >= 1

*/

public long getCloudletFileSize() {

return cloudletFileSize;

}

/**获取输出文件大小

* Gets the output size of this Cloudlet <tt>AFTER</tt> submitting and

* executing to a CloudResource.

*

* @return the Cloudlet output file size

*

* @pre $none

* @post $result >= 1

*/

public long getCloudletOutputSize() {

return cloudletOutputSize;

}

/**通过资源实体设置资源参数

* Sets the resource parameters for which this Cloudlet is going to be

* executed. <br>

* NOTE: This method <tt>should</tt> be called only by a 【resource entity】,

* not the user or owner of this Cloudlet.

*

* @param resourceID   the CloudResource ID

* @param cost   the cost running this CloudResource per second

*

* @pre resourceID >= 0

* @pre cost > 0.0

* @post $none

*/

public void setResourceParameter(final int resourceID, final double cost) {

final Resource res = new Resource();

res.resourceId = resourceID;

res.costPerSec = cost;

res.resourceName = CloudSim.getEntityName(resourceID);

// add into a list if moving to a new grid resource

resList.add(res);

if (index == -1 && record) {

write("Allocates this Cloudlet to " + res.resourceName + " (ID #" + resourceID + ") with cost = $" + cost + "/sec");

} else if (record) {

final int id = resList.get(index).resourceId;

final String name = resList.get(index).resourceName;

write("Moves Cloudlet from " + name + " (ID #" + id + ") to " +

res.resourceName + " (ID #" + resourceID +

") with cost = $" + cost + "/sec");

}

index++;  // initially, index = -1

}

/**设置 提交  到达 时间

* Sets the submission or arrival time of this Cloudlet into a CloudResource.

*

* @param clockTime  提交时间     the submission time

*

* @pre clockTime >= 0.0

* @post $none

*/

public void setSubmissionTime(final double clockTime) {

if (clockTime < 0.0 || index < 0) {

return;

}

final Resource res = resList.get(index);

res.submissionTime = clockTime;

if (record) {

write( "Sets the submission time to " + num.format(clockTime) );

}

}

/**

* Gets the submission or arrival time of this Cloudlet from

* the latest CloudResource.

*

* @return the submission time or <tt>0.0</tt> if none

*

* @pre $none

* @post $result >= 0.0

*/

public double getSubmissionTime() {

if (index == -1) {

return 0.0;

}

return resList.get(index).submissionTime;

}

/**设置执行开始时间 (取消 暂停 重启)

* Sets the execution start time of this Cloudlet inside a CloudResource.

* <b>NOTE:</b> With new functionalities, such as being able to cancel /

* to pause / to resume this Cloudlet, the execution start time only holds

* the latest one. Meaning, all previous execution start time are ignored.

*

* @param clockTime     the latest execution start time

*

* @pre clockTime >= 0.0

* @post $none

*/

public void setExecStartTime(final double clockTime) {

execStartTime = clockTime;

if (record) {

write("Sets the execution start time to " + num.format(clockTime));

}

}

/**

* Gets the latest execution start time.

*

* @return the latest execution start time

*

* @pre $none

* @post $result >= 0.0

*/

public double getExecStartTime() {

return execStartTime;

}

/**云任务执行参数设置

* Sets this Cloudlet's execution parameters. These parameters are set by

* the CloudResource before departure or sending back to the original

* Cloudlet's owner.

*

* @param wallTime  (云任务停留时间)  the time of this Cloudlet resides in

* a CloudResource (from arrival time until

* departure time).

* @param actualTime  (执行时间)  the total execution time of this Cloudlet in a

* CloudResource.

*

* @pre wallTime >= 0.0

* @pre actualTime >= 0.0

* @post $none

*/

public void setExecParam(final double wallTime, final double actualTime) {

if (wallTime < 0.0 || actualTime < 0.0 || index < 0) {

return;

}

final Resource res = resList.get(index);

res.wallClockTime = wallTime;

res.actualCPUTime = actualTime;

if (record) {

write("Sets the wall clock time to "+ num.format(wallTime)+

" and the actual CPU time to " + num.format(actualTime));

}

}

/**云任务状态设置

* Sets the status code of this Cloudlet.

*

* @param newStatus    the status code of this Cloudlet

*

* @throws Exception   Invalid range of Cloudlet status

*

* @pre newStatus >= 0 && newStatus <= 8

* @post $none

*/

public void setCloudletStatus(final int newStatus) throws Exception {

// if the new status is same as current one, then ignore the rest

if (status == newStatus) {

return;

}

// throws an exception if the new status is outside the range

if (newStatus < Cloudlet.CREATED || newStatus > Cloudlet.FAILED_RESOURCE_UNAVAILABLE) {

throw new Exception("Cloudlet.setCloudletStatus() : Error - Invalid integer range for Cloudlet status.");

}//newStatus  Cloudlet.CREATED 有可比性

if (newStatus == Cloudlet.SUCCESS) {

finishTime = CloudSim.clock();

}

if (record) {

write("Sets Cloudlet status from " + getCloudletStatusString() + " to " + Cloudlet.getStatusString(newStatus));

}

this.status = newStatus;

}

/**

* Gets the status code of this Cloudlet.

*

* @return the status code of this Cloudlet

*

* @pre $none

* @post $result >= 0

*/

public int getCloudletStatus() {

return status;

}

/**代表此刻云任务状态

* Gets the string representation of the current Cloudlet status code.

*

* @return the Cloudlet status code as a string or <tt>null</tt> if the

* status code is unknown

*

* @pre $none

* @post $none

*/

public String getCloudletStatusString() {

return Cloudlet.getStatusString(status);

}

/**

* Gets the string representation of the given Cloudlet status code.

*

* @param status    the Cloudlet status code

*

* @return the Cloudlet status code as a string or <tt>null</tt> if the

* status code is unknown

*

* @pre $none

* @post $none

*/

public static String getStatusString(final int status) {

String statusString = null;

switch (status)

{

case Cloudlet.CREATED://创建

statusString = "Created";

break;

case Cloudlet.READY://准备

statusString = "Ready";

break;

case Cloudlet.INEXEC://执行

statusString = "InExec";

break;

case Cloudlet.SUCCESS://成功

statusString = "Success";

break;

case Cloudlet.QUEUED://排队等候

statusString = "Queued";

break;

case Cloudlet.FAILED://失败

statusString = "Failed";

break;

case Cloudlet.CANCELED://取消

statusString = "Canceled";

break;

case Cloudlet.PAUSED://暂停

statusString = "Paused";

break;

case Cloudlet.RESUMED://重启

statusString = "Resumed";

break;

case Cloudlet.FAILED_RESOURCE_UNAVAILABLE ://无可用资源

statusString = "Failed_resource_unavailable";

break;

default:

break;

}

return statusString;

}

/**获取云任务长度

* Gets the length of this Cloudlet.

*

* @return the length of this Cloudlet

*

* @pre $none

* @post $result >= 0.0

*/

public long getCloudletLength() {

return cloudletLength;

}

/**获取任务总长度

* Gets the total length (across all PEs) of this Cloudlet.

*

* @return the total length of this Cloudlet

*

* @pre $none

* @post $result >= 0.0

*/

public long getCloudletTotalLength() {

return getCloudletLength() * getPesNumber();//为什么乘以PE数

}

/**云资源上的执行费用

* Gets the cost running this Cloudlet in the latest CloudResource.

*

* @return the cost associated with running this Cloudlet

* or <tt>0.0</tt> if none

*

* @pre $none

* @post $result >= 0.0

*/

public double getCostPerSec() {

if (index == -1) {

return 0.0;

}

return resList.get(index).costPerSec;

}

/**云任务停留时间在最近的云资源上 (云资源   是指  虚拟机??)

* Gets the time of this Cloudlet resides in the latest CloudResource

* (from arrival time until departure time).

*

* @return the time of this Cloudlet resides in a CloudResource

*

* @pre $none

* @post $result >= 0.0

*/

public double getWallClockTime() {

if (index == -1) {

return 0.0;

}

return resList.get(index).wallClockTime;

}

/**执行云任务的所有资源名称

* Gets all the CloudResource names that executed this Cloudlet.

*

* @return an array of CloudResource names or <tt>null</tt> if it has none

*

* @pre $none

* @post $none

*/

public String[] getAllResourceName() {

final int size = resList.size();

String[] data = null;

if (size > 0) {

data = new String[size];

for (int i = 0; i < size; i++) {

data[i] = resList.get(i).resourceName;

}

}

return data;

}

/**执行云任务的所有资源ID号

* Gets all the CloudResource IDs that executed this Cloudlet.

*

* @return an array of CloudResource IDs or <tt>null</tt> if it has none

*

* @pre $none

* @post $none

*/

public int[] getAllResourceId() {

final int size = resList.size();

int[] data = null;

if (size > 0) {

data = new int[size];

for (int i = 0; i < size; i++) {

data[i] = resList.get(i).resourceId;

}

}

return data;

}

/**云任务执行的总时间

* Gets the total execution time of this Cloudlet in a given CloudResource ID.

*

* @param resId  a CloudResource entity ID

*

* @return the total execution time of this Cloudlet in a CloudResource

* or <tt>0.0</tt> if not found

*

* @pre resId >= 0

* @post $result >= 0.0

*/

public double getActualCPUTime(final int resId) {

Resource resource = getResourceById(resId);

if (resource != null) {

return resource.actualCPUTime;

}

return 0.0;

}

/**指定的资源上运行云任务的费用

* Gets the cost running this Cloudlet in a given CloudResource ID.

*

* @param resId  a CloudResource entity ID

*

* @return the cost associated with running this Cloudlet

* or <tt>0.0</tt> if not found

*

* @pre resId >= 0

* @post $result >= 0.0

*/

public double getCostPerSec(final int resId) {

Resource resource = getResourceById(resId);

if (resource != null) {

return resource.costPerSec;

}

return 0.0;

}

/**指定的资源上获取云任务已执行的长度 (取消 或 移动任务至不同的云资源)

* Gets the length of this Cloudlet that has been executed so far in a given

* CloudResource ID. This method is useful when trying to move this Cloudlet

* into different CloudResources or to cancel it.

*

* @param resId  a CloudResource entity ID

*

* @return the length of a partially executed Cloudlet or the full Cloudlet

* length if it is completed or <tt>0.0</tt> if not found

*

* @pre resId >= 0

* @post $result >= 0.0

*/

public long getCloudletFinishedSoFar(final int resId) {

Resource resource = getResourceById(resId);

if (resource != null) {

return resource.finishedSoFar;

}

return 0;

}

/**指定的资源上获取云任务提交  到达时间

* Gets the submission or arrival time of this Cloudlet in the

* given CloudResource ID.

*

* @param resId  a CloudResource entity ID

*

* @return the submission time or <tt>0.0</tt> if not found

*

* @pre resId >= 0

* @post $result >= 0.0

*/

public double getSubmissionTime(final int resId) {

Resource resource = getResourceById(resId);

if (resource != null) {

return resource.submissionTime;

}

return 0.0;

}

/**指定的资源上云任务停留的时间

* Gets the time of this Cloudlet resides in a given CloudResource ID

* (from arrival time until departure time).

*

* @param resId  a CloudResource entity ID

*

* @return the time of this Cloudlet resides in the CloudResource

* or <tt>0.0</tt> if not found

*

* @pre resId >= 0

* @post $result >= 0.0

*/

public double getWallClockTime(final int resId) {

Resource resource = getResourceById(resId);

if (resource != null) {

return resource.wallClockTime;

}

return 0.0;

}

/**在ID基础上获取云资源名

* Gets the CloudResource name based on its ID.

*

* @param resId  a CloudResource entity ID

*

* @return the CloudResource name or <tt>null</tt> if not found

*

* @pre resId >= 0

* @post $none

*/

public String getResourceName(final int resId) {

Resource resource = getResourceById(resId);

if (resource != null) {

return resource.resourceName;

}

return null;

}

/**由ID获取资源

* Gets the resource by id.

*

* @param resourceId the resource id

*

* @return the resource by id

*/

public Resource getResourceById(final int resourceId) {

for (Resource resource : resList) {

if (resource.resourceId == resourceId) {

return resource;

}

}

return null;

}

/**获取云任务在资源中完成时间

* Gets the finish time of this Cloudlet in a CloudResource.

*

* @return the finish or completion time of this Cloudlet or <tt>-1</tt> if

* not finished yet.

*

* @pre $none

* @post $result >= -1

*/

public double getFinishTime() {

return finishTime;

}

////////////////////////// PROTECTED METHODS //////////////////////////////

/**记录云任务特别交易历史

* Writes this particular history transaction of this Cloudlet into a log.

*

* @param str   a history transaction of this Cloudlet

*

* @pre str != null

* @post $none

*/

protected void write(final String str) {

if (!record) {

return;

}

if (num == null || history == null) { // Creates the history or transactions of this Cloudlet

newline = System.getProperty("line.separator");

num = new DecimalFormat("#0.00#"); // with 3 decimal spaces

history = new StringBuffer(1000);

history.append("Time below denotes the simulation time.");

history.append( System.getProperty("line.separator") );

history.append("Time (sec)       Description Cloudlet #"+cloudletId);

history.append( System.getProperty("line.separator") );

history.append("------------------------------------------");

history.append( System.getProperty("line.separator") );

history.append( num.format(CloudSim.clock()) );

history.append("   Creates Cloudlet ID #" + cloudletId);

history.append( System.getProperty("line.separator") );

}

history.append(num.format(CloudSim.clock()));

history.append("   " + str + newline);

}

/**云任务状态

* Get the status of the Cloudlet.

*

* @return status of the Cloudlet

*

* @pre $none

* @post $none

*/

public int getStatus(){

return getCloudletStatus();

}

/**获取任务ID

* Gets the ID of this Cloudlet.

*

* @return Cloudlet Id

*

* @pre $none

* @post $none

*/

public int getCloudletId() {

return this.cloudletId;

}

/**获取运行云任务的虚拟机ID

* Gets the ID of the VM that will run this Cloudlet.

*

* @return VM Id, -1 if the Cloudlet was not assigned to a VM

*

* @pre $none

* @post $none

*/

public int getVmId() {

return vmId;

}

/**设置虚拟机ID

* Sets the ID of the VM that will run this Cloudlet.

*

* @param vmId the vm id

*

* @pre id >= 0

* @post $none

*/

public void setVmId(final int vmId) {

this.vmId = vmId;

}

/**

* Returns the time the Cloudlet actually run.

*

* @return time in which the Cloudlet was running

*

* @pre $none

* @post $none

*/

public double getActualCPUTime(){

return getFinishTime() - getExecStartTime();

}

/**设置资源参数

* Sets the resource parameters for which this Cloudlet is going to be

* executed. <br>

* NOTE: This method <tt>should</tt> be called only by a resource entity,

* not the user or owner of this Cloudlet.

*

* @param resourceID   the CloudResource ID

* @param costPerCPU   the cost running this Cloudlet per second

* @param costPerBw    the cost of data transfer to this PowerDatacenter

*

* @pre resourceID >= 0

* @pre cost > 0.0

* @post $none

*/

public void setResourceParameter(final int resourceID, final double costPerCPU, final double costPerBw) {

setResourceParameter(resourceID, costPerCPU);

this.costPerBw = costPerBw;

this.accumulatedBwCost = costPerBw * getCloudletFileSize();

}

/**执行云任务总费用

* Gets the total cost of processing or executing this Cloudlet

* <tt>Processing Cost = input data transfer + processing cost + output transfer cost</tt>.

*

* @return the total cost of processing Cloudlet

*

* @pre $none

* @post $result >= 0.0

*/

public double getProcessingCost() {

//cloudlet cost: execution cost...

//double cost = getProcessingCost();//处理费用

double cost = 0;

//...plus input data transfer cost...//数据传送费用

cost += this.accumulatedBwCost;

//...plus output cost输出费用

cost += this.costPerBw * getCloudletOutputSize();

return cost;

}

// Data cloudlet

/**

* Gets the required files.

*

* @return the required files

*/

public List<String> getRequiredFiles() {

return requiredFiles;

}

/**设置请求文件    (是指什么呢???)

* Sets the required files.

*

* @param requiredFiles the new required files

*/

protected void setRequiredFiles(final List<String> requiredFiles) {

this.requiredFiles = requiredFiles;

}

/**

* Adds the required filename to the list.

*

* @param fileName  the required filename

*

* @return <tt>true</tt> if succesful, <tt>false</tt> otherwise

*/

public boolean addRequiredFile(final String fileName) {

// if the list is empty

if (getRequiredFiles() == null) {

setRequiredFiles(new LinkedList<String>());

}

// then check whether filename already exists or not

boolean result = false;

for (int i = 0; i < getRequiredFiles().size(); i++) {

final String temp = getRequiredFiles().get(i);

if (temp.equals(fileName)) {

result = true;

break;

}

}

if (!result) {

getRequiredFiles().add(fileName);

}

return result;

}

/**删除给出的问就爱你名

* Deletes the given filename from the list.

*

* @param filename  the given filename to be deleted

*

* @return <tt>true</tt> if succesful, <tt>false</tt> otherwise

*/

public boolean deleteRequiredFile(final String filename) {

boolean result = false;

if (getRequiredFiles() == null) {

return result;

}

for (int i = 0; i < getRequiredFiles().size(); i++) {

final String temp = getRequiredFiles().get(i);

if (temp.equals(filename)) {

getRequiredFiles().remove(i);

result = true;

break;

}

}

return result;

}

/**

* Checks whether this cloudlet requires any files or not.

*

* @return <tt>true</tt> if required, <tt>false</tt> otherwise

*/

public boolean requiresFiles() {

boolean result = false;

if (getRequiredFiles() != null && getRequiredFiles().size() > 0) {

result = true;

}

return result;

}

//【设置 cpu ram bw 利用率】

/**

* Gets the utilization model cpu.

*

* @return the utilization model cpu

*/

public UtilizationModel getUtilizationModelCpu() {

return utilizationModelCpu;

}

/**

* Sets the utilization model cpu.

*

* @param utilizationModelCpu the new utilization model cpu

*/

public void setUtilizationModelCpu(final UtilizationModel utilizationModelCpu) {

this.utilizationModelCpu = utilizationModelCpu;

}

/**

* Gets the utilization model ram.

*

* @return the utilization model ram

*/

public UtilizationModel getUtilizationModelRam() {

return utilizationModelRam;

}

/**

* Sets the utilization model ram.

*

* @param utilizationModelRam the new utilization model ram

*/

public void setUtilizationModelRam(final UtilizationModel utilizationModelRam) {

this.utilizationModelRam = utilizationModelRam;

}

/**

* Gets the utilization model bw.

*

* @return the utilization model bw

*/

public UtilizationModel getUtilizationModelBw() {

return utilizationModelBw;

}

/**

* Sets the utilization model bw.

*

* @param utilizationModelBw the new utilization model bw

*/

public void setUtilizationModelBw(final UtilizationModel utilizationModelBw) {

this.utilizationModelBw = utilizationModelBw;

}

/**

* Gets the total utilization of cpu.

*

* @param time the time

*

* @return the utilization of cpu

*/

public double getUtilizationOfCpu(final double time) {

return getUtilizationModelCpu().getUtilization(time);

}

/**

* Gets the utilization of memory.

*

* @param time the time

*

* @return the utilization of memory

*/

public double getUtilizationOfRam(final double time) {

return getUtilizationModelRam().getUtilization(time);

}

/**

* Gets the utilization of bw.

*

* @param time the time

*

* @return the utilization of bw

*/

public double getUtilizationOfBw(final double time) {

return getUtilizationModelBw().getUtilization(time);

}

}

CloudSim源代码学习——任务单元(Cloudlet)的更多相关文章

  1. CloudSim源代码学习——服务代理商(DatacenterBroker)

    DatacenterBroker.java文件如下: (其中,相关语句已经做好标注) /* * Title: CloudSim Toolkit * Description: CloudSim (Clo ...

  2. CloudSim源代码学习——虚拟机(VM)

    package org.cloudbus.cloudsim; import java.util.ArrayList;//This class provides methods to manipulat ...

  3. CloudSim源代码学习——云数据中心(Datacenter)

    package org.cloudbus.cloudsim; import java.text.DecimalFormat;//十进制 import java.util.ArrayList; impo ...

  4. struts2源代码学习之初始化(一)

    看struts2源代码已有一段时日,从今天開始,就做一个总结吧. 首先,先看看怎么调试struts2源代码吧,主要是下面步骤: 使用Myeclipse创建一个webproject 导入struts2须 ...

  5. [Java] LinkedList / Queue - 源代码学习笔记

    简单地画了下 LinkedList 的继承关系,如下图.只是画了关注的部分,并不是完整的关系图.本博文涉及的是 Queue, Deque, LinkedList 的源代码阅读笔记.关于 List 接口 ...

  6. 开源中国安卓client源代码学习(一) 渐变启动界面

    开源中国安卓client源代码学习(一) 渐变启动界面 准备学习安卓开发, 看到网上有人推荐开源中国安卓client的源代码, 说里面包括了大部分技术, 于是准备好好研究研究. 特开通此系列博客来记录 ...

  7. 读Flask源代码学习Python--config原理

    读Flask源代码学习Python--config原理 个人学习笔记,水平有限.如果理解错误的地方,请大家指出来,谢谢!第一次写文章,发现好累--!. 起因   莫名其妙在第一份工作中使用了从来没有接 ...

  8. nginx源代码学习资源(不断更新)

    nginx源代码学习是一个痛苦又快乐的过程,以下列出了一些nginx的学习资源. 首先要做的当然是下载一份nginx源代码,能够从nginx官方站点下载一份最新的. 看了nginx源代码,发现这是一份 ...

  9. JDK源代码学习系列07----Stack

                                                                   JDK源代码学习系列07----Stack 1.Stack源代码很easy ...

随机推荐

  1. struts2框架学习笔记3:获取servletAPI

    Struts2存在一个对象ActionContext(本质是Map),可以获得原生的request,response,ServletContext 还可以获得四大域对象(Map),以及param参数( ...

  2. hdu 5116--Everlasting L(计数DP)

    题目链接 Problem Description Matt loves letter L. A point set P is (a, b)-L if and only if there exists ...

  3. oracle中常见的查询操作

    普通查询:select * from t; 去除重复值:select distinct f1,f2 from t; between用法:select * from t where f1 not/bet ...

  4. 30 个java编程技巧

    1.return 一个空的集合,而不是 null 如果一个程序返回一个没有任何值的集合,请确保一个空集合返回,而不是空元素.这样你就不用去写一大堆 ”if else” 判断null元素. Java 的 ...

  5. Apache Commons Digester 一 (基础内容、核心API)

    前言 在许多需要处理XML格式数据的应用环境中, 如果能够以“事件驱动”的方式来处理XML文档,比如,当识别出特定的XML元素时,触发“创建对象”操作事件(或者触发调用对象的方法事件),这对于应用程序 ...

  6. Eureka核心知识点

    一.Eureka特性1.当注册中心挂了,客户端之间依然可以通过原有的注册表进行调用:注册中心重启后,客户端会继续注册进来 2.当服务提供者挂了,在关闭自我保护的情况下,注册中心在规定时间(默认是60s ...

  7. Go 语言实践(一)

    本文由Austin发表 指导原则 我们要谈论在一个编程语言中的最佳实践,那么我们首先应该明确什么是"最佳".如果您们听了我昨天那场讲演的话,您一定看到了来自 Go 团队的 Russ ...

  8. kong+konga

    kong+kongau 注意kong1.0与之前版本API发生了很大的改动,所以是不兼容的,kongav0.14.0是匹配kong1.0+的,不兼容1.0之前的.可以根据自己的需求进行选择. kong ...

  9. Java提高篇之理解java的三大特性——继承

    在<Think in java>中有这样一句话:复用代码是Java众多引人注目的功能之一.但要想成为极具革命性的语言,仅仅能够复制代码并对加以改变是不够的,它还必须能够做更多的事情.在这句 ...

  10. WPF Application 类介绍以及怎样修改启动方式

    因为想要修改wpf的启动方式,所以研究了下Application类,现把一些有用的属性与大家分享下: 属性: Current                  获取当前 AppDomain的 Appl ...