Search in sources :

Example 11 with AssemblyContext

use of org.palladiosimulator.pcm.core.composition.AssemblyContext in project iobserve-analysis by research-iobserve.

the class SystemGeneration method getAndRemoveRandomAC.

/*
     * This method returns a random AssemblyContext in the given container, but never the given
     * forbidden object ref! It returns null if this is not possible!
     */
private AssemblyContext getAndRemoveRandomAC(final List<AssemblyContext> container, final Object forbiddenRef) {
    AssemblyContext ac = null;
    for (int i = 0; ac == null && i < container.size() * 10; i++) {
        final int randIndex = ThreadLocalRandom.current().nextInt(container.size());
        final AssemblyContext randomAC = container.get(randIndex);
        if (randomAC != forbiddenRef) {
            container.remove(randIndex);
            ac = randomAC;
        }
    }
    // AssemblyContext in the container!");
    return ac;
}
Also used : AssemblyContext(org.palladiosimulator.pcm.core.composition.AssemblyContext)

Example 12 with AssemblyContext

use of org.palladiosimulator.pcm.core.composition.AssemblyContext in project iobserve-analysis by research-iobserve.

the class SystemGeneration method finalizeModelGeneration.

/*
     * Connects open required interfaces to existing providing interfaces
     */
private void finalizeModelGeneration() {
    final Set<String> interfaceIDs = this.openRequiredInterfaces.keySet();
    // Iterate over all not connected required interfaces
    for (final String interfaceID : interfaceIDs) {
        if (this.openRequiredInterfaces.get(interfaceID).size() == 0) {
            continue;
        }
        final List<AssemblyContext> openReqACs = this.openRequiredInterfaces.get(interfaceID);
        for (final AssemblyContext requAC : openReqACs) {
            AssemblyContext provAC = null;
            if (this.openProvidedInterfaces.get(interfaceID).size() > 0) {
                // First search the not connected providing interfaces
                provAC = this.getAndRemoveRandomAC(this.openProvidedInterfaces.get(interfaceID), requAC);
            }
            if (provAC == null && this.connectedProvidedInterfaces.get(interfaceID).size() > 0) {
                // Second search the connected providing interfaces
                provAC = this.getAndRemoveRandomAC(this.connectedProvidedInterfaces.get(interfaceID), requAC);
            }
            if (provAC != null) {
                // Create assembly connector and add to connected providing
                // interfaces
                this.createAssemblyConnector(requAC, provAC, interfaceID);
                this.connectedProvidedInterfaces.get(interfaceID).add(provAC);
            } else {
                throw new RuntimeException("A required interface has no matching provided interface!");
            }
        }
    }
    final int unconnectedAssemblyContextCount = this.unconnectedAssemblyContextes.size();
    SystemGeneration.LOGGER.info("There are \t{}\t unconnected AssemblyContexts, deleting and retrying!", unconnectedAssemblyContextCount);
    if (unconnectedAssemblyContextCount > 0) {
        for (final AssemblyContext ac : this.unconnectedAssemblyContextes) {
            this.removeAssemblyContext(ac);
        }
        this.unconnectedAssemblyContextes.clear();
        this.addAssemblyContexts(unconnectedAssemblyContextCount, "");
    }
}
Also used : AssemblyContext(org.palladiosimulator.pcm.core.composition.AssemblyContext)

Example 13 with AssemblyContext

use of org.palladiosimulator.pcm.core.composition.AssemblyContext in project iobserve-analysis by research-iobserve.

the class SystemGeneration method connectProvidedInterfaces.

/*
     * This method tires to connect all providing interfaces to non connected required interfaces!
     *
     * If this is not possible, it will be added to non connected providing interfaces for later
     * connecting!
     */
