Skip to content

Commit

Permalink
Removes Simulation parameter from CloudSimEvent constructors
Browse files Browse the repository at this point in the history
since such an object can be got from the source or destination entity.

Signed-off-by: Manoel Campos <manoelcampos@gmail.com>
  • Loading branch information
manoelcampos committed Oct 4, 2018
1 parent 8071f96 commit 341b3e2
Show file tree
Hide file tree
Showing 11 changed files with 71 additions and 77 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ public List<SimEntity> getEntityList() {
public void addEntity(final CloudSimEntity entity) {
requireNonNull(entity);
if (running) {
final SimEvent evt = new CloudSimEvent(this, SimEvent.Type.CREATE, 0, entity, null, -1, entity);
final SimEvent evt = new CloudSimEvent(SimEvent.Type.CREATE, 0, entity, null, -1, entity);
future.addEvent(evt);
}

Expand Down Expand Up @@ -474,7 +474,7 @@ public void sendNow(final SimEntity src, final SimEntity dest, final int tag, fi

@Override
public void send(final SimEntity src, final SimEntity dest, final double delay, final int tag, final Object data) {
send(new CloudSimEvent(this, SimEvent.Type.SEND, delay, src, dest, tag, data));
send(new CloudSimEvent(SimEvent.Type.SEND, delay, src, dest, tag, data));
}

@Override
Expand All @@ -488,7 +488,7 @@ public void send(final SimEvent evt) {

@Override
public void sendFirst(final SimEntity src, final SimEntity dest, final double delay, final int tag, final Object data) {
sendFirst(new CloudSimEvent(this, SimEvent.Type.SEND, delay, src, dest, tag, data));
sendFirst(new CloudSimEvent(SimEvent.Type.SEND, delay, src, dest, tag, data));
}

@Override
Expand Down Expand Up @@ -719,14 +719,14 @@ public boolean resume() {

@Override
public void pauseEntity(final SimEntity src, final double delay) {
final SimEvent evt = new CloudSimEvent(this, SimEvent.Type.HOLD_DONE, delay, src);
final SimEvent evt = new CloudSimEvent(SimEvent.Type.HOLD_DONE, delay, src);
future.addEvent(evt);
src.setState(SimEntity.State.HOLDING);
}

@Override
public void holdEntity(final SimEntity src, final long delay) {
final SimEvent evt = new CloudSimEvent(this, SimEvent.Type.HOLD_DONE, delay, src);
final SimEvent evt = new CloudSimEvent(SimEvent.Type.HOLD_DONE, delay, src);
future.addEvent(evt);
src.setState(SimEntity.State.HOLDING);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public void shutdownEntity() {

@Override
public boolean schedule(final SimEntity dest, final double delay, final int tag, final Object data) {
return schedule(new CloudSimEvent(simulation, delay, this, dest, tag, data));
return schedule(new CloudSimEvent(delay, this, dest, tag, data));
}

@Override
Expand Down Expand Up @@ -208,7 +208,7 @@ public void scheduleFirst(final SimEntity dest, final double delay, final int ta
* @param data The data to be sent with the event.
*/
public void scheduleFirst(final SimEntity dest, final double delay, final int tag, final Object data) {
final CloudSimEvent evt = new CloudSimEvent(simulation, delay, this, dest, tag, data);
final CloudSimEvent evt = new CloudSimEvent(delay, this, dest, tag, data);
if (!canSendEvent(evt)) {
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,91 +60,57 @@ public final class CloudSimEvent implements SimEvent {
*/
private long serial = -1;

/**
* Creates a CloudSimEvent.
*
* @param simulation the Simulation the event belongs to
* @param type the internal type of the event
* @param delay how many seconds after the current simulation time the event should be scheduled
* @param src the source entity which is sending the message
* @param dest the source entity which has to receive the message
* @param tag the tag that identifies the type of the message (which is used by the destination entity to perform operations based on the message type)
* @param data the data attached to the message, that depends on the message tag
*/
public CloudSimEvent(
final Simulation simulation, final Type type, final double delay,
final SimEntity src, final SimEntity dest, final int tag, final Object data)
{
if (delay < 0) {
throw new IllegalArgumentException("Delay can't be negative.");
}

this.simulation = Objects.requireNonNull(simulation);
this.type = type;
this.time = simulation.clock() + delay;
this.src = src;
this.dest = dest;
this.tag = tag;
this.data = data;
}

/**
* Creates a {@link Type#SEND} CloudSimEvent.
*
* @param simulation the Simulation the event belongs to
* @param delay how many seconds after the current simulation time the event should be scheduled
* @param src the source entity which is sending the message
* @param dest the source entity which has to receive the message
* @param tag the tag that identifies the type of the message (which is used by the destination entity to perform operations based on the message type)
* @param data the data attached to the message, that depends on the message tag
*/
public CloudSimEvent(
final Simulation simulation, final double delay,
final SimEntity src, final SimEntity dest, final int tag, final Object data)
final double delay,
final SimEntity src, final SimEntity dest,
final int tag, final Object data)
{
this(simulation, Type.SEND, delay, src, dest, tag, data);
this(Type.SEND, delay, src, dest, tag, data);
}

/**
* Creates a {@link Type#SEND} CloudSimEvent where the sender and destination are the same entity.
*
* @param simulation the Simulation the event belongs to
* @param delay how many seconds after the current simulation time the event should be scheduled
* @param delay how many seconds after the current simulation time the event should be scheduled
* @param dest the source entity which has to receive the message
* @param tag the tag that identifies the type of the message (which is used by the destination entity to perform operations based on the message type)
* @param data the data attached to the message, that depends on the message tag
*/
public CloudSimEvent(
final Simulation simulation, final double delay,
final double delay,
final SimEntity dest, final int tag, final Object data)
{
this(simulation, Type.SEND, delay, dest, dest, tag, data);
this(Type.SEND, delay, dest, dest, tag, data);
}

/**
* Creates a {@link Type#SEND} CloudSimEvent where the sender and destination are the same entity,
* the message has no delay and no data.
*
* @param simulation the Simulation the event belongs to
* @param dest the source entity which has to receive the message
* @param tag the tag that identifies the type of the message (which is used by the destination entity to perform operations based on the message type)
* @todo the simulation object may be got from the destination entity
*/
public CloudSimEvent(
final Simulation simulation, final SimEntity dest, final int tag)
final SimEntity dest, final int tag)
{
this(simulation, Type.SEND, 0, dest, dest, tag, null);
this(Type.SEND, 0, dest, dest, tag, null);
}

/**
* Creates a CloudSimEvent where the destination entity and tag are not set yet.
* Furthermore, there will be not data associated to the event.
*
* @param simulation the Simulation the event belongs to
* @param delay how many seconds after the current simulation time the event should be scheduled
*/
public CloudSimEvent(final Simulation simulation, final Type type, final double delay, final SimEntity src) {
this(simulation, type, delay, src, SimEntity.NULL, -1, null);
public CloudSimEvent(final Type type, final double delay, final SimEntity src) {
this(type, delay, src, SimEntity.NULL, -1, null);
}

/**
Expand All @@ -154,10 +120,37 @@ public CloudSimEvent(final Simulation simulation, final Type type, final double
*/
public CloudSimEvent(final SimEvent src) {
this(
src.getSimulation(), src.getType(), src.getTime(),
src.getType(), src.getTime(),
src.getSource(), src.getDestination(), src.getTag(), src.getData());
}

/**
* Creates a CloudSimEvent.
* @param type the internal type of the event
* @param delay how many seconds after the current simulation time the event should be scheduled
* @param src the source entity which is sending the message
* @param dest the source entity which has to receive the message
* @param tag the tag that identifies the type of the message (which is used by the destination entity to perform operations based on the message type)
* @param data the data attached to the message, that depends on the message tag
*/
public CloudSimEvent(
final Type type, final double delay,
final SimEntity src, final SimEntity dest,
final int tag, final Object data)
{
if (delay < 0) {
throw new IllegalArgumentException("Delay can't be negative.");
}

this.type = type;
this.setSource(src);
this.setDestination(dest);
this.setSimulation(src.getSimulation());
this.time = simulation.clock() + delay;
this.tag = tag;
this.data = data;
}

@Override
public void setSerial(final long serial) {
this.serial = serial;
Expand All @@ -169,13 +162,7 @@ public double getEndWaitingTime() {
}

@Override
public String toString() {
return "Event tag = " + tag + " source = " + src.getName() +
" target = " + dest.getName() + " time = " + time;
}

@Override
public SimEvent setSimulation(final CloudSim simulation) {
public final SimEvent setSimulation(final Simulation simulation) {
this.simulation = Objects.requireNonNull(simulation);
return this;
}
Expand Down Expand Up @@ -228,14 +215,14 @@ public Object getData() {
}

@Override
public SimEvent setSource(final SimEntity source) {
this.src = source;
public final SimEvent setSource(final SimEntity source) {
this.src = Objects.requireNonNull(source);
return this;
}

@Override
public SimEvent setDestination(final SimEntity destination) {
this.dest = destination;
public final SimEvent setDestination(final SimEntity destination) {
this.dest = Objects.requireNonNull(destination);
return this;
}

Expand All @@ -258,4 +245,10 @@ public long getSerial() {
public Simulation getSimulation() {
return simulation;
}

@Override
public String toString() {
return "Event tag = " + tag + " source = " + src.getName() +
" target = " + dest.getName() + " time = " + time;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
*/
package org.cloudbus.cloudsim.core.events;

import org.cloudbus.cloudsim.core.CloudSim;
import org.cloudbus.cloudsim.core.CloudSimTags;
import org.cloudbus.cloudsim.core.SimEntity;
import org.cloudbus.cloudsim.core.Simulation;
Expand Down Expand Up @@ -38,7 +37,7 @@ enum Type {NULL, SEND, HOLD_DONE, CREATE}
* @param simulation the simulation instance to set
* @return
*/
SimEvent setSimulation(CloudSim simulation);
SimEvent setSimulation(Simulation simulation);

/**
* Gets the internal type
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package org.cloudbus.cloudsim.core.events;

import org.cloudbus.cloudsim.core.CloudSim;
import org.cloudbus.cloudsim.core.SimEntity;
import org.cloudbus.cloudsim.core.Simulation;
import org.cloudsimplus.listeners.EventInfo;
Expand All @@ -14,7 +13,7 @@
* @see SimEvent#NULL
*/
final class SimEventNull implements SimEvent {
@Override public SimEvent setSimulation(CloudSim simulation) { return this; }
@Override public SimEvent setSimulation(Simulation simulation) { return this; }
@Override public Type getType() { return Type.NULL; }
@Override public SimEntity getDestination() { return SimEntity.NULL; }
@Override public SimEntity getSource() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ public boolean cloudletReady(final Cloudlet cloudlet) {
the processing update is requested right away.
*/
final Datacenter dc = vm.getHost().getDatacenter();
vm.getSimulation().send(new CloudSimEvent(vm.getSimulation(), dc, CloudSimTags.VM_UPDATE_CLOUDLET_PROCESSING));
vm.getSimulation().send(new CloudSimEvent(dc, CloudSimTags.VM_UPDATE_CLOUDLET_PROCESSING));
return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,20 +174,23 @@ public static double teraToMega(final double tera){
* Converts any value in micro (渭) to milli (m) scale,
* such as microseconds to milliseconds.
*
* <p>The existing {@link java.util.concurrent.TimeUnit} and {@link java.time.Duration} classes
* don't provide the double precision required here.</p>
*
* @param micro the value in micro (渭) scale
* @return the value in milli (m) scale
* @todo Should use TimeUnits class to perform such a conversion
*/
public static double microToMilli(final double micro){
return micro/1000.0;
}

/**
* Converts any value in microseconds (渭) to seconds.
* <p>The existing {@link java.util.concurrent.TimeUnit} and {@link java.time.Duration} classes
* don't provide the double precision required here.</p>
*
* @param micro the value in microseconds (渭)
* @return the value in seconds
* @todo Should use TimeUnits class to perform such a conversion
*/
public static double microToSeconds(final double micro) {
return microToMilli(micro)/1000.0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public enum FieldIndex implements TraceField<GoogleMachineEventsTraceReader> {
*/
@Override
public Double getValue(final GoogleMachineEventsTraceReader reader) {
return Conversion.microToMilli(reader.getFieldIntValue(this));
return Conversion.microToSeconds(reader.getFieldDoubleValue(this));
}
},

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,7 @@ protected TaskEvent createTaskEventFromTraceLine() {

return cloudletLookupFunction
.apply(broker, taskEvent.getUniqueTaskId())
.map(cloudlet -> addCloudletStatusChangeEvents(new CloudSimEvent(simulation, delay, broker, tag, cloudlet), taskEvent))
.map(cloudlet -> addCloudletStatusChangeEvents(new CloudSimEvent(delay, broker, tag, cloudlet), taskEvent))
.isPresent();
}

Expand Down Expand Up @@ -568,7 +568,7 @@ are instantiated based on a class chosen by the researcher.
* This way, it will be executed only when the event is processed.*/
final CloudSimEvent attrsChangeSimEvt =
new CloudSimEvent(
simulation, taskEvent.getTimestamp(),
taskEvent.getTimestamp(),
statusChangeSimEvt.getDestination(),
CloudSimTags.CLOUDLET_UPDATE_ATTRIBUTES, attributesUpdateRunnable);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,7 @@ private boolean requestCloudletUsageChange(final Cloudlet cloudlet, final TaskUs
addAvailableObject(cloudlet);
final CloudSimEvent evt =
new CloudSimEvent(
simulation, taskUsage.getStartTime(), cloudlet.getBroker(),
taskUsage.getStartTime(), cloudlet.getBroker(),
CloudSimTags.CLOUDLET_UPDATE_ATTRIBUTES, resourceUsageUpdateRunnable);
return cloudletUsageChangeEvents.add(evt);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,13 @@ public void teraToMega(){
public void microToMilli1(){
final double micro = 1;
final double expectedMilli = 0.001;
assertEquals(expectedMilli, Conversion.microToMilli(micro),0);
assertEquals(expectedMilli, Conversion.microToMilli(micro), 0);
}

@Test
public void microToMilli1000(){
final double micro = 1000;
final double expectedMilli = 1;
assertEquals(expectedMilli, Conversion.microToMilli(micro),0);
assertEquals(expectedMilli, Conversion.microToMilli(micro), 0);
}
}

0 comments on commit 341b3e2

Please sign in to comment.