Java tutorial
/** * Copyright 2014 Andy Godwin * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package uk.co.sdev.async.http.ning; import com.fasterxml.jackson.core.type.TypeReference; import uk.co.sdev.async.http.AbstractParallel3CompletableFutureTest; import uk.co.sdev.async.http.model.NewsItem; import uk.co.sdev.async.http.model.TravelProblem; import uk.co.sdev.async.http.model.Weather; import java.io.IOException; import java.util.Collections; import java.util.List; import java.util.Optional; import java.util.concurrent.CompletableFuture; import static uk.co.sdev.async.Futures.withFallback; public class Parallel3CompletableFutureClientTest extends AbstractParallel3CompletableFutureTest { @Override protected CompletableFuture<List<NewsItem>> getNews() throws IOException { return completableFutureClient.get("http://localhost:9101/news", new TypeReference<List<NewsItem>>() { }).handle(withFallback(Collections.<NewsItem>emptyList())); } @Override protected CompletableFuture<Optional<Weather>> getWeather() throws IOException { return completableFutureClient.get("http://localhost:9101/weather", new TypeReference<Optional<Weather>>() { }); } @Override protected CompletableFuture<List<TravelProblem>> getTravel() throws IOException { return completableFutureClient .get("http://localhost:9101/travel", new TypeReference<List<TravelProblem>>() { }).handle(withFallback(Collections.<TravelProblem>emptyList())); } }