private int connectProvidedInterfaces(final AssemblyContext newAC, final EList<ProvidedRole> provRoles) {
    int connectionsCreated = 0;
    for (final ProvidedRole provRole : provRoles) {
        // Connect all providing interfaces!
        if (!(provRole instanceof OperationProvidedRole)) {
            continue;
        }
        boolean connected = false;
        final OperationProvidedRole provInterface = (OperationProvidedRole) provRole;
        final String interfaceID = provInterface.getProvidedInterface__OperationProvidedRole().getId();
        if (this.openRequiredInterfaces.get(interfaceID).size() > 0) {
            // Currently not connected, but required interfaces
            final List<AssemblyContext> openRequiredAC = this.openRequiredInterfaces.get(interfaceID);
            final AssemblyContext requiringAC = this.getAndRemoveRandomAC(openRequiredAC, newAC);
            if (requiringAC != null) {
                this.createAssemblyConnector(requiringAC, newAC, interfaceID);
                connectionsCreated++;
                connected = true;
            }
        }
        if (connected) {
            // Matching required interface found!
            this.connectedProvidedInterfaces.get(interfaceID).add(newAC);
        } else {
            // No matching required interface yet!
            this.openProvidedInterfaces.get(interfaceID).add(newAC);
        }
    }
    return connectionsCreated;
}
Also used : OperationProvidedRole(org.palladiosimulator.pcm.repository.OperationProvidedRole) ProvidedRole(org.palladiosimulator.pcm.repository.ProvidedRole) OperationProvidedRole(org.palladiosimulator.pcm.repository.OperationProvidedRole) AssemblyContext(org.palladiosimulator.pcm.core.composition.AssemblyContext)

Example 14 with AssemblyContext

use of org.palladiosimulator.pcm.core.composition.AssemblyContext in project iobserve-analysis by research-iobserve.

the class SystemGeneration method connectRequiredInterfaces.

/*
     * This method tries to connect all required interfaces to the open provided interfaces.
     *
     * If this is not possible the interface will be added to the open required interfaces for later
     * connecting.
     */
private int connectRequiredInterfaces(final AssemblyContext newAC, final EList<RequiredRole> requRoles) {
    int connectionsCreated = 0;
    for (final RequiredRole requRole : requRoles) {
        // Connect all providing interfaces!
        if (!(requRole instanceof OperationRequiredRole)) {
            continue;
        }
        boolean connected = false;
        final OperationRequiredRole reqInterface = (OperationRequiredRole) requRole;
        final String interfaceID = reqInterface.getRequiredInterface__OperationRequiredRole().getId();
        if (this.openProvidedInterfaces.get(interfaceID).size() > 0) {
            // Open provided interface is available
            final List<AssemblyContext> openProvidingAC = this.openProvidedInterfaces.get(interfaceID);
            final AssemblyContext providingAC = this.getAndRemoveRandomAC(openProvidingAC, newAC);
            if (providingAC != null) {
                this.createAssemblyConnector(newAC, providingAC, interfaceID);
                this.connectedProvidedInterfaces.get(interfaceID).add(providingAC);
                connectionsCreated++;
                connected = true;
            }
        }
        if (!connected) {
            // Add to open, but required interfaces to connect later!
            final List<AssemblyContext> acs = this.openRequiredInterfaces.get(interfaceID);
            acs.add(newAC);
        }
    }
    return connectionsCreated;
}
Also used : RequiredRole(org.palladiosimulator.pcm.repository.RequiredRole) OperationRequiredRole(org.palladiosimulator.pcm.repository.OperationRequiredRole) AssemblyContext(org.palladiosimulator.pcm.core.composition.AssemblyContext) OperationRequiredRole(org.palladiosimulator.pcm.repository.OperationRequiredRole)

Example 15 with AssemblyContext

use of org.palladiosimulator.pcm.core.composition.AssemblyContext in project iobserve-analysis by research-iobserve.

the class SystemGeneration method initInterfaceMaps.

