1、CloudSim源代码学习SimEntityjavaSimEntity.java/*该类表示一个模拟实体。实体处理事件并且发送事件到其他实体。 * Title: CloudSim Toolkit * Description: CloudSim (Cloud Simulation) Toolkit for Modeling and Simulation of Clouds * Licence: GPL - /gpl.html * * Copyright (c) 2009-2010, The University of Melbourne, Australia */package ;import
2、;import ;import ;/* * This class represents a simulation entity. An entity handles events and can * send events to other entities. When this class is extended, there are a few * methods that need to be implemented: * * link #startEntity() is invoked by the link Simulation class when * the simulation
3、 is started. This method should be responsible for starting the * entity up. * link #processEvent(SimEvent) is invoked by the link Simulation * class whenever there is an event in the deferred queue, which needs to be * processed by the entity. * link #shutdownEntity() is invoked by the link Simulat
4、ion before the * simulation finishes. If you want to save data in log files this is the method * in which the corresponding code would be placed. * * * author Marcos Dias de Assuncao * since CloudSim Toolkit 1.0 */public abstract class SimEntity implements Cloneable /* The name. */ private String na
5、me; /* The id. */ private int id; /* The buffer for selected incoming events. */ private SimEvent evbuf; /* The entitys current state. */ private int state; /* * Creates a new entity. * * param name the name to be associated with this entity */ public SimEntity(String name) if (name.indexOf( ) != -1
6、) throw new IllegalArgumentException( Entity names cant contain spaces.); this.name = name; id = -1; state = RUNNABLE; CloudSim.addEntity(this); /* * Get the name of this entity. * * return The entitys name */ public String getName() return name; /* * Get the unique id number assigned to this entity
7、. * * return The id number */ public int getId() return id; / The schedule functions /* * Send an event to another entity by id number, with data. Note that the * tag 9999 is reserved. * * param dest The unique id number of the destination entity * param delay How long from the current simulation ti
8、me the event * should be sent * param tag An user-defined number representing the type of event. * param data The data to be sent with the event. */ public void schedule(int dest, double delay, int tag, Object data) if (!CloudSim.running() return; CloudSim.send(id, dest, delay, tag, data); /* * Send
9、 an event to another entity by id number and with no data. * Note that the tag 9999 is reserved. * * param dest The unique id number of the destination entity * param delay How long from the current simulation time the event * should be sent * param tag An user-defined number representing the type o
10、f event. */ public void schedule(int dest, double delay, int tag) schedule(dest, delay, tag, null); /* * Send an event to another entity through a port with a given name, with * data. Note that the tag 9999 is reserved. * * param dest The name of the port to send the event through * param delay How
11、long from the current simulation time the event * should be sent * param tag An user-defined number representing the type of event. * param data The data to be sent with the event. */ public void schedule(String dest, double delay, int tag, Object data) schedule(CloudSim.getEntityId(dest), delay, ta
12、g, data); /* * Send an event to another entity through a port with a given name, with * no data. Note that the tag 9999 is reserved. * * param dest The name of the port to send the event through * param delay How long from the current simulation time the event should be * sent * param tag An user-de
13、fined number representing the type of event. */ public void schedule(String dest, double delay, int tag) schedule(dest, delay, tag, null); /* * Send an event to another entity by id number, with data. Note that the * tag 9999 is reserved. * * param dest The unique id number of the destination entity
14、 * param tag An user-defined number representing the type of event. * param data The data to be sent with the event. */ public void scheduleNow(int dest, int tag, Object data) schedule(dest, 0, tag, data); /* * Send an event to another entity by id number and with no data. * Note that the tag 9999 is reserved. * * param dest The unique id number of the destination entity * param tag An user-defined number representing the type of event. */ public void scheduleNow(int dest, int tag) schedule(dest, 0, tag, null); /* * Send an event to
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1