-
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.
discrete scheduler's triggering limitations fixed
Three new wrapper classes are introduced into 'invokable' package to monitor the updated knowledge paths of a schedulable process. This is to overcome the limitation that duck typing: without listeners we needed a way to know which exact knowledge fields are updated (and if) when an ensemble is executed.
- Loading branch information
Showing
12 changed files
with
389 additions
and
113 deletions.
There are no files selected for viewing
56 changes: 56 additions & 0 deletions
56
jdeeco-core/src/cz/cuni/mff/d3s/deeco/invokable/SchedulableComponentProcessWrapper.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,56 @@ | ||
package cz.cuni.mff.d3s.deeco.invokable; | ||
|
||
import java.util.ArrayList; | ||
|
||
import cz.cuni.mff.d3s.deeco.knowledge.ISession; | ||
|
||
/** | ||
* To be used instead of the | ||
* {@link cz.cuni.mff.d3s.deeco.invokable.SchedulableComponentProcess | ||
* SchedulableComponentProcess} when keeping track of the knowledge fields in | ||
* the end of every execution is needed (e.g. in case of the | ||
* {@link cz.cuni.mff.d3s.deeco.scheduling.discrete.DiscreteScheduler | ||
* DiscreteScheduler}). | ||
* | ||
* @author Ilias Gerostathopoulos | ||
* | ||
*/ | ||
public class SchedulableComponentProcessWrapper extends | ||
SchedulableProcessWrapper { | ||
|
||
private final SchedulableComponentProcess scp; | ||
|
||
public SchedulableComponentProcessWrapper(SchedulableProcess sp) { | ||
super(sp); | ||
this.scp = (SchedulableComponentProcess) sp; | ||
} | ||
|
||
public void invoke() { | ||
scp.invoke(null, null); | ||
findChangedKnowledgePaths(); | ||
} | ||
|
||
public void findChangedKnowledgePaths() { | ||
changedKnowledgePaths = new ArrayList<String>(); | ||
for (Parameter par : scp.process.inOut) { | ||
changedKnowledgePaths.add(getKnowledgePath(scp, par)); | ||
} | ||
for (Parameter par : scp.process.out) { | ||
changedKnowledgePaths.add(getKnowledgePath(scp, par)); | ||
} | ||
} | ||
|
||
public String getKnowledgePath(SchedulableComponentProcess scp, | ||
Parameter par) { | ||
String path = null; | ||
String coord = null; | ||
String member = null; | ||
ISession session = scp.km.createSession(); | ||
session.begin(); | ||
while (session.repeat()) { | ||
path = par.kPath.getEvaluatedPath(scp.km, coord, member, session); | ||
session.end(); | ||
} | ||
return path; | ||
} | ||
} |
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
117 changes: 117 additions & 0 deletions
117
jdeeco-core/src/cz/cuni/mff/d3s/deeco/invokable/SchedulableEnsembleProcessWrapper.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,117 @@ | ||
package cz.cuni.mff.d3s.deeco.invokable; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import cz.cuni.mff.d3s.deeco.exceptions.KMException; | ||
import cz.cuni.mff.d3s.deeco.exceptions.KMNotExistentException; | ||
import cz.cuni.mff.d3s.deeco.knowledge.ConstantKeys; | ||
import cz.cuni.mff.d3s.deeco.knowledge.ISession; | ||
import cz.cuni.mff.d3s.deeco.scheduling.ETriggerType; | ||
|
||
/** | ||
* To be used instead of the | ||
* {@link cz.cuni.mff.d3s.deeco.invokable.SchedulableEnsembleProcess | ||
* SchedulableEnsembleProcess} when keeping track of the knowledge fields in the | ||
* end of every execution is needed (e.g. in case of the | ||
* {@link cz.cuni.mff.d3s.deeco.scheduling.discrete.DiscreteScheduler | ||
* DiscreteScheduler}). | ||
* | ||
* @author Ilias Gerostathopoulos | ||
* | ||
*/ | ||
public class SchedulableEnsembleProcessWrapper extends | ||
SchedulableProcessWrapper { | ||
|
||
private final SchedulableEnsembleProcess sep; | ||
|
||
public SchedulableEnsembleProcessWrapper(SchedulableProcess sp) { | ||
super(sp); | ||
this.sep = (SchedulableEnsembleProcess) sp; | ||
} | ||
|
||
public void invoke() { | ||
changedKnowledgePaths = new ArrayList<String>(); | ||
SchedulableProcess.runtime.set(sep.km.getRuntime()); | ||
Object[] rootIds = null; | ||
try { | ||
rootIds = (Object[]) sep.km | ||
.getKnowledge(ConstantKeys.ROOT_KNOWLEDGE_ID); | ||
for (Object oid : rootIds) { | ||
changedKnowledgePaths | ||
.addAll(singleInvocationWithOutputMonitoring( | ||
(String) oid, ETriggerType.COORDINATOR, rootIds)); | ||
} | ||
} catch (KMException e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
|
||
private List<String> singleInvocationWithOutputMonitoring(String outerId, | ||
ETriggerType recipientMode, Object[] rootIds) throws KMException { | ||
List<String> changedPaths = new ArrayList<String>(); | ||
ISession session = null; | ||
try { | ||
String cId = null, mId = null; | ||
if (recipientMode.equals(ETriggerType.COORDINATOR)) { | ||
cId = outerId; | ||
} else { | ||
mId = outerId; | ||
} | ||
mloop: for (Object iid : rootIds) { | ||
if (recipientMode.equals(ETriggerType.COORDINATOR)) { | ||
mId = (String) iid; | ||
} else { | ||
cId = (String) iid; | ||
} | ||
session = sep.km.createSession(); | ||
session.begin(); | ||
while (session.repeat()) { | ||
try { | ||
Object[] parametersMembership = sep | ||
.getParameterMethodValues( | ||
sep.membership.getIn(), | ||
sep.membership.getInOut(), | ||
sep.membership.getOut(), session, | ||
(String) cId, (String) mId); | ||
if (sep.evaluateMembership(parametersMembership)) { | ||
Object[] parametersKnowledgeExchange = sep | ||
.getParameterMethodValues( | ||
sep.knowledgeExchange.in, | ||
sep.knowledgeExchange.inOut, | ||
sep.knowledgeExchange.out, session, | ||
(String) cId, (String) mId); | ||
for (Parameter p : sep.knowledgeExchange.inOut) { | ||
String changedPath = p.kPath.getEvaluatedPath( | ||
sep.km, cId, mId, session); | ||
if (!changedPaths.contains(changedPath)) | ||
changedPaths.add(changedPath); | ||
} | ||
for (Parameter p : sep.knowledgeExchange.out) { | ||
String changedPath = p.kPath.getEvaluatedPath( | ||
sep.km, cId, mId, session); | ||
if (!changedPaths.contains(changedPath)) | ||
changedPaths.add(changedPath); | ||
} | ||
sep.evaluateKnowledgeExchange(parametersKnowledgeExchange); | ||
sep.putParameterMethodValues( | ||
parametersKnowledgeExchange, | ||
sep.knowledgeExchange.inOut, | ||
sep.knowledgeExchange.out, session, | ||
(String) cId, (String) mId); | ||
} | ||
} catch (KMNotExistentException kmnee) { | ||
session.cancel(); | ||
continue mloop; | ||
} | ||
session.end(); | ||
} | ||
} | ||
} catch (KMException kme) { | ||
if (session != null) | ||
session.cancel(); | ||
throw kme; | ||
} | ||
return changedPaths; | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
jdeeco-core/src/cz/cuni/mff/d3s/deeco/invokable/SchedulableProcessWrapper.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,42 @@ | ||
package cz.cuni.mff.d3s.deeco.invokable; | ||
|
||
import java.util.List; | ||
|
||
/** | ||
* Base class for wrapping a | ||
* {@link cz.cuni.mff.d3s.deeco.invokable.SchedulableProcess SchedulableProcess} | ||
* with the sole purpose of keeping track of the the knowledge paths that get | ||
* updated. To be used by the | ||
* {@link cz.cuni.mff.d3s.deeco.scheduling.discrete.DiscreteScheduler | ||
* DiscreteScheduler} in order to implement its triggering mechanism. | ||
* | ||
* @author Ilias Gerostathopoulos | ||
* | ||
*/ | ||
public abstract class SchedulableProcessWrapper { | ||
|
||
// wrapped process: | ||
private final SchedulableProcess sp; | ||
// structure to keep the updated knowledge paths on each execution: | ||
protected List<String> changedKnowledgePaths; | ||
|
||
public SchedulableProcessWrapper(SchedulableProcess sp) { | ||
this.sp = sp; | ||
} | ||
|
||
public abstract void invoke(); | ||
|
||
/** | ||
* Retrieves a list of the knowledge paths that were updated during last | ||
* execution | ||
* | ||
* @return list of strings | ||
*/ | ||
public List<String> getChangedKnowledgePaths() { | ||
return changedKnowledgePaths; | ||
} | ||
|
||
public SchedulableProcess getProcess() { | ||
return sp; | ||
} | ||
} |
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 |
---|---|---|
@@ -1,7 +1,5 @@ | ||
package cz.cuni.mff.d3s.deeco.logging; | ||
|
||
import java.io.Serializable; | ||
|
||
/** | ||
* API for sending log output. | ||
* | ||
|
Oops, something went wrong.