X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsamples%2Ftoaster-consumer%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fsample%2Fkitchen%2Fimpl%2FKitchenServiceImpl.java;h=55bb9e426707684a302fb4275d475aaa5f1767cd;hp=50ae8fd04fcce09c66a9eb7dd512af433df058d7;hb=21186d16ca8b233674ebdf3aa1ea190a2c0b3959;hpb=c1362c86eb19e92e6c64d10099a45deb499c6db1 diff --git a/opendaylight/md-sal/samples/toaster-consumer/src/main/java/org/opendaylight/controller/sample/kitchen/impl/KitchenServiceImpl.java b/opendaylight/md-sal/samples/toaster-consumer/src/main/java/org/opendaylight/controller/sample/kitchen/impl/KitchenServiceImpl.java index 50ae8fd04f..55bb9e4267 100644 --- a/opendaylight/md-sal/samples/toaster-consumer/src/main/java/org/opendaylight/controller/sample/kitchen/impl/KitchenServiceImpl.java +++ b/opendaylight/md-sal/samples/toaster-consumer/src/main/java/org/opendaylight/controller/sample/kitchen/impl/KitchenServiceImpl.java @@ -1,17 +1,30 @@ +/* + * Copyright (c) 2014, 2015 Brocade Communications Systems, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * 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 java.util.Arrays; -import java.util.Collections; +import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableList.Builder; +import com.google.common.util.concurrent.AsyncFunction; +import com.google.common.util.concurrent.Futures; +import com.google.common.util.concurrent.JdkFutureAdapters; +import com.google.common.util.concurrent.ListenableFuture; +import com.google.common.util.concurrent.ListeningExecutorService; +import com.google.common.util.concurrent.MoreExecutors; import java.util.List; import java.util.concurrent.Callable; import java.util.concurrent.ExecutionException; import java.util.concurrent.Executors; import java.util.concurrent.Future; -import org.opendaylight.controller.config.yang.config.kitchen_service.impl.KitchenServiceRuntimeMXBean; -import org.opendaylight.controller.sal.common.util.RpcErrors; -import org.opendaylight.controller.sal.common.util.Rpcs; +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.ToastType; @@ -20,23 +33,15 @@ import org.opendaylight.yang.gen.v1.http.netconfcentral.org.ns.toaster.rev091120 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.RpcError.ErrorSeverity; import org.opendaylight.yangtools.yang.common.RpcError; -import org.opendaylight.yangtools.yang.common.RpcResult; import org.opendaylight.yangtools.yang.common.RpcError.ErrorType; +import org.opendaylight.yangtools.yang.common.RpcResult; +import org.opendaylight.yangtools.yang.common.RpcResultBuilder; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableList.Builder; -import com.google.common.util.concurrent.AsyncFunction; -import com.google.common.util.concurrent.Futures; -import com.google.common.util.concurrent.JdkFutureAdapters; -import com.google.common.util.concurrent.ListenableFuture; -import com.google.common.util.concurrent.ListeningExecutorService; -import com.google.common.util.concurrent.MoreExecutors; - -public class KitchenServiceImpl implements KitchenService, KitchenServiceRuntimeMXBean, ToasterListener { +public class KitchenServiceImpl extends AbstractMXBean + implements KitchenService, KitchenServiceRuntimeMXBean, ToasterListener { private static final Logger log = LoggerFactory.getLogger( KitchenServiceImpl.class ); @@ -48,6 +53,7 @@ public class KitchenServiceImpl implements KitchenService, KitchenServiceRuntime private volatile boolean toasterOutOfBread; public KitchenServiceImpl(ToasterService toaster) { + super("KitchenService", "toaster-consumer", null); this.toaster = toaster; } @@ -89,7 +95,8 @@ public class KitchenServiceImpl implements KitchenService, KitchenServiceRuntime } return Futures.immediateFuture( - Rpcs. getRpcResult( atLeastOneSucceeded, errorList.build() ) ); + RpcResultBuilder. status( atLeastOneSucceeded ) + .withRpcErrors( errorList.build() ).build() ); } } ); } @@ -102,7 +109,7 @@ public class KitchenServiceImpl implements KitchenService, KitchenServiceRuntime public RpcResult call() throws Exception { // We don't actually do anything here - just return a successful result. - return Rpcs. getRpcResult( true, Collections.emptyList() ); + return RpcResultBuilder. success().build(); } } ); } @@ -113,11 +120,9 @@ public class KitchenServiceImpl implements KitchenService, KitchenServiceRuntime if( toasterOutOfBread ) { log.info( "We're out of toast but we can make eggs" ); - return Futures.immediateFuture( Rpcs. getRpcResult( true, - Arrays.asList( RpcErrors.getRpcError( "", "partial-operation", null, - ErrorSeverity.WARNING, - "Toaster is out of bread but we can make you eggs", - ErrorType.APPLICATION, null ) ) ) ); + return Futures.immediateFuture( RpcResultBuilder. success() + .withWarning( ErrorType.APPLICATION, "partial-operation", + "Toaster is out of bread but we can make you eggs" ).build() ); } // Access the ToasterService to make the toast.