init
This commit is contained in:
39
src/org/cloudbus/cloudsim/core/predicates/Predicate.java
Normal file
39
src/org/cloudbus/cloudsim/core/predicates/Predicate.java
Normal file
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* Title: CloudSim Toolkit
|
||||
* Description: CloudSim (Cloud Simulation) Toolkit for Modeling and Simulation of Clouds
|
||||
* Licence: GPL - http://www.gnu.org/copyleft/gpl.html
|
||||
*
|
||||
* Copyright (c) 2009-2012, The University of Melbourne, Australia
|
||||
*/
|
||||
|
||||
package org.cloudbus.cloudsim.core.predicates;
|
||||
|
||||
import org.cloudbus.cloudsim.core.SimEvent;
|
||||
|
||||
/**
|
||||
* Predicates are used to select events from the deferred queue. This class is abstract and must be
|
||||
* extended when writing a new predicate. Some standard predicates are provided.<br>
|
||||
* The idea of simulation predicates was copied from SimJava 2.
|
||||
*
|
||||
* @author Marcos Dias de Assuncao
|
||||
* @since CloudSim Toolkit 1.0
|
||||
* @see PredicateType
|
||||
* @see PredicateFrom
|
||||
* @see PredicateAny
|
||||
* @see PredicateNone
|
||||
* @see Simulation
|
||||
*/
|
||||
public abstract class Predicate {
|
||||
|
||||
/**
|
||||
* The match function which must be overridden when writing a new predicate. The function is
|
||||
* called with each event in the deferred queue as its parameter when a
|
||||
* <code>Simulation.select()</code> call is made by the user.
|
||||
*
|
||||
* @param event The event to test for a match.
|
||||
* @return The function should return <code>true</code> if the event matches and should be
|
||||
* selected, or <code>false</code> if it does not match the predicate.
|
||||
*/
|
||||
public abstract boolean match(SimEvent event);
|
||||
|
||||
}
|
||||
37
src/org/cloudbus/cloudsim/core/predicates/PredicateAny.java
Normal file
37
src/org/cloudbus/cloudsim/core/predicates/PredicateAny.java
Normal file
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
* Title: CloudSim Toolkit
|
||||
* Description: CloudSim (Cloud Simulation) Toolkit for Modeling and Simulation of Clouds
|
||||
* Licence: GPL - http://www.gnu.org/copyleft/gpl.html
|
||||
*
|
||||
* Copyright (c) 2009-2012, The University of Melbourne, Australia
|
||||
*/
|
||||
|
||||
package org.cloudbus.cloudsim.core.predicates;
|
||||
|
||||
import org.cloudbus.cloudsim.core.SimEvent;
|
||||
|
||||
/**
|
||||
* A predicate which will match any event on the deferred event queue. There is a publicly
|
||||
* accessible instance of this predicate in <code>Simulation</code>, called
|
||||
* <code>Simulation.SIM_ANY</code>, so no new instances need to be created. <br>
|
||||
* The idea of simulation predicates was copied from SimJava 2.
|
||||
*
|
||||
* @author Marcos Dias de Assuncao
|
||||
* @since CloudSim Toolkit 1.0
|
||||
* @see Predicate
|
||||
* @see Simulation
|
||||
*/
|
||||
public class PredicateAny extends Predicate {
|
||||
|
||||
/**
|
||||
* The match function called by <code>Simulation</code>, not used directly by the user.
|
||||
*
|
||||
* @param ev the ev
|
||||
* @return true, if match
|
||||
*/
|
||||
@Override
|
||||
public boolean match(SimEvent ev) {
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
62
src/org/cloudbus/cloudsim/core/predicates/PredicateFrom.java
Normal file
62
src/org/cloudbus/cloudsim/core/predicates/PredicateFrom.java
Normal file
@@ -0,0 +1,62 @@
|
||||
/*
|
||||
* Title: CloudSim Toolkit
|
||||
* Description: CloudSim (Cloud Simulation) Toolkit for Modeling and Simulation of Clouds
|
||||
* Licence: GPL - http://www.gnu.org/copyleft/gpl.html
|
||||
*
|
||||
* Copyright (c) 2009-2012, The University of Melbourne, Australia
|
||||
*/
|
||||
|
||||
package org.cloudbus.cloudsim.core.predicates;
|
||||
|
||||
import org.cloudbus.cloudsim.core.SimEvent;
|
||||
|
||||
/**
|
||||
* A predicate which selects events from specific entities.<br>
|
||||
* The idea of simulation predicates was copied from SimJava 2.
|
||||
*
|
||||
* @author Marcos Dias de Assuncao
|
||||
* @since CloudSim Toolkit 1.0
|
||||
* @see PredicateNotFrom
|
||||
* @see Predicate
|
||||
*/
|
||||
public class PredicateFrom extends Predicate {
|
||||
|
||||
/** The ids. */
|
||||
private final int[] ids;
|
||||
|
||||
/**
|
||||
* Constructor used to select events that were sent by a specific entity.
|
||||
*
|
||||
* @param sourceId the id number of the source entity
|
||||
*/
|
||||
public PredicateFrom(int sourceId) {
|
||||
ids = new int[] { sourceId };
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor used to select events that were sent by any entity from a given set.
|
||||
*
|
||||
* @param sourceIds the set of id numbers of the source entities
|
||||
*/
|
||||
public PredicateFrom(int[] sourceIds) {
|
||||
ids = sourceIds.clone();
|
||||
}
|
||||
|
||||
/**
|
||||
* The match function called by <code>Simulation</code>, not used directly by the user.
|
||||
*
|
||||
* @param ev the event to check
|
||||
* @return <code>true</code> if the event matches the predicate, <code>false</code> otherwise
|
||||
*/
|
||||
@Override
|
||||
public boolean match(SimEvent ev) {
|
||||
int src = ev.getSource();
|
||||
for (int id : ids) {
|
||||
if (src == id) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
37
src/org/cloudbus/cloudsim/core/predicates/PredicateNone.java
Normal file
37
src/org/cloudbus/cloudsim/core/predicates/PredicateNone.java
Normal file
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
* Title: CloudSim Toolkit
|
||||
* Description: CloudSim (Cloud Simulation) Toolkit for Modeling and Simulation of Clouds
|
||||
* Licence: GPL - http://www.gnu.org/copyleft/gpl.html
|
||||
*
|
||||
* Copyright (c) 2009-2012, The University of Melbourne, Australia
|
||||
*/
|
||||
|
||||
package org.cloudbus.cloudsim.core.predicates;
|
||||
|
||||
import org.cloudbus.cloudsim.core.SimEvent;
|
||||
|
||||
/**
|
||||
* A predicate which will <b>not</b> match any event on the deferred event queue. There is a
|
||||
* publicly accessible instance of this predicate in the {@link Simulation} class, called
|
||||
* {@link Simulation#SIM_NONE}, so the user does not need to create any new instances. The idea of
|
||||
* simulation predicates was copied from SimJava 2.
|
||||
*
|
||||
* @author Marcos Dias de Assuncao
|
||||
* @since CloudSim Toolkit 1.0
|
||||
* @see Predicate
|
||||
* @see Simulation
|
||||
*/
|
||||
public class PredicateNone extends Predicate {
|
||||
|
||||
/**
|
||||
* The match function called by {@link Simulation}, not used directly by the user.
|
||||
*
|
||||
* @param ev the event to check
|
||||
* @return <code>true</code> if the event matches the predicate, <code>false</code> otherwise
|
||||
*/
|
||||
@Override
|
||||
public boolean match(SimEvent ev) {
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
* Title: CloudSim Toolkit
|
||||
* Description: CloudSim (Cloud Simulation) Toolkit for Modeling and Simulation of Clouds
|
||||
* Licence: GPL - http://www.gnu.org/copyleft/gpl.html
|
||||
*
|
||||
* Copyright (c) 2009-2012, The University of Melbourne, Australia
|
||||
*/
|
||||
|
||||
package org.cloudbus.cloudsim.core.predicates;
|
||||
|
||||
import org.cloudbus.cloudsim.core.SimEvent;
|
||||
|
||||
/**
|
||||
* A predicate which selects events that have not been sent by specific entities.
|
||||
*
|
||||
* @author Marcos Dias de Assuncao
|
||||
* @since CloudSim Toolkit 1.0
|
||||
* @see PredicateFrom
|
||||
* @see Predicate
|
||||
*/
|
||||
public class PredicateNotFrom extends Predicate {
|
||||
|
||||
/** The ids. */
|
||||
private final int[] ids;
|
||||
|
||||
/**
|
||||
* Constructor used to select events that were not sent by a specific entity.
|
||||
*
|
||||
* @param sourceId the id number of the source entity
|
||||
*/
|
||||
public PredicateNotFrom(int sourceId) {
|
||||
ids = new int[] { sourceId };
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor used to select events that were not sent by any entity from a given set.
|
||||
*
|
||||
* @param sourceIds the set of id numbers of the source entities
|
||||
*/
|
||||
public PredicateNotFrom(int[] sourceIds) {
|
||||
ids = sourceIds.clone();
|
||||
}
|
||||
|
||||
/**
|
||||
* The match function called by {@link Simulation}, not used directly by the user.
|
||||
*
|
||||
* @param ev the event to check
|
||||
* @return <code>true</code> if the event matches the predicate, <code>false</code> otherwise
|
||||
*/
|
||||
@Override
|
||||
public boolean match(SimEvent ev) {
|
||||
int src = ev.getSource();
|
||||
for (int id : ids) {
|
||||
if (src == id) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
* Title: CloudSim Toolkit
|
||||
* Description: CloudSim (Cloud Simulation) Toolkit for Modeling and Simulation of Clouds
|
||||
* Licence: GPL - http://www.gnu.org/copyleft/gpl.html
|
||||
*
|
||||
* Copyright (c) 2009-2012, The University of Melbourne, Australia
|
||||
*/
|
||||
|
||||
package org.cloudbus.cloudsim.core.predicates;
|
||||
|
||||
import org.cloudbus.cloudsim.core.SimEvent;
|
||||
|
||||
/**
|
||||
* A predicate to select events that don't match specific tags.
|
||||
*
|
||||
* @author Marcos Dias de Assuncao
|
||||
* @since CloudSim Toolkit 1.0
|
||||
* @see PredicateType
|
||||
* @see Predicate
|
||||
*/
|
||||
public class PredicateNotType extends Predicate {
|
||||
|
||||
/** The tags. */
|
||||
private final int[] tags;
|
||||
|
||||
/**
|
||||
* Constructor used to select events whose tags do not match a given tag.
|
||||
*
|
||||
* @param tag An event tag value
|
||||
*/
|
||||
public PredicateNotType(int tag) {
|
||||
tags = new int[] { tag };
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor used to select events whose tag values do not match any of the given tags.
|
||||
*
|
||||
* @param tags the list of tags
|
||||
*/
|
||||
public PredicateNotType(int[] tags) {
|
||||
this.tags = tags.clone();
|
||||
}
|
||||
|
||||
/**
|
||||
* The match function called by {@link Simulation}, not used directly by the user.
|
||||
*
|
||||
* @param ev the ev
|
||||
* @return true, if match
|
||||
*/
|
||||
@Override
|
||||
public boolean match(SimEvent ev) {
|
||||
int tag = ev.getTag();
|
||||
for (int tag2 : tags) {
|
||||
if (tag == tag2) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
61
src/org/cloudbus/cloudsim/core/predicates/PredicateType.java
Normal file
61
src/org/cloudbus/cloudsim/core/predicates/PredicateType.java
Normal file
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
* Title: CloudSim Toolkit
|
||||
* Description: CloudSim (Cloud Simulation) Toolkit for Modeling and Simulation of Clouds
|
||||
* Licence: GPL - http://www.gnu.org/copyleft/gpl.html
|
||||
*
|
||||
* Copyright (c) 2009-2012, The University of Melbourne, Australia
|
||||
*/
|
||||
|
||||
package org.cloudbus.cloudsim.core.predicates;
|
||||
|
||||
import org.cloudbus.cloudsim.core.SimEvent;
|
||||
|
||||
/**
|
||||
* A predicate to select events with specific tags.
|
||||
*
|
||||
* @author Marcos Dias de Assuncao
|
||||
* @since CloudSim Toolkit 1.0
|
||||
* @see PredicateNotType
|
||||
* @see Predicate
|
||||
*/
|
||||
public class PredicateType extends Predicate {
|
||||
|
||||
/** The tags. */
|
||||
private final int[] tags;
|
||||
|
||||
/**
|
||||
* Constructor used to select events with the tag value <code>t1</code>.
|
||||
*
|
||||
* @param t1 an event tag value
|
||||
*/
|
||||
public PredicateType(int t1) {
|
||||
tags = new int[] { t1 };
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor used to select events with a tag value equal to any of the specified tags.
|
||||
*
|
||||
* @param tags the list of tags
|
||||
*/
|
||||
public PredicateType(int[] tags) {
|
||||
this.tags = tags.clone();
|
||||
}
|
||||
|
||||
/**
|
||||
* The match function called by <code>Sim_system</code>, not used directly by the user.
|
||||
*
|
||||
* @param ev the ev
|
||||
* @return true, if match
|
||||
*/
|
||||
@Override
|
||||
public boolean match(SimEvent ev) {
|
||||
int tag = ev.getTag();
|
||||
for (int tag2 : tags) {
|
||||
if (tag == tag2) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user