📄 gridsimcore.java
字号:
/** * Sets the background traffic generator for this entity. * <p> * When simulation starts, the Output entity will automatically sends junk * packets to resource entities and other entities. <br> * NOTE: Sending background traffic to itself is not supported. * * @param gen a background traffic generator * @param userName a collection of user entity name (in String object). * @return <tt>true</tt> if successful, <tt>false</tt> otherwise * @pre gen != null * @pre userName != null * @post $none */ public boolean setBackgroundTraffic(TrafficGenerator gen, Collection userName) { if (gen == null || userName == null || out_ == null) { return false; } return out_.setBackgroundTraffic(gen, userName); } /** * Pings to a particular entity ID with a given packet size. * <p> * This method is <i>a non-blocking call</i>, meaning you need * to get the ping result by calling {@link #getPingResult()}. * The return value of this method is just an indication whether * ping() has successfully sent or not. * * @param entityID the destination entity ID * @param size the ping packet size * @return <tt>true</tt> if successful, <tt>false</tt> otherwise * @pre entityID > 0 * @pre size >= 0 * @post $none */ protected boolean ping(int entityID, int size) { return ping(entityID, size, 0.0, 0); } /** * Pings to a particular entity ID with a given packet size. * <p> * This method is <i>a non-blocking call</i>, meaning you need * to get the ping result by calling {@link #getPingResult()}. * The return value of this method is just an indication whether * ping() has successfully sent or not. * * @param entityName the destination entity name * @param size the ping packet size * @return <tt>true</tt> if successful, <tt>false</tt> otherwise * @pre entityName != null * @pre size >= 0 * @post $none */ protected boolean ping(String entityName, int size) { return ping(entityName, size, 0.0, 0); } /** * Pings to a particular entity ID with a given packet size. * <p> * This method is <i>a non-blocking call</i>, meaning you need * to get the ping result by calling {@link #getPingResult()}. * The return value of this method is just an indication whether * ping() has successfully sent or not. * * @param entityName the destination entity name * @param size the ping packet size * @param delay the delay time for submitting this ping request * @param netServiceLevel level of service for ping packet (only * applicable to certain PacketScheduler, such as * {@link gridsim.net.SCFQScheduler}. * @return <tt>true</tt> if successful, <tt>false</tt> otherwise * @pre entityName != null * @pre size >= 0 * @pre delay >= 0 * @pre netServiceLevel >= 0 * @post $none */ protected boolean ping(String entityName, int size, double delay, int netServiceLevel) { int id = GridSim.getEntityId(entityName); return ping(id, size, delay, netServiceLevel); } /** * Pings to a particular entity ID with a given packet size. * <p> * This method is <i>a non-blocking call</i>, meaning you need * to get the ping result by calling {@link #getPingResult()}. * The return value of this method is just an indication whether * ping() has successfully sent or not. * * @param entityID the destination entity ID * @param size the ping packet size * @param delay the delay time for submitting this ping request * @param netServiceLevel level of service for ping packet (only * applicable to certain PacketScheduler, such as * {@link gridsim.net.SCFQScheduler}. * @return <tt>true</tt> if successful, <tt>false</tt> otherwise * @pre entityID > 0 * @pre size >= 0 * @pre delay >= 0 * @pre netServiceLevel >= 0 * @post $none */ protected boolean ping(int entityID, int size, double delay, int netServiceLevel) { if (entityID < 0) { System.out.println(super.get_name() + ".ping(): Error - " + "invalid entity ID or name."); return false; } if (size < 0) { System.out.println(super.get_name() + ".ping(): Error - " + "invalid packet size."); return false; } if (delay < 0) { delay = 0.0; } // send this ping to the destination send( this.output, delay, GridSimTags.INFOPKT_SUBMIT, new IO_data(null, size, entityID, netServiceLevel) ); return true; } /** * Pings to a particular entity ID with a given packet size. * <p> * This method is <i>a blocking call</i>, meaning it will keep * waiting until it gets the ping result back. * * @param entityID the destination entity ID * @param size the ping packet size * @param delay the delay time for submitting this ping request * @param netServiceLevel level of service for ping packet (only * applicable to certain PacketScheduler, such as * {@link gridsim.net.SCFQScheduler}. * @return a ping result in InfoPacket object or <tt>null</tt> * if unexpected error happens. * @pre entityID > 0 * @pre size >= 0 * @pre delay >= 0 * @pre netServiceLevel >= 0 * @post $none */ protected InfoPacket pingBlockingCall(int entityID, int size, double delay, int netServiceLevel) { boolean result = ping(entityID, size, delay, netServiceLevel); if (result == false) { return null; } return getPingResult(); } /** * Pings to a particular entity ID with a given packet size. * <p> * This method is <i>a blocking call</i>, meaning it will keep * waiting until it gets the ping result back. * * @param entityID the destination entity ID * @param size the ping packet size * @return a ping result in InfoPacket object or <tt>null</tt> * if unexpected error happens. * @pre entityID > 0 * @pre size >= 0 * @post $none */ protected InfoPacket pingBlockingCall(int entityID, int size) { return pingBlockingCall(entityID, size, 0.0, 0); } /** * Pings to a particular entity ID with a given packet size. * <p> * This method is <i>a blocking call</i>, meaning it will keep * waiting until it gets the ping result back. * * @param entityName the destination entity name * @param size the ping packet size * @return a ping result in InfoPacket object or <tt>null</tt> * if unexpected error happens. * @pre entityName != null * @pre size >= 0 * @post $none */ protected InfoPacket pingBlockingCall(String entityName, int size) { int id = GridSim.getEntityId(entityName); return pingBlockingCall(id, size, 0.0, 0); } /** * Pings to a particular entity ID with a given packet size. * <p> * This method is <i>a blocking call</i>, meaning it will keep * waiting until it gets the ping result back. * * @param entityName the destination entity name * @param size the ping packet size * @param delay the delay time for submitting this ping request * @param netServiceLevel level of service for ping packet (only * applicable to certain PacketScheduler, such as * {@link gridsim.net.SCFQScheduler}. * @return a ping result in InfoPacket object or <tt>null</tt> * if unexpected error happens. * @pre entityName != null * @pre size >= 0 * @pre delay >= 0 * @pre netServiceLevel >= 0 * @post $none */ protected InfoPacket pingBlockingCall(String entityName, int size, double delay, int netServiceLevel) { int id = GridSim.getEntityId(entityName); return pingBlockingCall(id, size, delay, netServiceLevel); } /** * Gets the first available ping result in the event queue. * @return a ping result in InfoPacket object or <tt>null</tt> * if unexpected error happens. * @pre $none * @post $none */ protected InfoPacket getPingResult() { Sim_event ev = new Sim_event(); // waiting for a response from the GridResource Sim_type_p tag = new Sim_type_p(GridSimTags.INFOPKT_RETURN); // only look for this type of ack super.sim_get_next(tag, ev); InfoPacket pkt = null; try { pkt = (InfoPacket) ev.get_data(); } catch(Sim_exception sim) { System.out.print(super.get_name() + ".getPingResult(): Error - "); System.out.println("exception occurs. See the below message:"); System.out.println( sim.getMessage() ); pkt = null; } catch(Exception e) { System.out.print(super.get_name() + ".getPingResult(): Error - "); System.out.println("exception occurs. See the below message:"); System.out.println( e.getMessage() ); pkt = null; } return pkt; } /** * It terminates Entities managing NETWORK communication channels. * It can be invoked explicity to shutdown NETWORK communication channels. * It is advisable for all entities extending GridSim class, explicitly * invoke this method to terminate <tt>Input</tt> and * <tt>Output</tt> entities created * by the constructor: {@link GridSim#GridSim(String, double)} * @deprecated As of GridSim 2.1, replaced by * {@link #terminateIOEntities()} * @pre $none * @post $none */ protected void TerminateInputOutputEntities() { terminateIOEntities(); } /** * It terminates Entities managing NETWORK communication channels. * It can be invoked explicity to shutdown NETWORK communication channels. * It is advisable for all entities extending GridSim class, explicitly * invoke this method to terminate <tt>Input</tt> and * <tt>Output</tt> entities created * by the constructor: {@link GridSim#GridSim(String, double)} * @pre $none * @post $none */ protected void terminateIOEntities() { // If it is Networked entity and Not yet terminated, then terminate. if ( isNetworked() && !terminateIOEntitiesFlag_ ) { // Send END_OF_SIMULATION to Input entity send(input, 0.0, GridSimTags.END_OF_SIMULATION); // Send END_OF_SIMULATION to Output entity send(output, 0.0, GridSimTags.END_OF_SIMULATION); terminateIOEntitiesFlag_ = true; } } /** * It terminates the entities of this object that manage <tt>NETWORK</tt> * communication channels * @deprecated As of GridSim 2.1, replaced by * {@link #finalizeGridSimulation()} * @see gridsim.GridSim#terminateIOEntities() * @pre $none * @post $none */ protected void finalize() { finalizeGridSimulation(); } /** * It terminates the entities of this object that manage <tt>NETWORK</tt> * communication channels * @see gridsim.GridSim#terminateIOEntities() * @pre $none * @post $none */ protected void finalizeGridSimulation() { terminateIOEntities(); } /**
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -