use of es.bsc.compss.types.annotations.Constraints in project compss by bsc-wdc.
the class Test method constraintManagerTest.
/*
* *************************************** CONSTRAINT MANAGER TEST IMPLEMENTATION
* ***************************************
*/
@SuppressWarnings("unchecked")
private static void constraintManagerTest() {
// Check if the number of tasks from ITF and core is the same
java.lang.reflect.Method[] declaredMethodsItf = TestItf.class.getDeclaredMethods();
coreCountItf = declaredMethodsItf.length;
if (CoreManager.getCoreCount() != coreCountItf) {
System.out.println("[ERROR]" + CoreManager.getCoreCount() + " CE registered in the runtime and " + coreCountItf + " declared in the CEI");
System.exit(-1);
}
// Loading data from Cores
signatureToId = CoreManager.getSignaturesToId();
idToSignatures = new LinkedList[coreCountItf];
for (int coreId = 0; coreId < coreCountItf; coreId++) {
idToSignatures[coreId] = new LinkedList<String>();
}
for (Entry<String, Integer> entry : signatureToId.entrySet()) {
String signature = entry.getKey();
Integer coreId = entry.getValue();
idToSignatures[coreId].add(signature);
}
// Loading Information from the interface
declaringClassesItf = new String[coreCountItf][];
constraintsItf = new Constraints[coreCountItf][];
generalConstraintsItf = new Constraints[coreCountItf];
coreToName = new String[coreCountItf];
for (int i = 0; i < coreCountItf; i++) {
int cutValue1 = idToSignatures[i].getFirst().indexOf("(");
int cutValue2 = idToSignatures[i].getFirst().indexOf(")");
coreToName[i] = idToSignatures[i].getFirst().substring(0, cutValue1);
String params = idToSignatures[i].getFirst().substring(cutValue1, cutValue2);
java.lang.reflect.Method m = null;
try {
if (params.equals("(")) {
m = TestItf.class.getDeclaredMethod(coreToName[i], new Class[] {});
} else {
m = TestItf.class.getDeclaredMethod(coreToName[i], new Class[] { String.class });
}
} catch (NoSuchMethodException nsme) {
System.out.println("[ERROR] Method " + coreToName[i] + "not found.");
System.exit(-1);
}
// Add general constraints
if (m.isAnnotationPresent(Constraints.class)) {
generalConstraintsItf[i] = m.getAnnotation(Constraints.class);
}
// Get declaring class of each method annotation
Method[] annotations = m.getAnnotationsByType(Method.class);
declaringClassesItf[i] = new String[annotations.length];
for (int j = 0; j < annotations.length; ++j) {
Method methodAnnotation = annotations[j];
declaringClassesItf[i][j] = methodAnnotation.declaringClass();
}
// Get specific constraints of each method annotation
constraintsItf[i] = new Constraints[annotations.length];
for (int j = 0; j < annotations.length; ++j) {
Method methodAnnotation = annotations[j];
constraintsItf[i][j] = methodAnnotation.constraints();
}
}
// Check all cores
for (int i = 0; i < coreCountItf; i++) {
if (declaringClassesItf[i] != null) {
checkCoreElementConstraints(i);
}
}
}
Aggregations