-
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.
Dynamic adding components and ensembles
Runtime can add components and ensembles without stopping the execution
- Loading branch information
Michał Kit
committed
Feb 7, 2013
1 parent
b76cb81
commit 0de8639
Showing
12 changed files
with
188 additions
and
77 deletions.
There are no files selected for viewing
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
88 changes: 88 additions & 0 deletions
88
jdeeco-core/src/cz/cuni/mff/d3s/deeco/invokable/SchedulableProcessTrigger.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,88 @@ | ||
package cz.cuni.mff.d3s.deeco.invokable; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import cz.cuni.mff.d3s.deeco.knowledge.ISession; | ||
import cz.cuni.mff.d3s.deeco.knowledge.KnowledgeManager; | ||
import cz.cuni.mff.d3s.deeco.path.grammar.EEnsembleParty; | ||
import cz.cuni.mff.d3s.deeco.scheduling.ETriggerType; | ||
import cz.cuni.mff.d3s.deeco.scheduling.IKnowledgeChangeListener; | ||
import cz.cuni.mff.d3s.deeco.scheduling.ProcessTriggeredSchedule; | ||
|
||
public class SchedulableProcessTrigger implements IKnowledgeChangeListener { | ||
|
||
public final SchedulableProcess sp; | ||
|
||
public SchedulableProcessTrigger(SchedulableProcess sp) { | ||
this.sp = sp; | ||
} | ||
|
||
@Override | ||
public void knowledgeChanged(final String triggerer, | ||
final ETriggerType recMode) { | ||
Thread t = new Thread(new Runnable() { | ||
|
||
@Override | ||
public void run() { | ||
if (sp.contextClassLoader != null) | ||
Thread.currentThread().setContextClassLoader( | ||
sp.contextClassLoader); | ||
sp.invoke(triggerer, recMode); | ||
} | ||
}); | ||
t.run(); | ||
} | ||
|
||
public boolean equals(Object o) { | ||
return o != null && o instanceof SchedulableProcessTrigger | ||
&& this.sp.equals(((SchedulableProcessTrigger) o).sp); | ||
} | ||
|
||
@Override | ||
public List<String> getKnowledgePaths() { | ||
if (isEnsembleTriggered()) { | ||
return getEvaluatedKnowledgePaths( | ||
EEnsembleParty.COORDINATOR.toString(), | ||
EEnsembleParty.MEMBER.toString()); | ||
} else { | ||
return getEvaluatedKnowledgePaths(); | ||
} | ||
} | ||
|
||
public KnowledgeManager getKnowledgeManager() { | ||
return sp.km; | ||
} | ||
|
||
public void registerListener() { | ||
getKnowledgeManager().registerListener(this); | ||
} | ||
|
||
public void unregisterListener() { | ||
getKnowledgeManager().unregisterListener(this); | ||
} | ||
|
||
private List<String> getEvaluatedKnowledgePaths() { | ||
return getEvaluatedKnowledgePaths(null, null); | ||
} | ||
|
||
private List<String> getEvaluatedKnowledgePaths(String coord, String member) { | ||
List<Parameter> triggeredParams = ((ProcessTriggeredSchedule) sp.scheduling).parameters; | ||
List<String> result = new ArrayList<String>(); | ||
ISession session; | ||
for (Parameter p : triggeredParams) { | ||
session = sp.km.createSession(); | ||
session.begin(); | ||
while (session.repeat()) { | ||
result.add(p.kPath.getEvaluatedPath(sp.km, coord, member, | ||
session)); | ||
session.end(); | ||
} | ||
} | ||
return result; | ||
} | ||
|
||
private boolean isEnsembleTriggered() { | ||
return sp instanceof SchedulableEnsembleProcess; | ||
} | ||
} |
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
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
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
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
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
Oops, something went wrong.