Skip to content

Commit

Permalink
Merge pull request #85 from d3scomp/newgen-keznikl
Browse files Browse the repository at this point in the history
API for the RuntimeFramework and its construction + tests
  • Loading branch information
rima-alali committed Nov 5, 2013
2 parents c7e6f7f + a8c763d commit bfce93d
Show file tree
Hide file tree
Showing 8 changed files with 759 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package cz.cuni.mff.d3s.deeco.runtime;

import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

import org.eclipse.emf.common.notify.Adapter;
import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.notify.impl.AdapterImpl;

import cz.cuni.mff.d3s.deeco.model.runtime.api.ComponentInstance;
import cz.cuni.mff.d3s.deeco.model.runtime.api.ComponentProcess;
import cz.cuni.mff.d3s.deeco.model.runtime.api.EnsembleController;
import cz.cuni.mff.d3s.deeco.task.Task;

/**
* Container holding {@link Task}s corresponding to a single {@link ComponentInstance}.
*
* @author Jaroslav Keznikl <keznikl@d3s.mff.cuni.cz>
*
*/
class ComponentInstanceRecord {
ComponentInstance componentInstance;

Map<ComponentProcess , Task> processTasks = new HashMap<>();
Map<EnsembleController, Task> ensembleTasks = new HashMap<>();


public ComponentInstanceRecord(ComponentInstance componentInstance) {
this.componentInstance = componentInstance;
}

public ComponentInstance getInstance() {
return componentInstance;
}

/**
* Returns tasks associated with the processes of the corresponding
* component instance.
*/
public Map<ComponentProcess , Task> getProcessTasks() {
return processTasks;
}


public Map<EnsembleController, Task> getEnsembleTasks() {
return ensembleTasks;
}


/**
* Returns all tasks associated with the corresponding component
* instance.
*/
public Collection<Task> getAllTasks() {
Set<Task> all = new HashSet<>();
all.addAll(processTasks.values());
all.addAll(ensembleTasks.values());
return all;
}



}
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package cz.cuni.mff.d3s.deeco.runtime;

import cz.cuni.mff.d3s.deeco.executor.Executor;
import cz.cuni.mff.d3s.deeco.executor.SingleThreadedExecutor;
import cz.cuni.mff.d3s.deeco.knowledge.KnowledgeManagerRegistry;
import cz.cuni.mff.d3s.deeco.logging.Log;
import cz.cuni.mff.d3s.deeco.scheduler.LocalTimeScheduler;
import cz.cuni.mff.d3s.deeco.scheduler.Scheduler;

/**
*
* @author Jaroslav Keznikl <keznikl@d3s.mff.cuni.cz>
*
*/
public class RuntimeConfiguration {
public enum Scheduling { WALL_TIME } // future: discrete
public enum Distribution { LOCAL } // future: BEE, IP
public enum Execution { SINGLE_THREADED } // future: multi-threaded, actor-based

Scheduling scheduling;
Distribution distribution;
Execution execution;


public RuntimeConfiguration(Scheduling scheduling,
Distribution distribution, Execution execution) {
this.scheduling = scheduling;
this.distribution = distribution;
this.execution = execution;

}

public Scheduling getScheduling() {
return scheduling;
}

public Distribution getDistribution() {
return distribution;
}

public Execution getExecution() {
return execution;
}



@Override
public String toString() {
return "RuntimeConfiguration [scheduling=" + scheduling
+ ", distribution=" + distribution + ", execution=" + execution
+ "]";
}






}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package cz.cuni.mff.d3s.deeco.runtime;

/**
* JDEECo runtime framework interface.
*
* @author Jaroslav Keznikl <keznikl@d3s.mff.cuni.cz>
*
*/
public interface RuntimeFramework {

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

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

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
package cz.cuni.mff.d3s.deeco.runtime;

import cz.cuni.mff.d3s.deeco.executor.Executor;
import cz.cuni.mff.d3s.deeco.executor.SingleThreadedExecutor;
import cz.cuni.mff.d3s.deeco.knowledge.KnowledgeManagerRegistry;
import cz.cuni.mff.d3s.deeco.logging.Log;
import cz.cuni.mff.d3s.deeco.model.runtime.api.RuntimeMetadata;
import cz.cuni.mff.d3s.deeco.scheduler.LocalTimeScheduler;
import cz.cuni.mff.d3s.deeco.scheduler.Scheduler;

/**
*
* @author Jaroslav Keznikl <keznikl@d3s.mff.cuni.cz>
*
*/
public class RuntimeFrameworkBuilder {


Scheduler scheduler;
Executor executor;
KnowledgeManagerRegistry kmRegistry;
RuntimeConfiguration configuration;
RuntimeFramework runtime;


public RuntimeFrameworkBuilder(RuntimeConfiguration configuration) {
if (configuration == null) {
throw new IllegalArgumentException("Configuration must not be null");
}

this.configuration = configuration;
}

protected void buildScheduler() {
if (configuration.scheduling == null) {
String msg = "No Executor available for " + configuration.toString();
Log.w(msg);
throw new UnsupportedOperationException(msg);
}

switch (configuration.scheduling) {
case WALL_TIME:
scheduler = new LocalTimeScheduler();
break;
default:
String msg = "No Scheduler available for " + configuration.toString();
Log.w(msg);
throw new UnsupportedOperationException(msg);
}
}

protected void buildExecutor() {
if (configuration.execution == null) {
String msg = "No Executor available for " + configuration.toString();
Log.w(msg);
throw new UnsupportedOperationException(msg);
}

switch (configuration.execution) {
case SINGLE_THREADED:
executor = new SingleThreadedExecutor();
break;
default:
String msg = "No Executor available for " + configuration.toString();
Log.w(msg);
throw new UnsupportedOperationException(msg);
}
}

protected void buildKnowledgeManagerRegistry() {
kmRegistry = new KnowledgeManagerRegistry();
}

protected void connect() {
// wire things together
scheduler.setExecutor(executor);
executor.setExecutionListener(scheduler);
}

protected void buildRuntime(RuntimeMetadata model) {
// FIXME if we add support for sharing scheduler/synchronizer among
// multiple runtimes (for simulation), we will probably override/extend
// this method
runtime = new RuntimeFrameworkImpl(model, scheduler, executor, kmRegistry);
}



public RuntimeFramework build(RuntimeMetadata model) {
if (model == null) {
throw new IllegalArgumentException("Model must not be null");
}

buildScheduler();
buildExecutor();
buildKnowledgeManagerRegistry();
//buildNetworkContainer() - by default does nothing = no network is used
//buildSynchronizer() - by default does nothing = only one runtime in only one JVM
connect();
buildRuntime(model);
return runtime;
}

}
Loading

0 comments on commit bfce93d

Please sign in to comment.