Search in sources :

Example 11 with AgentResponse

use of org.glassfish.jersey.examples.rx.domain.AgentResponse in project jersey by jersey.

the class ListenableFutureAgentResource method listenable.

@GET
@ManagedAsync
public void listenable(@Suspended final AsyncResponse async) {
    final long time = System.nanoTime();
    final AgentResponse response = new AgentResponse();
    // Obtain and set visited and recommended places to create a response ...
    final ListenableFuture<List<AgentResponse>> successful = Futures.successfulAsList(Arrays.asList(visited(response), recommended(response)));
    // ... and when we have them, return response to the client.
    Futures.addCallback(successful, new FutureCallback<List<AgentResponse>>() {

        @Override
        public void onSuccess(final List<AgentResponse> result) {
            response.setProcessingTime((System.nanoTime() - time) / 1000000);
            async.resume(response);
        }

        @Override
        public void onFailure(final Throwable t) {
            async.resume(t);
        }
    });
}
Also used : List(java.util.List) AgentResponse(org.glassfish.jersey.examples.rx.domain.AgentResponse) GET(javax.ws.rs.GET) ManagedAsync(org.glassfish.jersey.server.ManagedAsync)

Aggregations

AgentResponse (org.glassfish.jersey.examples.rx.domain.AgentResponse)11 GET (javax.ws.rs.GET)6 List (java.util.List)5 Response (javax.ws.rs.core.Response)5 Calculation (org.glassfish.jersey.examples.rx.domain.Calculation)5 Destination (org.glassfish.jersey.examples.rx.domain.Destination)5 Forecast (org.glassfish.jersey.examples.rx.domain.Forecast)5 Recommendation (org.glassfish.jersey.examples.rx.domain.Recommendation)5 JerseyTest (org.glassfish.jersey.test.JerseyTest)5 Test (org.junit.Test)5 ConcurrentLinkedQueue (java.util.concurrent.ConcurrentLinkedQueue)4 GenericType (javax.ws.rs.core.GenericType)4 Path (javax.ws.rs.Path)3 Produces (javax.ws.rs.Produces)3 WebTarget (javax.ws.rs.client.WebTarget)3 AsyncResponse (javax.ws.rs.container.AsyncResponse)3 Suspended (javax.ws.rs.container.Suspended)3 ManagedAsync (org.glassfish.jersey.server.ManagedAsync)3 Uri (org.glassfish.jersey.server.Uri)3 ArrayList (java.util.ArrayList)2