* terms of the Eclipse Public License v1.0 which accompanies this distribution,
* and is available at http://www.eclipse.org/legal/epl-v10.html
*/
* terms of the Eclipse Public License v1.0 which accompanies this distribution,
* and is available at http://www.eclipse.org/legal/epl-v10.html
*/
package org.opendaylight.controller.sample.kitchen.impl;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableList.Builder;
import com.google.common.util.concurrent.Futures;
package org.opendaylight.controller.sample.kitchen.impl;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableList.Builder;
import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.MoreExecutors;
import java.util.List;
import java.util.concurrent.ExecutionException;
import com.google.common.util.concurrent.MoreExecutors;
import java.util.List;
import java.util.concurrent.ExecutionException;
import org.opendaylight.controller.md.sal.common.util.jmx.AbstractMXBean;
import org.opendaylight.controller.sample.kitchen.api.EggsType;
import org.opendaylight.controller.sample.kitchen.api.KitchenService;
import org.opendaylight.controller.sample.kitchen.api.KitchenServiceRuntimeMXBean;
import org.opendaylight.controller.md.sal.common.util.jmx.AbstractMXBean;
import org.opendaylight.controller.sample.kitchen.api.EggsType;
import org.opendaylight.controller.sample.kitchen.api.KitchenService;
import org.opendaylight.controller.sample.kitchen.api.KitchenServiceRuntimeMXBean;
import org.opendaylight.yang.gen.v1.http.netconfcentral.org.ns.toaster.rev091120.MakeToastInput;
import org.opendaylight.yang.gen.v1.http.netconfcentral.org.ns.toaster.rev091120.MakeToastInputBuilder;
import org.opendaylight.yang.gen.v1.http.netconfcentral.org.ns.toaster.rev091120.MakeToastInput;
import org.opendaylight.yang.gen.v1.http.netconfcentral.org.ns.toaster.rev091120.MakeToastInputBuilder;
import org.opendaylight.yang.gen.v1.http.netconfcentral.org.ns.toaster.rev091120.ToastType;
import org.opendaylight.yang.gen.v1.http.netconfcentral.org.ns.toaster.rev091120.ToasterListener;
import org.opendaylight.yang.gen.v1.http.netconfcentral.org.ns.toaster.rev091120.ToasterOutOfBread;
import org.opendaylight.yang.gen.v1.http.netconfcentral.org.ns.toaster.rev091120.ToasterRestocked;
import org.opendaylight.yang.gen.v1.http.netconfcentral.org.ns.toaster.rev091120.ToasterService;
import org.opendaylight.yang.gen.v1.http.netconfcentral.org.ns.toaster.rev091120.WheatBread;
import org.opendaylight.yang.gen.v1.http.netconfcentral.org.ns.toaster.rev091120.ToastType;
import org.opendaylight.yang.gen.v1.http.netconfcentral.org.ns.toaster.rev091120.ToasterListener;
import org.opendaylight.yang.gen.v1.http.netconfcentral.org.ns.toaster.rev091120.ToasterOutOfBread;
import org.opendaylight.yang.gen.v1.http.netconfcentral.org.ns.toaster.rev091120.ToasterRestocked;
import org.opendaylight.yang.gen.v1.http.netconfcentral.org.ns.toaster.rev091120.ToasterService;
import org.opendaylight.yang.gen.v1.http.netconfcentral.org.ns.toaster.rev091120.WheatBread;
import org.opendaylight.yangtools.yang.common.RpcResult;
import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
import org.opendaylight.yangtools.yang.common.RpcResult;
import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
+import org.opendaylight.yangtools.yang.common.Uint32;
+import org.osgi.service.component.annotations.Activate;
+import org.osgi.service.component.annotations.Component;
+import org.osgi.service.component.annotations.Deactivate;
+import org.osgi.service.component.annotations.Reference;
implements KitchenService, KitchenServiceRuntimeMXBean, ToasterListener {
private static final Logger LOG = LoggerFactory.getLogger(KitchenServiceImpl.class);
implements KitchenService, KitchenServiceRuntimeMXBean, ToasterListener {
private static final Logger LOG = LoggerFactory.getLogger(KitchenServiceImpl.class);
- 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.
+ 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<Void>> makeToastFuture = JdkFutureAdapters
- .listenInPoolThread(makeToast(toastType, toastDoneness), executor);
+ ListenableFuture<RpcResult<MakeToastOutput>> makeToastFuture = makeToast(toastType, toastDoneness);
ListenableFuture<RpcResult<Void>> makeEggsFuture = makeEggs(eggsType);
// Combine the 2 ListenableFutures into 1 containing a list RpcResults.
ListenableFuture<RpcResult<Void>> makeEggsFuture = makeEggs(eggsType);
// Combine the 2 ListenableFutures into 1 containing a list RpcResults.
.allAsList(ImmutableList.of(makeToastFuture, makeEggsFuture));
// Then transform the RpcResults into 1.
.allAsList(ImmutableList.of(makeToastFuture, makeEggsFuture));
// Then transform the RpcResults into 1.
return Futures.transformAsync(combinedFutures, results -> {
boolean atLeastOneSucceeded = false;
Builder<RpcError> errorList = ImmutableList.builder();
return Futures.transformAsync(combinedFutures, results -> {
boolean atLeastOneSucceeded = false;
Builder<RpcError> errorList = ImmutableList.builder();
- return Futures.immediateFuture(RpcResultBuilder.<Void>status(atLeastOneSucceeded)
- .withRpcErrors(errorList.build()).build());
- });
+ return RpcResultBuilder.<Void>status(atLeastOneSucceeded).withRpcErrors(errorList.build()).buildFuture();
+ }, MoreExecutors.directExecutor());
- private ListenableFuture<RpcResult<Void>> makeEggs(EggsType eggsType) {
- return executor.submit(() -> RpcResultBuilder.<Void>success().build());
+ private ListenableFuture<RpcResult<Void>> makeEggs(final EggsType eggsType) {
+ return Futures.submit(() -> RpcResultBuilder.<Void>success().build(), executor);
- return Futures.immediateFuture(RpcResultBuilder.<Void>success().withWarning(ErrorType.APPLICATION,
- "partial-operation", "Toaster is out of bread but we can make you eggs").build());
+ return RpcResultBuilder.success(EMPTY_MAKE_OUTPUT)
+ .withWarning(ErrorType.APPLICATION, ErrorTag.PARTIAL_OPERATION,
+ "Toaster is out of bread but we can make you eggs")
+ .buildFuture();
public Boolean makeScrambledWithWheat() {
try {
// This call has to block since we must return a result to the JMX client.
public Boolean makeScrambledWithWheat() {
try {
// This call has to block since we must return a result to the JMX client.
- public void onToasterRestocked(ToasterRestocked notification) {
- LOG.info("ToasterRestocked notification - amountOfBread: " + notification.getAmountOfBread());
+ public void onToasterRestocked(final ToasterRestocked notification) {
+ LOG.info("ToasterRestocked notification - amountOfBread: {}", notification.getAmountOfBread());