Skip to content

Instantly share code, notes, and snippets.

@jsanda
Created April 2, 2015 14:58
Show Gist options
  • Save jsanda/702b82b06222ded41aad to your computer and use it in GitHub Desktop.
Save jsanda/702b82b06222ded41aad to your computer and use it in GitHub Desktop.
add data end point
public void addDataForMetric(
@Suspended final AsyncResponse asyncResponse,
@PathParam("tenantId") final String tenantId, @PathParam("id") String id,
@ApiParam(value = "List of datapoints containing timestamp and value", required = true)
List<NumericData> data
) {
Callable<Response> callable = () -> {
// long sleep = random.nextLong() % SLEEP;
// if (sleep > 0) {
// try {
// Thread.sleep(sleep);
// } catch (InterruptedException e) {
// }
// }
return Response.status(Status.OK).build();
};
ListenableFuture<Response> future = threadPool.submit(callable);
Futures.addCallback(future, new FutureCallback<Response>() {
@Override
public void onSuccess(Response response) {
asyncResponse.resume(response);
}
@Override
public void onFailure(Throwable t) {
String msg = "Failed to perform operation due to an error: " + Throwables.getRootCause(t).getMessage();
asyncResponse.resume(Response.serverError().entity(new ApiError(msg)).build());
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment