Skip to content

Instantly share code, notes, and snippets.

@jsanda
Created May 27, 2014 17:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jsanda/543a822b6324f601bfae to your computer and use it in GitHub Desktop.
Save jsanda/543a822b6324f601bfae to your computer and use it in GitHub Desktop.
@POST
@Path("/metrics")
@Consumes({"application/json","application/xml"})
public void addMetrics(@Suspended AsyncResponse asyncResponse, Collection<IdDataPoint> dataPoints) {
Set<RawNumericMetric> rawSet = new HashSet<>(dataPoints.size());
for (IdDataPoint dataPoint : dataPoints) {
RawNumericMetric rawMetric = new RawNumericMetric(dataPoint.getId(), dataPoint.getValue(),
dataPoint.getTimestamp());
rawSet.add(rawMetric);
}
addData(asyncResponse, rawSet);
}
private void addData(final AsyncResponse asyncResponse, Set<RawNumericMetric> rawData) {
ListenableFuture<Map<RawNumericMetric,Throwable>> future = metricsService.addData(rawData);
Futures.addCallback(future, new FutureCallback<Map<RawNumericMetric, Throwable>>() {
@Override
public void onSuccess(Map<RawNumericMetric, Throwable> errors) {
Response jaxrs = Response.ok().type(MediaType.APPLICATION_JSON_TYPE).build();
asyncResponse.resume(jaxrs);
}
@Override
public void onFailure(Throwable t) {
asyncResponse.resume(t);
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment