Bump MRI versions
[controller.git] / opendaylight / md-sal / samples / clustering-test-app / provider / src / main / java / org / opendaylight / controller / clustering / it / provider / PurchaseCarProvider.java
1 /*
2  * Copyright (c) 2014 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.controller.clustering.it.provider;
9
10 import com.google.common.util.concurrent.Futures;
11 import com.google.common.util.concurrent.ListenableFuture;
12 import com.google.common.util.concurrent.MoreExecutors;
13 import org.opendaylight.mdsal.binding.api.NotificationPublishService;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.config.sal.clustering.it.car.purchase.rev140818.BuyCarInput;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.config.sal.clustering.it.car.purchase.rev140818.BuyCarOutput;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.config.sal.clustering.it.car.purchase.rev140818.BuyCarOutputBuilder;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.config.sal.clustering.it.car.purchase.rev140818.CarBoughtBuilder;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.config.sal.clustering.it.car.purchase.rev140818.CarPurchaseService;
19 import org.opendaylight.yangtools.yang.common.RpcResult;
20 import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
21 import org.slf4j.Logger;
22 import org.slf4j.LoggerFactory;
23
24 public class PurchaseCarProvider implements CarPurchaseService, AutoCloseable {
25
26     private static final Logger LOG = LoggerFactory.getLogger(PurchaseCarProvider.class);
27
28     private NotificationPublishService notificationProvider;
29
30
31     public void setNotificationProvider(final NotificationPublishService salService) {
32         this.notificationProvider = salService;
33     }
34
35
36     @Override
37     public ListenableFuture<RpcResult<BuyCarOutput>> buyCar(final BuyCarInput input) {
38         LOG.info("Routed RPC buyCar : generating notification for buying car [{}]", input);
39
40         return Futures.transform(notificationProvider.offerNotification(new CarBoughtBuilder()
41             .setCarId(input.getCarId())
42             .setPersonId(input.getPersonId())
43             .build()),
44             result -> RpcResultBuilder.success(new BuyCarOutputBuilder().build()).build(),
45             MoreExecutors.directExecutor());
46     }
47
48     @Override
49     public void close() {
50     }
51 }