diff --git a/tools.descartes.prisma.agent.generic/src/tools/descartes/prisma/agent/generic/GenericAgent.java b/tools.descartes.prisma.agent.generic/src/tools/descartes/prisma/agent/generic/GenericAgent.java index f7a147f5b112bfd679a123b3f9f13c9f2509b574..429e77fddc483eb6149baa8e8f6c10237beccffc 100644 --- a/tools.descartes.prisma.agent.generic/src/tools/descartes/prisma/agent/generic/GenericAgent.java +++ b/tools.descartes.prisma.agent.generic/src/tools/descartes/prisma/agent/generic/GenericAgent.java @@ -14,8 +14,10 @@ import org.apache.commons.cli.GnuParser; import org.apache.commons.cli.HelpFormatter; import org.apache.commons.cli.Options; import org.eclipse.emf.cdo.CDOObject; +import org.eclipse.emf.common.util.TreeIterator; import org.eclipse.emf.common.util.URI; import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.ecore.EReference; import org.eclipse.emf.ecore.EStructuralFeature.Setting; import org.eclipse.emf.ecore.resource.Resource; import org.eclipse.emf.ecore.resource.ResourceSet; @@ -25,6 +27,9 @@ import org.eclipse.equinox.app.IApplication; import org.eclipse.equinox.app.IApplicationContext; import edu.kit.ipd.descartes.identifier.Identifier; +import edu.kit.ipd.descartes.mm.resourcetype.ResourceType; +import edu.kit.ipd.descartes.mm.resourcetype.ResourceTypeRepository; +import edu.kit.ipd.descartes.mm.resourcetype.ResourcetypePackage; import tools.descartes.prisma.agent.generic.genericagent.GenericAgentConfiguration; import tools.descartes.prisma.agent.generic.genericagent.RequiredObject; import tools.descartes.prisma.core.ModelRepository; @@ -40,8 +45,6 @@ public class GenericAgent implements IApplication { private class GenericAgentController extends AgentController { - private ModelSkeleton skeleton; - private final Set<EObject> delegatedObjects = new HashSet<>(); public GenericAgentController(ModelRepository repository, GenericAgentConfiguration configuration) { @@ -138,6 +141,8 @@ public class GenericAgent implements IApplication { agent.start().get(); + resolvePublicResources(agent, configuration.getSkeleton()); + if (resolveRequiredObjects(agent, configuration)) { agent.apply(configuration.getSkeleton()); } @@ -170,6 +175,37 @@ public class GenericAgent implements IApplication { return configuration; } + private void resolvePublicResources(GenericAgentController agent, ModelSkeleton skeleton) { + // Resource types (e.g., CPU, HDD, DELAY) which are defined globally are + // not included in the model skeleton. + // We need to find these references in the model skeleton and connect + // them with the instances in the repository. + TreeIterator<EObject> iterator = skeleton.eAllContents(); + ResourceTypeRepository publicResourceTypes = agent.getContainerScope().getSystemScope().getResourceTypes(); + while (iterator.hasNext()) { + EObject curObject = iterator.next(); + for (EReference curReference : curObject.eClass().getEAllReferences()) { + if (!curReference.isContainment() && !curReference.isContainer()) { + if (ResourcetypePackage.Literals.RESOURCE_TYPE.isSuperTypeOf(curReference.getEReferenceType())) { + ResourceType curType = (ResourceType) curObject.eGet(curReference); + if (curType != null) { + // find matching resources in system global scope + // (matching is based on name and class + for (ResourceType curPublicOne : publicResourceTypes.getResourceTypes()) { + if (curType.eClass().isInstance(curPublicOne) + && curType.getName().equals(curPublicOne.getName())) { + ModelSkeletonAdapter adapter = agent.adapt(curType, ModelSkeletonAdapter.class); + adapter.setRepositoryObject(curPublicOne); + break; + } + } + } + } + } + } + } + } + private boolean resolveRequiredObjects(GenericAgentController agent, GenericAgentConfiguration configuration) { Set<RequiredObject> notResolved = new HashSet<>(configuration.getRequiredObjects()); diff --git a/tools.descartes.prisma.core/src/tools/descartes/prisma/core/agent/AgentController.java b/tools.descartes.prisma.core/src/tools/descartes/prisma/core/agent/AgentController.java index d059c3a649348b4012749b3d49355f6f4e57476a..ec9582c2b6f360b9cf8e75e646a46c1e5bf559ff 100644 --- a/tools.descartes.prisma.core/src/tools/descartes/prisma/core/agent/AgentController.java +++ b/tools.descartes.prisma.core/src/tools/descartes/prisma/core/agent/AgentController.java @@ -13,13 +13,8 @@ import java.util.concurrent.TimeUnit; import org.eclipse.emf.cdo.CDOAdapter; import org.eclipse.emf.common.notify.Notification; import org.eclipse.emf.common.notify.Notifier; -import org.eclipse.emf.common.util.TreeIterator; import org.eclipse.emf.ecore.EObject; -import org.eclipse.emf.ecore.EReference; -import edu.kit.ipd.descartes.mm.resourcetype.ResourceType; -import edu.kit.ipd.descartes.mm.resourcetype.ResourceTypeRepository; -import edu.kit.ipd.descartes.mm.resourcetype.ResourcetypePackage; import tools.descartes.prisma.core.ModelRepository; import tools.descartes.prisma.core.Transaction; import tools.descartes.prisma.core.adapter.ModelSkeletonAdapter; @@ -168,8 +163,6 @@ public class AgentController { try (Transaction transaction = getModelRepository().createTransaction()) { - replacePublicResources(skeleton); - scope.synchronizeModelSkeleton(this, transaction, skeleton); boolean success = true; @@ -274,36 +267,4 @@ public class AgentController { public <T> T adapt(EObject obj, Class<T> adapterClass) { return (T) adapterFactory.adapt(obj, adapterClass); } - - private void replacePublicResources(ModelSkeleton skeleton) { - // Resource types (e.g., CPU, HDD, DELAY) which are defined globally are - // not included in the model skeleton. - // We need to find these references in the model skeleton and connect - // them with the instances in the repository. - TreeIterator<EObject> iterator = skeleton.eAllContents(); - ResourceTypeRepository publicResourceTypes = scope.getSystemScope().getResourceTypes(); - while (iterator.hasNext()) { - EObject curObject = iterator.next(); - for (EReference curReference : curObject.eClass().getEAllReferences()) { - if (!curReference.isContainment() && !curReference.isContainer()) { - if (ResourcetypePackage.Literals.RESOURCE_TYPE.isSuperTypeOf(curReference.getEReferenceType())) { - ResourceType curType = (ResourceType) curObject.eGet(curReference); - if (curType != null) { - // find matching resources in system global scope - // (matching is based on name and class - for (ResourceType curPublicOne : publicResourceTypes.getResourceTypes()) { - if (curType.eClass().isInstance(curPublicOne) - && curType.getName().equals(curPublicOne.getName())) { - ModelSkeletonAdapter adapter = adapt(curType, - ModelSkeletonAdapter.class); - adapter.setRepositoryObject(curPublicOne); - break; - } - } - } - } - } - } - } - } }