+ public ListenableFuture<RpcResult<Void>> makeBreakfast(final EggsType eggsType, final ToastType toastType,
+ final int toastDoneness) {
+ // Call makeToast, The OpendaylightToaster impl already returns a ListenableFuture so the conversion is
+ // actually a no-op.
+
+ ListenableFuture<RpcResult<MakeToastOutput>> makeToastFuture = makeToast(toastType, toastDoneness);
+
+ ListenableFuture<RpcResult<Void>> makeEggsFuture = makeEggs(eggsType);
+
+ // Combine the 2 ListenableFutures into 1 containing a list RpcResults.
+
+ ListenableFuture<List<RpcResult<? extends Object>>> combinedFutures = Futures
+ .allAsList(ImmutableList.of(makeToastFuture, makeEggsFuture));
+
+ // Then transform the RpcResults into 1.
+
+ return Futures.transformAsync(combinedFutures, results -> {
+ boolean atLeastOneSucceeded = false;
+ Builder<RpcError> errorList = ImmutableList.builder();
+ for (RpcResult<? extends Object> result : results) {
+ if (result.isSuccessful()) {
+ atLeastOneSucceeded = true;
+ }
+
+ if (result.getErrors() != null) {
+ errorList.addAll(result.getErrors());
+ }
+ }
+
+ return RpcResultBuilder.<Void>status(atLeastOneSucceeded).withRpcErrors(errorList.build()).buildFuture();
+ }, MoreExecutors.directExecutor());
+ }