Register global PurchaseCarProvider
[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 static java.util.Objects.requireNonNull;
11
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;
25
26 public class PurchaseCarProvider implements CarPurchaseService, AutoCloseable {
27     private static final Logger LOG = LoggerFactory.getLogger(PurchaseCarProvider.class);
28
29     private final NotificationPublishService notificationProvider;
30
31     public PurchaseCarProvider(final NotificationPublishService notificationProvider) {
32         this.notificationProvider = requireNonNull(notificationProvider);
33     }
34
35     @Override
36     public ListenableFuture<RpcResult<BuyCarOutput>> buyCar(final BuyCarInput input) {
37         LOG.info("Routed RPC buyCar : generating notification for buying car [{}]", input);
38
39         return Futures.transform(notificationProvider.offerNotification(new CarBoughtBuilder()
40             .setCarId(input.getCarId())
41             .setPersonId(input.getPersonId())
42             .build()),
43             result -> RpcResultBuilder.success(new BuyCarOutputBuilder().build()).build(),
44             MoreExecutors.directExecutor());
45     }
46
47     @Override
48     public void close() {
49
50     }
51 }