Skip to content

Commit

Permalink
adding interfaces to DEECo runners
Browse files Browse the repository at this point in the history
  • Loading branch information
iliasger committed Feb 14, 2015
1 parent d2c04d2 commit 7b91946
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 33 deletions.
Original file line number Diff line number Diff line change
@@ -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;

}
53 changes: 30 additions & 23 deletions jdeeco-core/src/cz/cuni/mff/d3s/deeco/runners/DEECoRun.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
* <p>
* Factory for {@link DEECoNode}.
* </p>
*
* @author Ilias Gerostathopoulos <iliasg@d3s.mff.cuni.cz>
*/
public class DEECoRun {
public class DEECoRun implements DEECoRunner {

List<DEECoNode> nodesList;
DEECoPlugin[] simulationWideplugins;
SimulationSchedulerNotifier simulationSchedulerNotifier;
List<DEECoNode> 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<extraPlugins.length; i++) {
ret[ind] = extraPlugins[i];
for (int i=0; i<nodeSpecificPlugins.length; i++) {
ret[ind] = nodeSpecificPlugins[i];
ind++;
}
for (int j=0; j<simulationWideplugins.length; j++) {
ret[ind] = extraPlugins[j];
for (int j=0; j<nodeWideplugins.length; j++) {
ret[ind] = nodeSpecificPlugins[j];
ind++;
}
return ret;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package cz.cuni.mff.d3s.deeco.runners;

public interface DEECoRunner extends DEECoNodeFactory {

public void start();

}
40 changes: 30 additions & 10 deletions jdeeco-core/src/cz/cuni/mff/d3s/deeco/runners/DEECoSimulation.java
Original file line number Diff line number Diff line change
@@ -1,32 +1,52 @@
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.scheduler.notifier.SimulationSchedulerNotifier;

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

private boolean terminationTimeSet = false;
public class DEECoSimulation implements DEECoSimulationRunner {

public DEECoSimulation(SimulationSchedulerNotifier simulationSchedulerNotifier, DEECoPlugin... simulationWideplugins) {
super(simulationSchedulerNotifier, simulationWideplugins);
}
List<DEECoNode> 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(
"Before starting a simulation you have to specify the termination time.");
}
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;
}

}
Original file line number Diff line number Diff line change
@@ -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);

}

0 comments on commit 7b91946

Please sign in to comment.