2 * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.controller.clustering.it.provider;
10 import static java.util.Objects.requireNonNull;
12 import com.google.common.util.concurrent.Futures;
13 import com.google.common.util.concurrent.ListenableFuture;
14 import com.google.common.util.concurrent.MoreExecutors;
15 import org.opendaylight.mdsal.binding.api.NotificationPublishService;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.config.sal.clustering.it.car.purchase.rev140818.BuyCarInput;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.config.sal.clustering.it.car.purchase.rev140818.BuyCarOutput;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.config.sal.clustering.it.car.purchase.rev140818.BuyCarOutputBuilder;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.config.sal.clustering.it.car.purchase.rev140818.CarBoughtBuilder;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.config.sal.clustering.it.car.purchase.rev140818.CarPurchaseService;
21 import org.opendaylight.yangtools.yang.common.RpcResult;
22 import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
23 import org.slf4j.Logger;
24 import org.slf4j.LoggerFactory;
26 public class PurchaseCarProvider implements CarPurchaseService, AutoCloseable {
27 private static final Logger LOG = LoggerFactory.getLogger(PurchaseCarProvider.class);
29 private final NotificationPublishService notificationProvider;
31 public PurchaseCarProvider(final NotificationPublishService notificationProvider) {
32 this.notificationProvider = requireNonNull(notificationProvider);
36 public ListenableFuture<RpcResult<BuyCarOutput>> buyCar(final BuyCarInput input) {
37 LOG.info("Routed RPC buyCar : generating notification for buying car [{}]", input);
39 return Futures.transform(notificationProvider.offerNotification(new CarBoughtBuilder()
40 .setCarId(input.getCarId())
41 .setPersonId(input.getPersonId())
43 result -> RpcResultBuilder.success(new BuyCarOutputBuilder().build()).build(),
44 MoreExecutors.directExecutor());