From 50d1d5002091f082ec7f6a70abd249b0c6519068 Mon Sep 17 00:00:00 2001 From: Simon Spinner <simon.spinner@uni-wuerzburg.de> Date: Thu, 31 Mar 2016 14:53:01 +0200 Subject: [PATCH] Move public resource handling to GenericAgent. --- .../prisma/agent/generic/GenericAgent.java | 37 ------------------ .../prisma/core/agent/AgentController.java | 38 +++++++++++++++++++ 2 files changed, 38 insertions(+), 37 deletions(-) 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 7254464..36ea416 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,10 +14,8 @@ 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; @@ -27,9 +25,6 @@ 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; @@ -143,8 +138,6 @@ public class GenericAgent implements IApplication { agent.start().get(); - replacePublicResources(agent, configuration.getSkeleton()); - if (resolveRequiredObjects(agent, configuration)) { agent.apply(configuration.getSkeleton()); } @@ -178,36 +171,6 @@ public class GenericAgent implements IApplication { } - private void replacePublicResources(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); - // 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.getModelRepository().adapt(curType, - ModelSkeletonAdapter.class); - adapter.setRepositoryObject(curPublicOne); - break; - } - } - } - } - } - } - } - private boolean resolveRequiredObjects(GenericAgentController agent, GenericAgentConfiguration configuration) { Set<RequiredObject> notResolved = new HashSet<>(configuration.getRequiredObjects()); for (EObject curDelegate : agent.getDelegatedObjects()) { 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 8fa6727..d6a81f0 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,8 +13,13 @@ 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; @@ -143,6 +148,9 @@ public class AgentController { public void apply(ModelSkeleton skeleton) { try (Transaction transaction = getModelRepository().createTransaction()) { + + replacePublicResources(skeleton); + scope.synchronizeModelSkeleton(transaction, skeleton); boolean success = true; @@ -227,4 +235,34 @@ public class AgentController { throw new IllegalStateException("The agent is not running."); } } + + 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); + // 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 = getModelRepository().adapt(curType, + ModelSkeletonAdapter.class); + adapter.setRepositoryObject(curPublicOne); + break; + } + } + } + } + } + } + } } -- GitLab