Examples of AgentResponse


Examples of models.asynchttp.response.AgentResponse

          try {
            agentResponse = request.getResponseType().newInstance();
          } catch (Exception e) {
            models.utils.LogUtils.printLogError(e.getLocalizedMessage()
                + " in reply() in GAOpWorker");
            agentResponse = new AgentResponse();
          }
        }

        agentResponse.setError(error);
        agentResponse.setErrorMessage(errorMessage);
View Full Code Here

Examples of models.asynchttp.response.AgentResponse

      try {
        agentResponse = request.getResponseType().newInstance();
      } catch (Exception e) {
        models.utils.LogUtils.printLogError(e.getLocalizedMessage()
            + " in sendProgress() in GAOpWorker");
        agentResponse = new AgentResponse();
      }
    }
    agentResponse.setOperationTimeMillis(operationTimeMillis);
    agentResponse.setRequest(request);
    agentResponse.setHost(host);
View Full Code Here

Examples of org.glassfish.jersey.examples.rx.domain.AgentResponse

        assertThat(response.getStatus(), is(200));
    }

    @Test
    public void testSyncClient() throws Exception {
        final AgentResponse response = target("agent").path("sync").request().get(AgentResponse.class);

        assertThat(response.getVisited().size(), is(5));
        assertThat(response.getRecommended().size(), is(5));

        assertThat(response.getProcessingTime() > 4500, is(true));

        System.out.println("Processing Time: " + response.getProcessingTime());
    }
View Full Code Here

