+ public Future<RpcResult<Void>> makeBreakfast( EggsType eggsType, Class<? extends ToastType> toastType,
+ int toastDoneness ) {
+
+ // Call makeToast and use JdkFutureAdapters to convert the Future to a ListenableFuture,
+ // The OpendaylightToaster impl already returns a ListenableFuture so the conversion is
+ // actually a no-op.
+
+ ListenableFuture<RpcResult<Void>> makeToastFuture = JdkFutureAdapters.listenInPoolThread(
+ makeToast( toastType, toastDoneness ), executor );
+
+ ListenableFuture<RpcResult<Void>> makeEggsFuture = makeEggs( eggsType );
+
+ // Combine the 2 ListenableFutures into 1 containing a list of RpcResults.
+
+ ListenableFuture<List<RpcResult<Void>>> combinedFutures =
+ Futures.allAsList( ImmutableList.of( makeToastFuture, makeEggsFuture ) );
+
+ // Then transform the RpcResults into 1.
+
+ return Futures.transform( combinedFutures,
+ new AsyncFunction<List<RpcResult<Void>>,RpcResult<Void>>() {
+ @Override
+ public ListenableFuture<RpcResult<Void>> apply( List<RpcResult<Void>> results )
+ throws Exception {
+ boolean atLeastOneSucceeded = false;
+ Builder<RpcError> errorList = ImmutableList.builder();
+ for( RpcResult<Void> result: results ) {
+ if( result.isSuccessful() ) {
+ atLeastOneSucceeded = true;
+ }
+
+ if( result.getErrors() != null ) {
+ errorList.addAll( result.getErrors() );
+ }
+ }
+
+ return Futures.immediateFuture(
+ RpcResultBuilder.<Void> status( atLeastOneSucceeded )
+ .withRpcErrors( errorList.build() ).build() );
+ }
+ } );
+ }
+
+ private ListenableFuture<RpcResult<Void>> makeEggs( EggsType eggsType ) {
+
+ return executor.submit( new Callable<RpcResult<Void>>() {
+
+ @Override
+ public RpcResult<Void> call() throws Exception {
+
+ // We don't actually do anything here - just return a successful result.
+ return RpcResultBuilder.<Void> success().build();
+ }
+ } );
+ }
+
+ private Future<RpcResult<Void>> makeToast( Class<? extends ToastType> toastType,
+ int toastDoneness ) {