Created
May 27, 2014 17:49
-
-
Save jsanda/543a822b6324f601bfae to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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