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.AbstractParallel2SequentialCompletableFutureTest; import uk.co.sdev.async.http.model.Denominator; import uk.co.sdev.async.http.model.Numerator; import uk.co.sdev.async.http.model.Quotient; import java.io.IOException; import java.util.Optional; import java.util.concurrent.CompletableFuture; import static uk.co.sdev.async.Futures.withFallback; public class Parallel2SequentialCompletableFutureClientTest extends AbstractParallel2SequentialCompletableFutureTest { @Override protected CompletableFuture<Optional<Numerator>> getNumerator() throws IOException { return completableFutureClient .get("http://localhost:9101/numerator", new TypeReference<Optional<Numerator>>() { }).handle(withFallback(Optional.<Numerator>empty())); } @Override protected CompletableFuture<Optional<Denominator>> getDenominator() throws IOException { return completableFutureClient .get("http://localhost:9101/denominator", new TypeReference<Optional<Denominator>>() { }).handle(withFallback(Optional.<Denominator>empty())); } @Override protected CompletableFuture<Optional<Quotient>> divide(Numerator numerator, Denominator denominator) throws IOException { String url = "http://localhost:9101/divide/" + numerator.getValue().toString() + "/" + denominator.getValue().toString(); return completableFutureClient.get(url, new TypeReference<Optional<Quotient>>() { }).handle(withFallback(Optional.<Quotient>empty())); } }