Skip to content

Commit

Permalink
Renaming "DEECoSimulationRealm" to "DEECoSimulation" and introducing new
Browse files Browse the repository at this point in the history
"simulation" source folder to keep all the simulation-related classes
  • Loading branch information
iliasger committed Feb 14, 2015
1 parent 1c560b4 commit 9afa60d
Show file tree
Hide file tree
Showing 5 changed files with 108 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package cz.cuni.mff.d3s.deeco.runners;

import java.util.ArrayList;
import java.util.List;

import cz.cuni.mff.d3s.deeco.runtime.DEECoException;
import cz.cuni.mff.d3s.deeco.runtime.DEECoNode;
import cz.cuni.mff.d3s.deeco.runtime.DEECoPlugin;
import cz.cuni.mff.d3s.deeco.runtime.SimulationSchedulerNotifier;

/**
* Main class for launching DEECo simulations.
*
* @author Ilias Gerostathopoulos <iliasg@d3s.mff.cuni.cz>
*/
public class DEECoSimulation {

List<DEECoNode> nodesList;
DEECoPlugin[] simulationWideplugins;
SimulationSchedulerNotifier simulationSchedulerNotifier;

public DEECoSimulation(SimulationSchedulerNotifier simulationSchedulerNotifier, DEECoPlugin... simulationWideplugins) {
this.simulationWideplugins = simulationWideplugins;
this.simulationSchedulerNotifier = simulationSchedulerNotifier;
nodesList = new ArrayList<>();
}

public void start() {
simulationSchedulerNotifier.start();
}

public DEECoNode createNode(DEECoPlugin... extraPlugins) throws DEECoException {
DEECoNode node = new DEECoNode(simulationSchedulerNotifier, getAllPlugins(extraPlugins));
nodesList.add(node);
return node;
}

public void setTerminationTime(long terminationTime) {
simulationSchedulerNotifier.setTerminationTime(terminationTime);
}

/**
* Concatenates the array of simulation-wide plugins with node-specific plugins.
* The returned array is intended to be passed to the DEECoNode() constructor.
* @param extraPlugins node-specific plugins
*/
private DEECoPlugin[] getAllPlugins(DEECoPlugin[] extraPlugins) {
DEECoPlugin[] ret = new DEECoPlugin[extraPlugins.length+simulationWideplugins.length];
int ind=0;
for (int i=0; i<extraPlugins.length; i++) {
ret[ind] = extraPlugins[i];
ind++;
}
for (int j=0; j<simulationWideplugins.length; j++) {
ret[ind] = extraPlugins[j];
ind++;
}
return ret;
}

}
11 changes: 11 additions & 0 deletions jdeeco-core/src/cz/cuni/mff/d3s/deeco/runners/DEECoRun.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package cz.cuni.mff.d3s.deeco.runners;

/**
* Main class for running DEECo in "real" deployment.
* For simulation purposes use {@link DEECoSimulation} instead.
*
* @author Ilias Gerostathopoulos <iliasg@d3s.mff.cuni.cz>
*/
public class DEECoRun {

}
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package cz.cuni.mff.d3s.deeco.scheduler.notifier;

/**
* TODO(Ilias): Merge this interface with the SchedulerNotifier interface before releasing jDEECo 3.0.
*
* Gives access to current time in milliseconds.
*
* @author Michal Kit <kit@d3s.mff.cuni.cz>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package cz.cuni.mff.d3s.deeco.scheduler.notifier;


public class WallTimeSchedulerNotifier extends DiscreteEventSchedulerNotifier {

long terminationTime;

public void start() {

while (!tryToTerminate()) {
EventTime eventTime = eventTimes.remove();
long nextEventTime = eventTime.getTimePoint();
try {
Thread.sleep(nextEventTime-currentTime);
currentTime = nextEventTime;
} catch (InterruptedException e) {
e.printStackTrace();
}
eventTime.getListener().at(currentTime);
}
}

public boolean tryToTerminate() {
if (currentTime < terminationTime) {
return false;
}
eventTimes.clear();
return true;
}

public void setTerminationTime(long terminationTime) {
this.terminationTime = terminationTime;
}
}

0 comments on commit 9afa60d

Please sign in to comment.