use of com.fasterxml.jackson.databind.exc.MismatchedInputException in project alluxio by Alluxio.
the class Benchmark method processMethodProfiles.
/**
* @param startMs the start time
* @param endMs the end time
* @param nameTransformer function which transforms the type and method into a name. If the
* function returns null, then the method is skipped
* @return a map of names to statistics
*/
@SuppressFBWarnings(value = "DMI_HARDCODED_ABSOLUTE_FILENAME")
protected Map<String, MethodStatistics> processMethodProfiles(long startMs, long endMs, Function<ProfileInput, String> nameTransformer) throws IOException {
Map<String, MethodStatistics> nameStatistics = new HashMap<>();
try (final BufferedReader reader = new BufferedReader(new FileReader(BaseParameters.AGENT_OUTPUT_PATH))) {
String line;
long bucketSize = (endMs - startMs) / StressConstants.MAX_TIME_COUNT;
final ObjectMapper objectMapper = new ObjectMapper();
while ((line = reader.readLine()) != null) {
final Map<String, Object> lineMap;
try {
lineMap = objectMapper.readValue(line, Map.class);
} catch (JsonParseException | MismatchedInputException e) {
// skip the last line of a not completed file
break;
}
final String type = (String) lineMap.get("type");
final String methodName = (String) lineMap.get("methodName");
final Number timestampNumber = (Number) lineMap.get("timestamp");
final Number durationNumber = (Number) lineMap.get("duration");
final Boolean ttfbFlag = (Boolean) lineMap.get("ttfb");
if (type == null || methodName == null || timestampNumber == null || durationNumber == null || ttfbFlag == null) {
continue;
}
final long timestamp = timestampNumber.longValue();
final long duration = durationNumber.longValue();
final boolean ttfb = ttfbFlag.booleanValue();
if (timestamp <= startMs) {
continue;
}
ProfileInput profileInput = new ProfileInput(type, methodName, ttfb);
final String name = nameTransformer.apply(profileInput);
if (name == null) {
continue;
}
if (!nameStatistics.containsKey(name)) {
nameStatistics.put(name, new MethodStatistics());
}
final MethodStatistics statistic = nameStatistics.get(name);
statistic.mTimeNs.recordValue(duration);
statistic.mNumSuccess += 1;
int bucket = Math.min(statistic.mMaxTimeNs.length - 1, (int) ((timestamp - startMs) / bucketSize));
statistic.mMaxTimeNs[bucket] = Math.max(statistic.mMaxTimeNs[bucket], duration);
}
}
return nameStatistics;
}
use of com.fasterxml.jackson.databind.exc.MismatchedInputException in project dhis2-core by dhis2.
the class SystemSetting method convertValueToSerializable.
private Serializable convertValueToSerializable() {
Serializable valueAsSerializable = null;
if (hasValue()) {
Optional<SettingKey> settingKey = SettingKey.getByName(name);
try {
if (settingKey.isPresent()) {
Object valueAsObject = objectMapper.readValue(value, settingKey.get().getClazz());
valueAsSerializable = (Serializable) valueAsObject;
} else {
valueAsSerializable = StringEscapeUtils.unescapeJava(value);
}
} catch (MismatchedInputException ex) {
log.warn("Content could not be de-serialized by Jackson", ex);
valueAsSerializable = StringEscapeUtils.unescapeJava(value);
} catch (JsonProcessingException ex) {
log.error(String.format("An error occurred while de-serializing system setting: '%s'", name), ex);
}
}
return valueAsSerializable;
}
Aggregations