| 1 | package de.uka.ipd.sdq.pcm.transformations.builder.resourceconsumer; |
| 2 | |
| 3 | import org.apache.log4j.Logger; |
| 4 | |
| 5 | import de.uka.ipd.sdq.pcm.repository.OperationInterface; |
| 6 | import de.uka.ipd.sdq.pcm.resourceenvironment.LinkingResource; |
| 7 | import de.uka.ipd.sdq.pcm.resourceenvironment.ResourceContainer; |
| 8 | import de.uka.ipd.sdq.pcm.resourceenvironment.ResourceenvironmentFactory; |
| 9 | import de.uka.ipd.sdq.pcm.resourcetype.CommunicationLinkResourceType; |
| 10 | import de.uka.ipd.sdq.pcm.transformations.builder.abstractbuilder.BasicComponentBuilder; |
| 11 | import de.uka.ipd.sdq.pcm.transformations.builder.seff.DelegatorComponentSeffBuilder; |
| 12 | import de.uka.ipd.sdq.pcm.transformations.builder.seff.StaticInternalActionDescriptor; |
| 13 | import de.uka.ipd.sdq.pcm.transformations.builder.util.PCMAndCompletionModelHolder; |
| 14 | |
| 15 | /** |
| 16 | * Generates a BasicComponent which determines and loads the underlying network resource with the message's size of the message to transmit. |
| 17 | * Respects both requesting service and returning from service. |
| 18 | * Assumes that the message size is contained in the variable stream.BYTESIZE. |
| 19 | * |
| 20 | * @author Steffen |
| 21 | * |
| 22 | */ |
| 23 | public class NetworkLoadingComponentBuilder extends BasicComponentBuilder { |
| 24 | |
| 25 | private Logger logger = Logger.getLogger(NetworkLoadingComponentBuilder.class); |
| 26 | private CommunicationLinkResourceType typeOfLink; |
| 27 | |
| 28 | /** |
| 29 | * Constructor of the network load simulator component |
| 30 | * @param models Container for the PCM model instance to modify |
| 31 | * @param interf Interface of the component, used to delgate the method calls to its target |
| 32 | * @param linkingRes The linking resource on which the load is created |
| 33 | */ |
| 34 | public NetworkLoadingComponentBuilder( |
| 35 | PCMAndCompletionModelHolder models, |
| 36 | OperationInterface interf, |
| 37 | LinkingResource linkingRes) { |
| 38 | super(models, interf, null, "NetworkLoadingComponent"); |
| 39 | |
| 40 | typeOfLink = linkingRes.getCommunicationLinkResourceSpecifications_LinkingResource().getCommunicationLinkResourceType_CommunicationLinkResourceSpecification(); |
| 41 | ResourceContainer dummyContainer = ResourceenvironmentFactory.eINSTANCE.createResourceContainer(); |
| 42 | dummyContainer.setId(linkingRes.getId()); |
| 43 | |
| 44 | this.container = dummyContainer; |
| 45 | } |
| 46 | |
| 47 | /** |
| 48 | * Returns a SEFF builder which adds a network demand depending on the parameters passed |
| 49 | */ |
| 50 | @Override |
| 51 | protected DelegatorComponentSeffBuilder getSeffBuilder() { |
| 52 | DelegatorComponentSeffBuilder builder = new DelegatorComponentSeffBuilder(getOperationProvidedRole(),getOperationRequiredRole()); |
| 53 | |
| 54 | // Network demand for the Request |
| 55 | builder.appendPreAction(new StaticInternalActionDescriptor("stream.BYTESIZE", typeOfLink)); |
| 56 | |
| 57 | // Network demand for the Reply |
| 58 | builder.appendPostAction(new StaticInternalActionDescriptor("stream.BYTESIZE", typeOfLink)); |
| 59 | return builder; |
| 60 | } |
| 61 | |
| 62 | @Override |
| 63 | public void build() { |
| 64 | logger.info("Creating a component to simulate network loads"); |
| 65 | super.build(); |
| 66 | } |
| 67 | } |