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;
}
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, "");
}
}
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;
}
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;
}
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>());
}
}
}
}
Aggregations