/** This method uses JAX-RS 2 {@link AsyncResponse} response capability. */ @GET @Produces(MediaType.TEXT_PLAIN) public void /* Yes it returns void */ asyncQueue( @BeanParam final CommonQueryProvider t, @Suspended final AsyncResponse asyncResponse) { if (GET_PROBE.hit()) { System.out.println("GET TPS: " + GET_PROBE.getLastInvocationCount()); } Work work = new Work( UUID.randomUUID().toString(), "work-payload", new CompletionCallback() { @Override public void onSuccess(Result result) { asyncResponse.resume(result.toString()); } @Override public void onFailure(Result result, Exception e, CompletionStatus sttaus) { asyncResponse.resume(e); } }); QUEUE.add(work); }
@PUT @Consumes(MediaType.TEXT_PLAIN) @Path("/sql") public void submit(String sql, @Suspended final AsyncResponse response) { if (PUT_PROBE.hit()) { System.err.println("PUT TPS: " + PUT_PROBE.getLastInvocationCount()); } final long time = System.currentTimeMillis(); ApplicationContext applicationContext = SpringContextLoader.getContext(); WorkQueue jdbcBatchQueue = (WorkQueue) applicationContext.getBean("batchUpdateQueue"); Work work = new Work( UUID.randomUUID().toString(), new String[] {sql}, new CompletionCallback() { @Override public void onSuccess(Result result) { response.resume( "Result received in " + (System.currentTimeMillis() - time) + "ms: " + result.toString()); } @Override public void onFailure(Result result, Exception e, CompletionStatus status) { e.printStackTrace(); response.resume(e); } }); jdbcBatchQueue.add(work); }