CloudSim源代码学习SimEntityjava.docx
《CloudSim源代码学习SimEntityjava.docx》由会员分享,可在线阅读,更多相关《CloudSim源代码学习SimEntityjava.docx(23页珍藏版)》请在冰豆网上搜索。
![CloudSim源代码学习SimEntityjava.docx](https://file1.bdocx.com/fileroot1/2022-11/17/354ff64c-6a9f-495c-ae9e-a704d1d07bb3/354ff64c-6a9f-495c-ae9e-a704d1d07bb31.gif)
CloudSim源代码学习SimEntityjava
SimEntity.java
/*
该类表示一个模拟实体。
实体处理事件并且发送事件到其他实体。
*Title:
CloudSimToolkit
*Description:
CloudSim(CloudSimulation)ToolkitforModelingandSimulationofClouds
*Licence:
GPL-/gpl.html
*
*Copyright(c)2009-2010,TheUniversityofMelbourne,Australia
*/
package;
import;
import;
import;
/**
*Thisclassrepresentsasimulationentity.Anentityhandleseventsandcan
*sendeventstootherentities.Whenthisclassisextended,thereareafew
*methodsthatneedtobeimplemented:
*
*
- {@link#startEntity()}isinvokedbythe{@linkSimulation}classwhen
*thesimulationisstarted.Thismethodshouldberesponsibleforstartingthe
*entityup.
*
- {@link#processEvent(SimEvent)}isinvokedbythe{@linkSimulation}
*classwheneverthereisaneventinthedeferredqueue,whichneedstobe
*processedbytheentity.
*
- {@link#shutdownEntity()}isinvokedbythe{@linkSimulation}beforethe
*simulationfinishes.Ifyouwanttosavedatainlogfilesthisisthemethod
*inwhichthecorrespondingcodewouldbeplaced.
*
*
*@authorMarcosDiasdeAssuncao
*@sinceCloudSimToolkit1.0
*/
publicabstractclassSimEntityimplementsCloneable{
/**Thename.*/
privateStringname;
/**Theid.*/
privateintid;
/**Thebufferforselectedincomingevents.*/
privateSimEventevbuf;
/**Theentity'scurrentstate.*/
privateintstate;
/**
*Createsanewentity.
*
*@paramnamethenametobeassociatedwiththisentity
*/
publicSimEntity(Stringname){
if(name.indexOf("")!
=-1){
thrownewIllegalArgumentException(
"Entitynamescan'tcontainspaces.");
}
this.name=name;
id=-1;
state=RUNNABLE;
CloudSim.addEntity(this);
}
/**
*Getthenameofthisentity.
*
*@returnTheentity'sname
*/
publicStringgetName(){
returnname;
}
/**
*Gettheuniqueidnumberassignedtothisentity.
*
*@returnTheidnumber
*/
publicintgetId(){
returnid;
}
//Theschedulefunctions
/**
*Sendaneventtoanotherentitybyidnumber,withdata.Notethatthe
*tag9999
isreserved.
*
*@paramdestTheuniqueidnumberofthedestinationentity
*@paramdelayHowlongfromthecurrentsimulationtimetheevent
*shouldbesent
*@paramtagAnuser-definednumberrepresentingthetypeofevent.
*@paramdataThedatatobesentwiththeevent.
*/
publicvoidschedule(intdest,doubledelay,inttag,Objectdata){
if(!
CloudSim.running()){
return;
}
CloudSim.send(id,dest,delay,tag,data);
}
/**
*Sendaneventtoanotherentitybyidnumberandwithnodata.
*Notethatthetag9999
isreserved.
*
*@paramdestTheuniqueidnumberofthedestinationentity
*@paramdelayHowlongfromthecurrentsimulationtimetheevent
*shouldbesent
*@paramtagAnuser-definednumberrepresentingthetypeofevent.
*/
publicvoidschedule(intdest,doubledelay,inttag){
schedule(dest,delay,tag,null);
}
/**
*Sendaneventtoanotherentitythroughaportwithagivenname,with
*data.Notethatthetag9999
isreserved.
*
*@paramdestThenameoftheporttosendtheeventthrough
*@paramdelayHowlongfromthecurrentsimulationtimetheevent
*shouldbesent
*@paramtagAnuser-definednumberrepresentingthetypeofevent.
*@paramdataThedatatobesentwiththeevent.
*/
publicvoidschedule(Stringdest,doubledelay,inttag,Objectdata){
schedule(CloudSim.getEntityId(dest),delay,tag,data);
}
/**
*Sendaneventtoanotherentitythroughaportwithagivenname,with
*nodata.Notethatthetag9999
isreserved.
*
*@paramdestThenameoftheporttosendtheeventthrough
*@paramdelayHowlongfromthecurrentsimulationtimetheeventshouldbe
*sent
*@paramtagAnuser-definednumberrepresentingthetypeofevent.
*/
publicvoidschedule(Stringdest,doubledelay,inttag){
schedule(dest,delay,tag,null);
}
/**
*Sendaneventtoanotherentitybyidnumber,withdata.Notethatthe
*tag9999
isreserved.
*
*@paramdestTheuniqueidnumberofthedestinationentity
*@paramtagAnuser-definednumberrepresentingthetypeofevent.
*@paramdataThedatatobesentwiththeevent.
*/
publicvoidscheduleNow(intdest,inttag,Objectdata){
schedule(dest,0,tag,data);
}
/**
*Sendaneventtoanotherentitybyidnumberandwithnodata.
*Notethatthetag9999
isreserved.
*
*@paramdestTheuniqueidnumberofthedestinationentity
*@paramtagAnuser-definednumberrepresentingthetypeofevent.
*/
publicvoidscheduleNow(intdest,inttag){
schedule(dest,0,tag,null);
}
/**
*Sendaneventto