-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #85 from d3scomp/newgen-keznikl
API for the RuntimeFramework and its construction + tests
- Loading branch information
Showing
8 changed files
with
759 additions
and
0 deletions.
There are no files selected for viewing
66 changes: 66 additions & 0 deletions
66
jdeeco-core/src/cz/cuni/mff/d3s/deeco/runtime/ComponentInstanceRecord.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
|
||
|
||
|
||
} |
59 changes: 59 additions & 0 deletions
59
jdeeco-core/src/cz/cuni/mff/d3s/deeco/runtime/RuntimeConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
+ "]"; | ||
} | ||
|
||
|
||
|
||
|
||
|
||
|
||
} |
21 changes: 21 additions & 0 deletions
21
jdeeco-core/src/cz/cuni/mff/d3s/deeco/runtime/RuntimeFramework.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
|
||
} |
104 changes: 104 additions & 0 deletions
104
jdeeco-core/src/cz/cuni/mff/d3s/deeco/runtime/RuntimeFrameworkBuilder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
|
||
} |
Oops, something went wrong.