Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/plugin-architecture' into
Browse files Browse the repository at this point in the history
omnet-plugin

Conflicts:
	jdeeco-core/src/cz/cuni/mff/d3s/deeco/task/EnsembleTask.java
	jdeeco-simulation/src/cz/cuni/mff/d3s/deeco/simulation/task/TimerTask.java
  • Loading branch information
vladamatena committed Feb 17, 2015
2 parents 7a878f9 + caff626 commit 66930ab
Show file tree
Hide file tree
Showing 45 changed files with 1,506 additions and 1,355 deletions.
686 changes: 682 additions & 4 deletions jdeeco-architecture/2015/architecture-2015-02-04.emx

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@
import cz.cuni.mff.d3s.deeco.model.runtime.meta.RuntimeMetadataFactory;
import cz.cuni.mff.d3s.deeco.network.CommunicationBoundaryPredicate;
import cz.cuni.mff.d3s.deeco.network.GenericCommunicationBoundaryPredicate;
import cz.cuni.mff.d3s.deeco.runtime.DuplicateEnsembleDefinitionException;
import cz.cuni.mff.d3s.deeco.security.ModelSecurityValidator;
import cz.cuni.mff.d3s.deeco.task.KnowledgePathHelper;

Expand Down Expand Up @@ -155,6 +156,12 @@ enum ParsingEvent {
*/
List<AnnotationProcessorExtensionPoint> extensions;

/**
* Maintains the set of known ensemble definitions for the purpose of guarding against duplicate deployment of one ensemble.
*/
@SuppressWarnings("rawtypes")
Set<Class> knownEnsembleDefinitions;

KnowledgeManagerFactory knowledgeManagerFactory;

Cloner cloner;
Expand All @@ -172,6 +179,7 @@ enum ParsingEvent {
* one or more classes extending the <code>AnnotationProcessorExtensionPoint</code> that provide additional processing functionality
* @param knowledgeMangerFactory knowledge manager factory to be used
*/
@SuppressWarnings("rawtypes")
public AnnotationProcessor(RuntimeMetadataFactory factory, RuntimeMetadata model, KnowledgeManagerFactory knowledgeMangerFactory,
AnnotationProcessorExtensionPoint... extensions) {
this.factory = factory;
Expand All @@ -183,6 +191,7 @@ public AnnotationProcessor(RuntimeMetadataFactory factory, RuntimeMetadata model
}
this.knowledgeManagerFactory = knowledgeMangerFactory;
this.cloner = new Cloner();
knownEnsembleDefinitions = new HashSet<Class>();
}

/**
Expand Down Expand Up @@ -253,9 +262,10 @@ public ComponentInstance processComponent(Object componentObj) throws Annotation
* @param ensembleClass
* object to be processed
* @throws AnnotationProcessorException
* @throws DuplicateEnsembleDefinitionException
*/
@SuppressWarnings("rawtypes")
public EnsembleDefinition processEnsemble(Class ensembleClass) throws AnnotationProcessorException {
public EnsembleDefinition processEnsemble(Class ensembleClass) throws AnnotationProcessorException, DuplicateEnsembleDefinitionException {
if (model == null) {
throw new AnnotationProcessorException("Provided model cannot be null.");
}
Expand All @@ -266,6 +276,9 @@ public EnsembleDefinition processEnsemble(Class ensembleClass) throws Annotation
throw new AnnotationProcessorException("Class: " + ensembleClass.getCanonicalName() +
"->No @" + Ensemble.class.getSimpleName() + " annotation found.");
}
if(knownEnsembleDefinitions.contains(ensembleClass)) {
throw new DuplicateEnsembleDefinitionException(ensembleClass);
}

EnsembleDefinition ed = createEnsembleDefinition(ensembleClass);
model.getEnsembleDefinitions().add(ed);
Expand All @@ -276,6 +289,8 @@ public EnsembleDefinition processEnsemble(Class ensembleClass) throws Annotation
ci.getEnsembleControllers().add(ec);
ec.setComponentInstance(ci);
}

knownEnsembleDefinitions.add(ensembleClass);

return ed;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package cz.cuni.mff.d3s.deeco.network;

import cz.cuni.mff.d3s.deeco.scheduler.CurrentTimeProvider;
import cz.cuni.mff.d3s.deeco.timer.CurrentTimeProvider;

@SuppressWarnings("rawtypes")
public abstract class AbstractHost implements CurrentTimeProvider {
Expand Down
2 changes: 1 addition & 1 deletion jdeeco-core/src/cz/cuni/mff/d3s/deeco/network/Host.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package cz.cuni.mff.d3s.deeco.network;

import cz.cuni.mff.d3s.deeco.scheduler.CurrentTimeProvider;
import cz.cuni.mff.d3s.deeco.timer.CurrentTimeProvider;

/**
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
import cz.cuni.mff.d3s.deeco.integrity.RatingsManager;
import cz.cuni.mff.d3s.deeco.knowledge.KnowledgeManagerContainer;
import cz.cuni.mff.d3s.deeco.logging.Log;
import cz.cuni.mff.d3s.deeco.scheduler.CurrentTimeProvider;
import cz.cuni.mff.d3s.deeco.scheduler.Scheduler;
import cz.cuni.mff.d3s.deeco.security.SecurityKeyManager;
import cz.cuni.mff.d3s.deeco.timer.CurrentTimeProvider;


/**
Expand Down Expand Up @@ -76,7 +76,7 @@ public void initialize(
RatingsManager ratingsManager) {
this.host = host;
this.scheduler = scheduler;
this.timeProvider = scheduler;
this.timeProvider = scheduler.getTimer();
this.kmContainer = kmContainer;
this.dataSender = dataSender;
this.keyManager = keyManager;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

import cz.cuni.mff.d3s.deeco.DeecoProperties;
import cz.cuni.mff.d3s.deeco.logging.Log;
import cz.cuni.mff.d3s.deeco.scheduler.CurrentTimeProvider;
import cz.cuni.mff.d3s.deeco.timer.CurrentTimeProvider;

/**
* This class enables receiving {@link KnowledgeData} that comes from the
Expand Down
26 changes: 26 additions & 0 deletions jdeeco-core/src/cz/cuni/mff/d3s/deeco/runners/DEECoRunner.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package cz.cuni.mff.d3s.deeco.runners;

import cz.cuni.mff.d3s.deeco.runtime.DEECoNode;
import cz.cuni.mff.d3s.deeco.timer.RunnerTimer;

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

DEECoNode deecoNode;
RunnerTimer runnerTimer;

public DEECoRunner(RunnerTimer runnerTimer, DEECoNode deecoNode) {
this.runnerTimer = runnerTimer;
this.deecoNode = deecoNode;
}

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

}
57 changes: 57 additions & 0 deletions jdeeco-core/src/cz/cuni/mff/d3s/deeco/runners/DEECoSimulation.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
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.timer.SimulationTimer;

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

List<DEECoNode> deecoNodes;
DEECoPlugin[] nodeWideplugins;
SimulationTimer simulationTimer;

public DEECoSimulation(SimulationTimer simulationTimer, DEECoPlugin... nodeWideplugins) {
this.nodeWideplugins = nodeWideplugins;
this.simulationTimer = simulationTimer;
deecoNodes = new ArrayList<>();
}

public void start(long duration) {
simulationTimer.start(duration);
}

public DEECoNode createNode(DEECoPlugin... nodeSpecificPlugins) throws DEECoException {
DEECoNode node = new DEECoNode(simulationTimer, getAllPlugins(nodeWideplugins, nodeSpecificPlugins));
deecoNodes.add(node);
return node;
}

/**
* 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 nodeSpecificPlugins extra plugins, not provided by the factory
*/
private DEECoPlugin[] getAllPlugins(DEECoPlugin[] nodeWideplugins, DEECoPlugin[] nodeSpecificPlugins) {
DEECoPlugin[] ret = new DEECoPlugin[nodeSpecificPlugins.length+nodeWideplugins.length];
int ind=0;
for (int i=0; i<nodeSpecificPlugins.length; i++) {
ret[ind] = nodeSpecificPlugins[i];
ind++;
}
for (int j=0; j<nodeWideplugins.length; j++) {
ret[ind] = nodeSpecificPlugins[j];
ind++;
}
return ret;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,7 @@ public interface DEECoContainer {
*/
@SuppressWarnings("rawtypes")
public EnsembleDefinition deployEnsemble(Class ensembles) throws AnnotationProcessorException, DuplicateEnsembleDefinitionException;

/**
* Returns true if the DEECo application is running, otherwise false.
*/
boolean isRunning();

public int getId();

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,10 @@
import java.util.ArrayList;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.Set;

import cz.cuni.mff.d3s.deeco.annotations.processor.AnnotationProcessor;
import cz.cuni.mff.d3s.deeco.annotations.processor.AnnotationProcessorException;
Expand All @@ -21,17 +19,23 @@
import cz.cuni.mff.d3s.deeco.model.runtime.api.EnsembleDefinition;
import cz.cuni.mff.d3s.deeco.model.runtime.api.RuntimeMetadata;
import cz.cuni.mff.d3s.deeco.model.runtime.custom.RuntimeMetadataFactoryExt;
import cz.cuni.mff.d3s.deeco.scheduler.NoExecutorAvailableException;
import cz.cuni.mff.d3s.deeco.scheduler.Scheduler;
import cz.cuni.mff.d3s.deeco.scheduler.SingleThreadedScheduler;
import cz.cuni.mff.d3s.deeco.timer.Timer;

/**
* Main container for a DEECo application.
*
* @author Ilias Gerostathopoulos <iliasg@d3s.mff.cuni.cz>
* @author Filip Krijt <krijt@d3s.mff.cuni.cz>
*/
public class DEECo implements DEECoContainer {
public class DEECoNode implements DEECoContainer {

/**
* TODO find a way to inject this field from the DEECoRealm (probably via the constructor here?)
*/
int id;
/**
* The metadata model corresponding to the running application.
*/
Expand All @@ -57,57 +61,29 @@ public class DEECo implements DEECoContainer {
*/
Map<Class<? extends DEECoPlugin>, DEECoPlugin> pluginsMap;

/**
* Maintains the set of known ensemble definitions for the purpose of guarding against duplicate deployment of one ensemble.
*/
Set<Class> knownEnsembleDefinitions;

/**
* True if this DEECo application is running.
*/
protected boolean running = false;


public DEECo(DEECoPlugin... plugins) throws PluginDependencyException {
public DEECoNode(Timer Timer, DEECoPlugin... plugins) throws DEECoException {
pluginsMap= new HashMap<>();
knownEnsembleDefinitions = new HashSet<Class>();
model = RuntimeMetadataFactoryExt.eINSTANCE.createRuntimeMetadata();
knowledgeManagerFactory = new CloningKnowledgeManagerFactory();
processor = new AnnotationProcessor(RuntimeMetadataFactoryExt.eINSTANCE, model, knowledgeManagerFactory);

createRuntime();
createRuntime(Timer);
runtime.init(this);
initializePlugins(plugins);
}

@Override
public int getId() {
return id;
}

public ComponentInstance deployComponent(Object component) throws AnnotationProcessorException {
return processor.processComponent(component);
}

@SuppressWarnings("rawtypes")
public EnsembleDefinition deployEnsemble(Class ensemble) throws AnnotationProcessorException, DuplicateEnsembleDefinitionException {
if(knownEnsembleDefinitions.contains(ensemble))
throw new DuplicateEnsembleDefinitionException(ensemble);

EnsembleDefinition ensembleDefinition = processor.processEnsemble(ensemble);
knownEnsembleDefinitions.add(ensemble);
return ensembleDefinition;
}

public void start() throws InvalidOperationException {
if(running)
throw new InvalidOperationException("start");

runtime.start();
running = true;
}

public void stop() throws InvalidOperationException {
if(!running)
throw new InvalidOperationException("stop");

runtime.stop();
running = false;
return processor.processEnsemble(ensemble);
}

@Override
Expand All @@ -132,12 +108,6 @@ public RuntimeMetadata getRuntimeMetadata() {
return model;
}

@Override
public boolean isRunning()
{
return running;
}

class DependencyNode {
DEECoPlugin plugin;
List<DependencyNode> dependantPlugins = new ArrayList<>();
Expand Down Expand Up @@ -188,7 +158,7 @@ List<DependencyNode> constructDependencyNodes(DEECoPlugin[] plugins) throws Plug

void initializePlugins(DEECoPlugin[] plugins) throws PluginDependencyException {
List<DependencyNode> nodes = constructDependencyNodes(plugins);
Queue<DependencyNode> queue = new PriorityQueue<DEECo.DependencyNode>(new DependencyNodeComparator());
Queue<DependencyNode> queue = new PriorityQueue<DEECoNode.DependencyNode>(new DependencyNodeComparator());

for(DependencyNode n : nodes)
{
Expand All @@ -214,9 +184,9 @@ void initializePlugins(DEECoPlugin[] plugins) throws PluginDependencyException {
}
}

private void createRuntime() {
Scheduler scheduler = new SingleThreadedScheduler();
private void createRuntime(Timer timer) throws NoExecutorAvailableException {
Executor executor = new SameThreadExecutor();
Scheduler scheduler = new SingleThreadedScheduler(executor, timer);
KnowledgeManagerContainer kmContainer = new KnowledgeManagerContainer(knowledgeManagerFactory, model);
scheduler.setExecutor(executor);
executor.setExecutionListener(scheduler);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,6 @@
*/
public interface RuntimeFramework extends DEECoPlugin {

/**
* Starts the execution of the runtime framework
*/
void start();

/**
* Stops the execution of the runtime framework
*/
void stop();

/**
* Invokes the runnable according to the execution policy of the runtime and
* waits for it to finish.
*
* @param r the runnable to invoke.
* @throws InterruptedException if the invocation was interrupted.
*/
void invokeAndWait(Runnable r) throws InterruptedException;

Scheduler getScheduler();
KnowledgeManagerContainer getContainer();
RatingsManager getRatingsManager();
Expand Down
Loading

0 comments on commit 66930ab

Please sign in to comment.