CloudSim源代码学习SimEntityjava文档格式.docx
《CloudSim源代码学习SimEntityjava文档格式.docx》由会员分享,可在线阅读,更多相关《CloudSim源代码学习SimEntityjava文档格式.docx(23页珍藏版)》请在冰豆网上搜索。
*
*Copyright(c)2009-2010,TheUniversityofMelbourne,Australia
*/
package;
import;
/**
*Thisclassrepresentsasimulationentity.Anentityhandleseventsandcan
*sendeventstootherentities.Whenthisclassisextended,thereareafew
*methodsthatneedtobeimplemented:
*<
ul>
li>
{@link#startEntity()}isinvokedbythe{@linkSimulation}classwhen
*thesimulationisstarted.Thismethodshouldberesponsibleforstartingthe
*entityup.
{@link#processEvent(SimEvent)}isinvokedbythe{@linkSimulation}
*classwheneverthereisaneventinthedeferredqueue,whichneedstobe
*processedbytheentity.
{@link#shutdownEntity()}isinvokedbythe{@linkSimulation}beforethe
*simulationfinishes.Ifyouwanttosavedatainlogfilesthisisthemethod
*inwhichthecorrespondingcodewouldbeplaced.
/ul>
*@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
*tag<
code>
9999<
/code>
isreserved.
*@paramdestTheuniqueidnumberofthedestinationentity
*@paramdelayHowlongfromthecurrentsimulationtimetheevent
*shouldbesent
*@paramtagAnuser-definednumberrepresentingthetypeofevent.
*@paramdataThedatatobesentwiththeevent.
publicvoidschedule(intdest,doubledelay,inttag,Objectdata){
if(!
CloudSim.running()){
return;
CloudSim.send(id,dest,delay,tag,data);
*Sendaneventtoanotherentitybyidnumberandwith<
b>
no<
/b>
data.
*Notethatthetag<
publicvoidschedule(intdest,doubledelay,inttag){
schedule(dest,delay,tag,null);
*Sendaneventtoanotherentitythroughaportwithagivenname,with
*data.Notethatthetag<
*@paramdestThenameoftheporttosendtheeventthrough
publicvoidschedule(Stringdest,doubledelay,inttag,Objectdata){
schedule(CloudSim.getEntityId(dest),delay,tag,data);
data.Notethatthetag<
*@paramdelayHowlongfromthecurrentsimulationtimetheeventshouldbe
*sent
publicvoidschedule(Stringdest,doubledelay,inttag){
publicvoidscheduleNow(intdest,inttag,Objectdata){
schedule(dest,0,tag,data);
publicvoidscheduleNow(intdest,inttag){
schedule(dest,0,tag,null);
*Sendaneventto