private void initInterfaceMaps() {
    this.openRequiredInterfaces = new HashMap<>();
    this.openProvidedInterfaces = new HashMap<>();
    this.connectedProvidedInterfaces = new HashMap<>();
    this.unconnectedAssemblyContextes = new HashSet<>();
    for (final RepositoryComponent component : this.components) {
        for (final ProvidedRole provRole : component.getProvidedRoles_InterfaceProvidingEntity()) {
            if (!(provRole instanceof OperationProvidedRole)) {
                continue;
            }
            final OperationProvidedRole provInterface = (OperationProvidedRole) provRole;
            final String interfaceID = provInterface.getProvidedInterface__OperationProvidedRole().getId();
            if (!this.openProvidedInterfaces.containsKey(interfaceID)) {
                this.openProvidedInterfaces.put(interfaceID, new LinkedList<AssemblyContext>());
                this.openRequiredInterfaces.put(interfaceID, new LinkedList<AssemblyContext>());
                this.connectedProvidedInterfaces.put(interfaceID, new LinkedList<AssemblyContext>());
            }
        }
        for (final RequiredRole requRole : component.getRequiredRoles_InterfaceRequiringEntity()) {
            if (!(requRole instanceof OperationRequiredRole)) {
                continue;
            }
            final OperationRequiredRole reqInterface = (OperationRequiredRole) requRole;
            final String interfaceID = reqInterface.getRequiredInterface__OperationRequiredRole().getId();
            if (!this.openProvidedInterfaces.containsKey(interfaceID)) {
                this.openProvidedInterfaces.put(interfaceID, new LinkedList<AssemblyContext>());
                this.openRequiredInterfaces.put(interfaceID, new LinkedList<AssemblyContext>());
                this.connectedProvidedInterfaces.put(interfaceID, new LinkedList<AssemblyContext>());
            }
        }
    }
}
Also used : OperationProvidedRole(org.palladiosimulator.pcm.repository.OperationProvidedRole) ProvidedRole(org.palladiosimulator.pcm.repository.ProvidedRole) RequiredRole(org.palladiosimulator.pcm.repository.RequiredRole) OperationRequiredRole(org.palladiosimulator.pcm.repository.OperationRequiredRole) OperationProvidedRole(org.palladiosimulator.pcm.repository.OperationProvidedRole) AssemblyContext(org.palladiosimulator.pcm.core.composition.AssemblyContext) RepositoryComponent(org.palladiosimulator.pcm.repository.RepositoryComponent) OperationRequiredRole(org.palladiosimulator.pcm.repository.OperationRequiredRole)

Aggregations

AssemblyContext (org.palladiosimulator.pcm.core.composition.AssemblyContext)64 AllocationContext (org.palladiosimulator.pcm.allocation.AllocationContext)16 RepositoryComponent (org.palladiosimulator.pcm.repository.RepositoryComponent)11 ArrayList (java.util.ArrayList)9 ResourceContainer (org.palladiosimulator.pcm.resourceenvironment.ResourceContainer)9 AssemblyConnector (org.palladiosimulator.pcm.core.composition.AssemblyConnector)8 System (org.palladiosimulator.pcm.system.System)8 Test (org.junit.Test)7 Connector (org.palladiosimulator.pcm.core.composition.Connector)7 OperationProvidedRole (org.palladiosimulator.pcm.repository.OperationProvidedRole)6 HashSet (java.util.HashSet)5 EObject (org.eclipse.emf.ecore.EObject)5 Allocation (org.palladiosimulator.pcm.allocation.Allocation)5 DataPrivacyLvl (org.palladiosimulator.pcm.compositionprivacy.DataPrivacyLvl)5 OperationRequiredRole (org.palladiosimulator.pcm.repository.OperationRequiredRole)5 ProvidedRole (org.palladiosimulator.pcm.repository.ProvidedRole)5 HashMap (java.util.HashMap)4 AssemblyEntry (org.iobserve.model.correspondence.AssemblyEntry)4 RequiredRole (org.palladiosimulator.pcm.repository.RequiredRole)4 URL (java.net.URL)3