Skip to content

Commit

Permalink
Preparing for hierarchial activities
Browse files Browse the repository at this point in the history
  • Loading branch information
Ferdinando Villa committed Nov 12, 2024
1 parent 02f4e33 commit 27df0e6
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public class ActivityImpl extends ProvenanceNodeImpl implements Activity {
private Activity.Type type;
private String description;
private long id;
private String taskId;
private Activity parent;

@Override
Expand Down Expand Up @@ -94,4 +95,18 @@ public Activity getParent() {
public void setParent(Activity parent) {
this.parent = parent;
}

/**
* Non-API: the ID path through which the activity hierarchy can be reconstructed. When an activity is
* included in a message, the taskId gets in there.
*
* @return
*/
public String getTaskId() {
return taskId;
}

public void setTaskId(String taskId) {
this.taskId = taskId;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import org.integratedmodelling.klab.api.lang.kactors.beans.ActionStatistics;
import org.integratedmodelling.klab.api.lang.kactors.beans.TestStatistics;
import org.integratedmodelling.klab.api.lang.kim.KlabDocument;
import org.integratedmodelling.klab.api.provenance.impl.ActivityImpl;
import org.integratedmodelling.klab.api.services.KlabService;
import org.integratedmodelling.klab.api.services.Reasoner;
import org.integratedmodelling.klab.api.services.resources.ResourceSet;
Expand Down Expand Up @@ -429,9 +430,7 @@ public static Message create(String identity, Object... o) {
ret.setMessageType((MessageType) ob);
} else if (ob instanceof MessageClass) {
ret.setMessageClass((MessageClass) ob);
} /*else if (ob instanceof Notification.Type) {
notype = (Notification.Type) ob;
} */ else if (ob instanceof Queue q) {
} else if (ob instanceof Queue q) {
queueOverridden = true;
ret.setQueue(q);
} /*else if (ob instanceof ForwardingPolicy) {
Expand All @@ -445,6 +444,8 @@ public static Message create(String identity, Object... o) {
case Error, SystemError -> MessageType.Error;
});
ret.setPayload(ob);
} else if (ob instanceof ActivityImpl activity) {
ret.setTaskId(activity.getTaskId());
} else if (ob != null) {
if (ret.getPayload() == null) {
ret.setPayload(ob);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ public class ServiceContextScope extends ServiceSessionScope implements ContextS
private Observation contextObservation;
private URL url;
private DigitalTwin digitalTwin;
private ActivityImpl activity;
// FIXME there's also parentScope (generic) and I'm not sure these should be duplicated
protected ServiceContextScope parent;
protected Map<ResolutionConstraint.Type, ResolutionConstraint> resolutionConstraints =
Expand All @@ -72,7 +71,6 @@ private ServiceContextScope(ServiceContextScope parent) {
this.digitalTwin = parent.digitalTwin;
this.observationCache = parent.observationCache;
this.resolutionConstraints.putAll(parent.resolutionConstraints);
this.activity = parent.activity;
}

@Override
Expand Down Expand Up @@ -346,23 +344,6 @@ public <T> List<T> getConstraints(ResolutionConstraint.Type type, Class<T> resul
return constraint.payload(resultClass);
}

/**
* Non-API: scopes carry the provenance activity they're representing during contextualization. When the
* activity is added, any previously set activity becomes the parent activity.
*
* @param activity
* @return
*/
public ServiceContextScope withActivity(Activity activity) {
ServiceContextScope ret = new ServiceContextScope(this);
if (activity instanceof ActivityImpl activityImpl) {
ret.activity = activityImpl;
ret.activity.setParent(activity);
return ret;
}
throw new KlabIllegalStateException("Using unexpected Activity implementation");
}

@Override
public boolean initializeAgents(String scopeId) {
// setting the ID here is dirty as technically this is still being set and will be set again later,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,6 @@ public boolean run() {
return true;
}


/**
* One operation per observation. Successful execution will update the observation in the DT.
*/
Expand Down

0 comments on commit 27df0e6

Please sign in to comment.