org.glowroot.container.trace.TracePointResponse Maven / Gradle / Ivy
The newest version!
/*
* Copyright 2012-2015 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.glowroot.container.trace;
import java.util.List;
import javax.annotation.Nullable;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Ordering;
import com.google.common.primitives.Longs;
import static com.google.common.base.Preconditions.checkNotNull;
import static org.glowroot.container.common.ObjectMappers.orEmpty;
class TracePointResponse {
private final ImmutableList normalPoints;
private final ImmutableList errorPoints;
private final ImmutableList activePoints;
private TracePointResponse(List normalPoints, List errorPoints,
List activePoints) {
this.normalPoints = ImmutableList.copyOf(normalPoints);
this.errorPoints = ImmutableList.copyOf(errorPoints);
this.activePoints = ImmutableList.copyOf(activePoints);
}
List getNormalPoints() {
return normalPoints;
}
List getErrorPoints() {
return errorPoints;
}
List getActivePoints() {
return activePoints;
}
@JsonCreator
static TracePointResponse readValue(
@JsonProperty("normalPoints") @Nullable List*@Nullable*/RawPoint> uncheckedNormalPoints,
@JsonProperty("errorPoints") @Nullable List*@Nullable*/RawPoint> uncheckedErrorPoints,
@JsonProperty("activePoints") @Nullable List*@Nullable*/RawPoint> uncheckedActivePoints)
throws JsonMappingException {
List normalPoints = orEmpty(uncheckedNormalPoints, "normalPoints");
List errorPoints = orEmpty(uncheckedErrorPoints, "errorPoints");
List activePoints = orEmpty(uncheckedActivePoints, "activePoints");
return new TracePointResponse(normalPoints, errorPoints, activePoints);
}
static class RawPoint {
static final Ordering orderingByCaptureTime = new Ordering() {
@Override
public int compare(@Nullable RawPoint left, @Nullable RawPoint right) {
checkNotNull(left);
checkNotNull(right);
return Longs.compare(left.captureTime, right.captureTime);
}
};
private final long captureTime;
private final String id;
private RawPoint(long captureTime, String id) {
this.captureTime = captureTime;
this.id = id;
}
String getId() {
return id;
}
@JsonCreator
static RawPoint readValue(ArrayNode point) {
long captureTime = point.get(0).asLong();
// duration which is point.get(1) is not needed here
String id = point.get(2).asText();
return new RawPoint(captureTime, id);
}
}
}