String operand2;
String pidfileContentsCache = null; // so we avoid reading the file over and over again
for (ProcessInfo process : getProcesses()) {
ProcessInfo processToMatch; // will be the same as process unless the parent qualifier was provided
if (qualifier.equals(Qualifier.parent)) {
processToMatch = getParentProcess(process);
} else {
processToMatch = process;
}
if (attribute.getAttributeValue().equals(Attribute.ProcessCategoryAttributes.name.toString())) {
operand1 = (processToMatch != null) ? processToMatch.getName() : "";
operand2 = criteria.getValue();
} else if (attribute.getAttributeValue().equals(Attribute.ProcessCategoryAttributes.basename.toString())) {
operand1 = (processToMatch != null) ? processToMatch.getBaseName() : "";
operand2 = criteria.getValue();
} else if (attribute.getAttributeValue().equals(Attribute.ProcessCategoryAttributes.pid.toString())) {
operand1 = (processToMatch != null) ? Long.toString(processToMatch.getPid()) : "";
operand2 = criteria.getValue();
} else if (attribute.getAttributeValue().equals(Attribute.ProcessCategoryAttributes.pidfile.toString())) {
if (pidfileContentsCache == null) {
pidfileContentsCache = getPidfileContents(criteria.getValue());
}
operand1 = (processToMatch != null) ? String.valueOf(processToMatch.getPid()) : null;
operand2 = pidfileContentsCache;
} else {
throw new IllegalArgumentException(
"Criteria with 'process' category must have an attribute of either 'name' or 'basename': "
+ criteria);