use of org.osate.aadl2.properties.PropertyNotPresentException in project osate2 by osate.
the class Binpack method getAllowedProcessorBindings.
/**
* Get the processor components that a given thread is allowed to be bound to
* based on the thread's ALLOWED_PROCESSOR_BINDING and
* ALLOWED_PROCESSOR_BINDING_CLASS property values. The processors are
* search for in the same system instance that the given thread component is
* a part of.
*
* @param thread
* The thread.
* @return An unmodifiable set of processor ComponentInstances.
* @exception IllegalArgumentException
* Thrown if the category of the component instance
* referenced by <code>thread</code> is not
* {@link ComponentCategory#THREAD_LITERAL}.
*/
public Set<ComponentInstance> getAllowedProcessorBindings(final ComponentInstance thread) {
if (thread.getCategory() != ComponentCategory.THREAD) {
throw new IllegalArgumentException("Component \"" + thread.getName() + "\" is not a thread.");
}
List<ComponentInstance> allowedBindingsVals;
try {
allowedBindingsVals = GetProperties.getAllowedProcessorBinding(thread);
} catch (PropertyNotPresentException e) {
// Ignore this situation and move on.
allowedBindingsVals = Collections.emptyList();
}
List<Classifier> allowedClassVals;
try {
allowedClassVals = GetProperties.getAllowedProcessorBindingClass(thread);
} catch (PropertyNotPresentException e) {
// Ignore this situation and move on.
allowedClassVals = Collections.emptyList();
}
final Set<ComponentInstance> searchRoots = new HashSet<>();
if (allowedBindingsVals.isEmpty()) {
searchRoots.add(thread.getSystemInstance());
} else {
for (final Iterator<ComponentInstance> i = allowedBindingsVals.iterator(); i.hasNext(); ) {
final ComponentInstance rv = i.next();
searchRoots.add(rv);
}
}
final Set<SystemClassifier> allowedSystemClassifiers = new HashSet<>();
final Set<ProcessorClassifier> allowedProcClassifiers = new HashSet<>();
for (final Iterator<Classifier> i = allowedClassVals.iterator(); i.hasNext(); ) {
final Classifier cc = i.next();
if (cc instanceof ProcessorClassifier) {
// ComponentCategory.PROCESSOR) {
allowedProcClassifiers.add((ProcessorClassifier) cc);
} else if (cc instanceof SystemClassifier) {
// cv.getValue() == ComponentCategory.SYSTEM_LITERAL) {
allowedSystemClassifiers.add((SystemClassifier) cc);
} else {
internalError("Ill-formed allowed_processor_binding_class value: got a non-system non-processor component classifier");
}
}
final Set<ComponentInstance> allowedProcs = new HashSet<>();
for (final Iterator<ComponentInstance> i = searchRoots.iterator(); i.hasNext(); ) {
final ComponentInstance ci = i.next();
getAllowedProcessorBindings(ci, allowedProcs, allowedProcClassifiers, allowedSystemClassifiers);
}
return Collections.unmodifiableSet(allowedProcs);
}
use of org.osate.aadl2.properties.PropertyNotPresentException in project osate2 by osate.
the class SetInstanceModelBindings method prepare.
public boolean prepare() {
/*
* First get the old processor bindings so we can undo.
* We assume that the bindings are NOT modal!
*/
try {
for (Iterator iter = threadsToProc.keySet().iterator(); iter.hasNext(); ) {
final ComponentInstance thread = (ComponentInstance) iter.next();
// Get the old val, may not have been set
PropertyValue oldVal;
try {
oldVal = (PropertyValue) thread.getSimplePropertyValue(GetProperties.getActualProcessorBindingProperty(thread));
} catch (PropertyNotPresentException e) {
oldVal = null;
}
oldThreadsToProc.put(thread, oldVal);
}
/*
* Next we go through the given thread->proc map and change it to be a
* map from theads to InstanceReferenceValues. This way we don't have
* to keep recreating reference values.
*/
for (Iterator iter = threadsToProc.keySet().iterator(); iter.hasNext(); ) {
final ComponentInstance thread = (ComponentInstance) iter.next();
final ComponentInstance proc = (ComponentInstance) threadsToProc.get(thread);
final InstanceReferenceValue val = InstanceFactory.eINSTANCE.createInstanceReferenceValue();
val.setReferencedInstanceObject(proc);
threadsToProc.put(thread, val);
}
// always ready to go
return true;
} catch (InvalidModelException e) {
ResourcemanagementPlugin.logErrorMessage(e.getMessage());
return false;
}
}
use of org.osate.aadl2.properties.PropertyNotPresentException in project osate2 by osate.
the class PriorityInversion method checkPriorityInversion.
/**
* check for priority inversion of threads bound to the given processor
* @param curProcessor Component Instance of processor
*/
public void checkPriorityInversion(ComponentInstance curProcessor) {
SystemInstance root = curProcessor.getSystemInstance();
final ComponentInstance currentProcessor = curProcessor;
EList<Element> boundThreads = new ForAllElement() {
@Override
protected boolean suchThat(Element obj) {
if (!InstanceModelUtil.isPeriodicThread((ComponentInstance) obj)) {
return false;
}
List<ComponentInstance> boundProcessor;
try {
boundProcessor = GetProperties.getActualProcessorBinding((ComponentInstance) obj);
} catch (PropertyNotPresentException e) {
return false;
}
return boundProcessor.contains(currentProcessor);
}
}.processPreOrderComponentInstance(root, ComponentCategory.THREAD);
// we will sort the thread list by period and
// check to make sure the assigned priority is monotonically decreasing
ECollections.sort(boundThreads, (obj1, obj2) -> {
final double a = PropertyUtils.getScaled(TimingProperties::getPeriod, (ComponentInstance) obj1, TimeUnits.MS).orElse(0.0);
final double b = PropertyUtils.getScaled(TimingProperties::getPeriod, (ComponentInstance) obj2, TimeUnits.MS).orElse(0.0);
if (a > b) {
return 1;
}
if (a == b) {
return 0;
}
return -1;
});
checkDecreasingPriority(boundThreads);
}
use of org.osate.aadl2.properties.PropertyNotPresentException in project osate2 by osate.
the class ModelingProperties method getAcceptableArraySize.
public static Optional<List<IntegerRange>> getAcceptableArraySize(NamedElement lookupContext, Optional<Mode> mode) {
Property property = getAcceptableArraySize_Property(lookupContext);
try {
PropertyExpression value = CodeGenUtil.lookupProperty(property, lookupContext, mode);
PropertyExpression resolved = CodeGenUtil.resolveNamedValue(value, lookupContext, mode);
return Optional.of(((ListValue) resolved).getOwnedListElements().stream().map(element1 -> {
PropertyExpression resolved1 = CodeGenUtil.resolveNamedValue(element1, lookupContext, mode);
return new IntegerRange(resolved1, lookupContext, mode);
}).collect(Collectors.toList()));
} catch (PropertyNotPresentException e) {
return Optional.empty();
}
}
use of org.osate.aadl2.properties.PropertyNotPresentException in project osate2 by osate.
the class ModelingProperties method getImplementedAs.
public static Optional<Classifier> getImplementedAs(NamedElement lookupContext, Optional<Mode> mode) {
Property property = getImplementedAs_Property(lookupContext);
try {
PropertyExpression value = CodeGenUtil.lookupProperty(property, lookupContext, mode);
PropertyExpression resolved = CodeGenUtil.resolveNamedValue(value, lookupContext, mode);
return Optional.of(((ClassifierValue) resolved).getClassifier());
} catch (PropertyNotPresentException e) {
return Optional.empty();
}
}
Aggregations