Examples of org.glassfish.jersey.examples.rx.domain.AgentResponse

    @GET
    public void observable(@Suspended final AsyncResponse async) {
        final long time = System.nanoTime();

        Observable.just(new AgentResponse())
                // Obtain visited destinations.
                .zipWith(visited(), new Func2<AgentResponse, List<Destination>,  AgentResponse>() {
                    @Override
                    public AgentResponse call(final AgentResponse agentResponse, final List<Destination> destinations) {
                        agentResponse.setVisited(destinations);
View Full Code Here

Examples of org.glassfish.jersey.examples.rx.domain.AgentResponse

        System.out.println("Processing Time: " + response.getProcessingTime());
    }

    @Test
    public void testAsyncClient() throws Exception {
        final AgentResponse response = target("agent").path("async").request().get(AgentResponse.class);

        assertThat(response.getVisited().size(), is(5));
        assertThat(response.getRecommended().size(), is(5));

        assertThat(response.getProcessingTime() > 850, is(true));
        assertThat(response.getProcessingTime() < 4500, is(true));

        System.out.println("Processing Time: " + response.getProcessingTime());
    }
View Full Code Here

Examples of org.glassfish.jersey.examples.rx.domain.AgentResponse

        System.out.println("Processing Time: " + response.getProcessingTime());
    }

    @Test
    public void testRxObservableClient() throws Exception {
        final AgentResponse response = target("agent").path("observable").request().get(AgentResponse.class);

        assertThat(response.getVisited().size(), is(5));
        assertThat(response.getRecommended().size(), is(5));

        assertThat(response.getProcessingTime() > 850, is(true));
        assertThat(response.getProcessingTime() < 4500, is(true));

        System.out.println("Processing Time: " + response.getProcessingTime());
    }
View Full Code Here

Examples of org.glassfish.jersey.examples.rx.domain.AgentResponse

        System.out.println("Processing Time: " + response.getProcessingTime());
    }

    @Test
    public void testRxListenableClient() throws Exception {
        final AgentResponse response = target("agent").path("listenable").request().get(AgentResponse.class);

        assertThat(response.getVisited().size(), is(5));
        assertThat(response.getRecommended().size(), is(5));

        assertThat(response.getProcessingTime() > 850, is(true));
        assertThat(response.getProcessingTime() < 4500, is(true));

        System.out.println("Processing Time: " + response.getProcessingTime());
    }
View Full Code Here

Examples of org.glassfish.jersey.examples.rx.domain.AgentResponse

    private WebTarget forecast;

    @GET
    public AgentResponse sync() {
        final long time = System.nanoTime();
        final AgentResponse response = new AgentResponse();

        // Obtain visited destinations.
        response.setVisited(destination.path("visited").request()
                // Identify the user.
                .header("Rx-User", "Sync")
                // Return a list of destinations
                .get(new GenericType<List<Destination>>() {}));

        // Obtain recommended destinations. (does not depend on visited ones)
        final List<Destination> recommended = destination.path("recommended").request()
                // Identify the user.
                .header("Rx-User", "Sync")
                // Return a list of destinations.
                .get(new GenericType<List<Destination>>() {});

        // Forecasts. (depend on recommended destinations)
        final List<Forecast> forecasts = new ArrayList<>(recommended.size());
        for (final Destination dest : recommended) {
            forecasts.add(forecast.resolveTemplate("destination", dest.getDestination()).request().get(Forecast.class));
        }

        // Calculations. (depend on recommended destinations)
        final List<Calculation> calculations = new ArrayList<>(recommended.size());
        for (final Destination dest : recommended) {
            calculations.add(calculation.resolveTemplate("from", "Moon").resolveTemplate("to", dest.getDestination())
                    .request().get(Calculation.class));
        }

        // Recommendations.
        final List<Recommendation> recommendations = new ArrayList<>(recommended.size());
        for (int i = 0; i < recommended.size(); i++) {
            recommendations.add(new Recommendation(recommended.get(i).getDestination(), forecasts.get(i).getForecast(),
                    calculations.get(i).getPrice()));
        }

        response.setRecommended(recommendations);
        response.setProcessingTime((System.nanoTime() - time) / 1000000);
        return response;
    }
View Full Code Here

Examples of org.glassfish.jersey.examples.rx.domain.AgentResponse

    @GET
    @ManagedAsync
    public void async(@Suspended final AsyncResponse async) {
        final long time = System.nanoTime();

        final AgentResponse response = new AgentResponse();

        final CountDownLatch outerLatch = new CountDownLatch(2);
        final Queue<String> errors = new ConcurrentLinkedQueue<>();

        // Obtain visited destinations.
        destination.path("visited").request()
                // Identify the user.
                .header("Rx-User", "Async")
                // Async invoker.
                .async()
                // Return a list of destinations
                .get(new InvocationCallback<List<Destination>>() {
                    @Override
                    public void completed(final List<Destination> destinations) {
                        response.setVisited(destinations);
                        outerLatch.countDown();
                    }

                    @Override
                    public void failed(final Throwable throwable) {
                        errors.offer("Visited: " + throwable.getMessage());
                        outerLatch.countDown();
                    }
                });


        // Obtain recommended destinations. (does not depend on visited ones)
        destination.path("recommended").request()
                // Identify the user.
                .header("Rx-User", "Async")
                // Async invoker.
                .async()
                // Return a list of destinations.
                .get(new InvocationCallback<List<Destination>>() {
                    @Override
                    public void completed(final List<Destination> recommended) {
                        final CountDownLatch innerLatch = new CountDownLatch(recommended.size() * 2);

                        // Forecasts. (depend on recommended destinations)
                        final List<Forecast> forecasts = Collections.synchronizedList(
                                new ArrayList<Forecast>(recommended.size()));
                        for (final Destination dest : recommended) {
                            forecast.resolveTemplate("destination", dest.getDestination()).request()
                                    .async()
                                    .get(new InvocationCallback<Forecast>() {
                                        @Override
                                        public void completed(final Forecast forecast) {
                                            forecasts.add(forecast);
                                            innerLatch.countDown();
                                        }

                                        @Override
                                        public void failed(final Throwable throwable) {
                                            errors.offer("Forecast: " + throwable.getMessage());
                                            innerLatch.countDown();
                                        }
                                    });
                        }

                        // Calculations. (depend on recommended destinations)
                        final List<Calculation> calculations = Collections.synchronizedList(
                                new ArrayList<Calculation>(recommended.size()));
                        for (final Destination dest : recommended) {
                            calculation.resolveTemplate("from", "Moon").resolveTemplate("to", dest.getDestination())
                                    .request()
                                    .async()
                                    .get(new InvocationCallback<Calculation>() {
                                        @Override
                                        public void completed(final Calculation calculation) {
                                            calculations.add(calculation);
                                            innerLatch.countDown();
                                        }

                                        @Override
                                        public void failed(final Throwable throwable) {
                                            errors.offer("Calculation: " + throwable.getMessage());
                                            innerLatch.countDown();
                                        }
                                    });
                        }

                        // Have to wait here for dependent requests ...
                        try {
                            if (!innerLatch.await(10, TimeUnit.SECONDS)) {
                                errors.offer("Inner: Waiting for requests to complete has timed out.");
                            }
                        } catch (final InterruptedException e) {
                            errors.offer("Inner: Waiting for requests to complete has been interrupted.");
                        }

                        // Recommendations.
                        final List<Recommendation> recommendations = new ArrayList<>(recommended.size());
                        for (int i = 0; i < recommended.size(); i++) {
                            recommendations.add(new Recommendation(recommended.get(i).getDestination(),
                                    forecasts.get(i).getForecast(), calculations.get(i).getPrice()));
                        }
                        response.setRecommended(recommendations);

                        outerLatch.countDown();
                    }

                    @Override
                    public void failed(final Throwable throwable) {
                        errors.offer("Recommended: " + throwable.getMessage());
                        outerLatch.countDown();
                    }
                });

        // ... and have to wait also here for independent requests.
        try {
            if (!outerLatch.await(10, TimeUnit.SECONDS)) {
                errors.offer("Outer: Waiting for requests to complete has timed out.");
            }
        } catch (final InterruptedException e) {
            errors.offer("Outer: Waiting for requests to complete has been interrupted.");
        }

        if (errors.isEmpty()) {
            response.setProcessingTime((System.nanoTime() - time) / 1000000);

            async.resume(response);
        } else {
            final ArrayList<String> issues = new ArrayList<>(errors);
            for (final String issue : issues) {
View Full Code Here

Examples of org.glassfish.jersey.examples.rx.domain.AgentResponse

    @GET
    @ManagedAsync
    public void observable(@Suspended final AsyncResponse async) {
        final long time = System.nanoTime();
        final AgentResponse response = new AgentResponse();

        // Fallback.
        Futures.addCallback(Futures.successfulAsList(Arrays.asList(visited(response), recommended(response))),
                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) {
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.