From 9afa60d0a9d3a8871c7121bedc8bab028906498a Mon Sep 17 00:00:00 2001 From: Ilias Gerostathopoulos Date: Sat, 14 Feb 2015 16:37:02 +0100 Subject: [PATCH] Renaming "DEECoSimulationRealm" to "DEECoSimulation" and introducing new "simulation" source folder to keep all the simulation-related classes --- .../d3s/deeco/runners/DEECoSimulation.java | 61 +++++++++++++++++++ .../runtime/SimulationSchedulerNotifier.java | 0 .../cuni/mff/d3s/deeco/runners/DEECoRun.java | 11 ++++ .../notifier/CurrentTimeProvider.java | 2 + .../notifier/WallTimeSchedulerNotifier.java | 34 +++++++++++ 5 files changed, 108 insertions(+) create mode 100644 jdeeco-core/simulation/cz/cuni/mff/d3s/deeco/runners/DEECoSimulation.java rename jdeeco-core/{src => simulation}/cz/cuni/mff/d3s/deeco/runtime/SimulationSchedulerNotifier.java (100%) create mode 100644 jdeeco-core/src/cz/cuni/mff/d3s/deeco/runners/DEECoRun.java create mode 100644 jdeeco-core/src/cz/cuni/mff/d3s/deeco/scheduler/notifier/WallTimeSchedulerNotifier.java diff --git a/jdeeco-core/simulation/cz/cuni/mff/d3s/deeco/runners/DEECoSimulation.java b/jdeeco-core/simulation/cz/cuni/mff/d3s/deeco/runners/DEECoSimulation.java new file mode 100644 index 000000000..2344a1659 --- /dev/null +++ b/jdeeco-core/simulation/cz/cuni/mff/d3s/deeco/runners/DEECoSimulation.java @@ -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 + */ +public class DEECoSimulation { + + List 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 + */ +public class DEECoRun { + +} diff --git a/jdeeco-core/src/cz/cuni/mff/d3s/deeco/scheduler/notifier/CurrentTimeProvider.java b/jdeeco-core/src/cz/cuni/mff/d3s/deeco/scheduler/notifier/CurrentTimeProvider.java index a8cfbb06a..826629f3e 100644 --- a/jdeeco-core/src/cz/cuni/mff/d3s/deeco/scheduler/notifier/CurrentTimeProvider.java +++ b/jdeeco-core/src/cz/cuni/mff/d3s/deeco/scheduler/notifier/CurrentTimeProvider.java @@ -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 diff --git a/jdeeco-core/src/cz/cuni/mff/d3s/deeco/scheduler/notifier/WallTimeSchedulerNotifier.java b/jdeeco-core/src/cz/cuni/mff/d3s/deeco/scheduler/notifier/WallTimeSchedulerNotifier.java new file mode 100644 index 000000000..94cf1afab --- /dev/null +++ b/jdeeco-core/src/cz/cuni/mff/d3s/deeco/scheduler/notifier/WallTimeSchedulerNotifier.java @@ -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; + } +}