diff --git a/jdeeco-core/src/cz/cuni/mff/d3s/deeco/runners/DEECoNodeFactory.java b/jdeeco-core/src/cz/cuni/mff/d3s/deeco/runners/DEECoNodeFactory.java new file mode 100644 index 000000000..af012aff6 --- /dev/null +++ b/jdeeco-core/src/cz/cuni/mff/d3s/deeco/runners/DEECoNodeFactory.java @@ -0,0 +1,11 @@ +package cz.cuni.mff.d3s.deeco.runners; + +import cz.cuni.mff.d3s.deeco.runtime.DEECoException; +import cz.cuni.mff.d3s.deeco.runtime.DEECoNode; +import cz.cuni.mff.d3s.deeco.runtime.DEECoPlugin; + +public interface DEECoNodeFactory { + + public DEECoNode createNode(DEECoPlugin... nodeSpecificPlugins) throws DEECoException; + +} diff --git a/jdeeco-core/src/cz/cuni/mff/d3s/deeco/runners/DEECoRun.java b/jdeeco-core/src/cz/cuni/mff/d3s/deeco/runners/DEECoRun.java index ded8e1247..5aeccd702 100644 --- a/jdeeco-core/src/cz/cuni/mff/d3s/deeco/runners/DEECoRun.java +++ b/jdeeco-core/src/cz/cuni/mff/d3s/deeco/runners/DEECoRun.java @@ -6,50 +6,57 @@ 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.scheduler.notifier.SimulationSchedulerNotifier; +import cz.cuni.mff.d3s.deeco.scheduler.notifier.SchedulerNotifier; /** - * Main class for running DEECo in "real" deployment. + * Main entry for running DEECo in "real" deployment. * For simulation purposes use {@link DEECoSimulation} instead. * + *

+ * Factory for {@link DEECoNode}. + *

+ * * @author Ilias Gerostathopoulos */ -public class DEECoRun { +public class DEECoRun implements DEECoRunner { - List nodesList; - DEECoPlugin[] simulationWideplugins; - SimulationSchedulerNotifier simulationSchedulerNotifier; + List deecoNodes; + DEECoPlugin[] nodeWideplugins; + + SchedulerNotifier schedulerNotifier; - public DEECoRun(SimulationSchedulerNotifier simulationSchedulerNotifier, DEECoPlugin... simulationWideplugins) { - this.simulationWideplugins = simulationWideplugins; - this.simulationSchedulerNotifier = simulationSchedulerNotifier; - nodesList = new ArrayList<>(); + public DEECoRun(SchedulerNotifier schedulerNotifier, DEECoPlugin... nodeWideplugins) { + this.nodeWideplugins = nodeWideplugins; + this.schedulerNotifier = schedulerNotifier; + deecoNodes = new ArrayList<>(); } - public void start() throws TerminationTimeNotSetException { - simulationSchedulerNotifier.start(); + @Override + public void start() { + schedulerNotifier.start(); } - public DEECoNode createNode(DEECoPlugin... extraPlugins) throws DEECoException { - DEECoNode node = new DEECoNode(simulationSchedulerNotifier, getAllPlugins(extraPlugins)); - nodesList.add(node); + @Override + public DEECoNode createNode(DEECoPlugin... nodeSpecificPlugins) throws DEECoException { + DEECoNode node = new DEECoNode(schedulerNotifier, getAllPlugins(nodeWideplugins, nodeSpecificPlugins)); + deecoNodes.add(node); return node; } /** - * Concatenates the array of simulation-wide plugins with node-specific plugins. + * Helper method that concatenates the array of node-wide plugins with node-specific plugins. * The returned array is intended to be passed to the DEECoNode() constructor. - * @param extraPlugins node-specific plugins + * @param nodeSpecificPlugins extra plugins, not provided by the factory */ - private DEECoPlugin[] getAllPlugins(DEECoPlugin[] extraPlugins) { - DEECoPlugin[] ret = new DEECoPlugin[extraPlugins.length+simulationWideplugins.length]; + static DEECoPlugin[] getAllPlugins(DEECoPlugin[] nodeWideplugins, DEECoPlugin[] nodeSpecificPlugins) { + DEECoPlugin[] ret = new DEECoPlugin[nodeSpecificPlugins.length+nodeWideplugins.length]; int ind=0; - for (int i=0; i */ -public class DEECoSimulation extends DEECoRun { - - private boolean terminationTimeSet = false; +public class DEECoSimulation implements DEECoSimulationRunner { - public DEECoSimulation(SimulationSchedulerNotifier simulationSchedulerNotifier, DEECoPlugin... simulationWideplugins) { - super(simulationSchedulerNotifier, simulationWideplugins); - } + List deecoNodes; + DEECoPlugin[] nodeWideplugins; + + SimulationSchedulerNotifier simulationSchedulerNotifier; + boolean terminationTimeSet = false; - public void setTerminationTime(long terminationTime) { - simulationSchedulerNotifier.setTerminationTime(terminationTime); - terminationTimeSet = true; + public DEECoSimulation(SimulationSchedulerNotifier simulationSchedulerNotifier, DEECoPlugin... nodeWideplugins) { + this.nodeWideplugins = nodeWideplugins; + this.simulationSchedulerNotifier = simulationSchedulerNotifier; + deecoNodes = new ArrayList<>(); } + @Override public void start() throws TerminationTimeNotSetException { if (!terminationTimeSet) { throw new TerminationTimeNotSetException( @@ -28,5 +35,18 @@ public void start() throws TerminationTimeNotSetException { } simulationSchedulerNotifier.start(); } + + @Override + public DEECoNode createNode(DEECoPlugin... nodeSpecificPlugins) throws DEECoException { + DEECoNode node = new DEECoNode(simulationSchedulerNotifier, DEECoRun.getAllPlugins(nodeWideplugins, nodeSpecificPlugins)); + deecoNodes.add(node); + return node; + } + + @Override + public void setTerminationTime(long terminationTime) { + simulationSchedulerNotifier.setTerminationTime(terminationTime); + terminationTimeSet = true; + } } diff --git a/jdeeco-core/src/cz/cuni/mff/d3s/deeco/runners/DEECoSimulationRunner.java b/jdeeco-core/src/cz/cuni/mff/d3s/deeco/runners/DEECoSimulationRunner.java new file mode 100644 index 000000000..5c87bf4a9 --- /dev/null +++ b/jdeeco-core/src/cz/cuni/mff/d3s/deeco/runners/DEECoSimulationRunner.java @@ -0,0 +1,9 @@ +package cz.cuni.mff.d3s.deeco.runners; + +public interface DEECoSimulationRunner extends DEECoNodeFactory { + + public void start() throws TerminationTimeNotSetException; + + public void setTerminationTime(long terminationTime); + +}