ebd5b2e9943b2f4ca28ce0c22d2871ef73fa8c0a
[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
9 package org.opendaylight.controller.clustering.it.provider;
10
11 import com.google.common.util.concurrent.SettableFuture;
12 import java.util.concurrent.Future;
13 import org.opendaylight.controller.sal.binding.api.NotificationProviderService;
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.CarBoughtBuilder;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.config.sal.clustering.it.car.purchase.rev140818.CarPurchaseService;
17 import org.opendaylight.yangtools.yang.common.RpcResult;
18 import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
19 import org.slf4j.Logger;
20 import org.slf4j.LoggerFactory;
21
22 public class PurchaseCarProvider implements CarPurchaseService, AutoCloseable {
23
24     private static final Logger LOG = LoggerFactory.getLogger(PurchaseCarProvider.class);
25
26     private NotificationProviderService notificationProvider;
27
28
29     public void setNotificationProvider(final NotificationProviderService salService) {
30         this.notificationProvider = salService;
31     }
32
33
34     @Override
35     public Future<RpcResult<Void>> buyCar(BuyCarInput input) {
36         LOG.info("Routed RPC buyCar : generating notification for buying car [{}]", input);
37         final SettableFuture<RpcResult<Void>> futureResult = SettableFuture.create();
38         CarBoughtBuilder carBoughtBuilder = new CarBoughtBuilder();
39         carBoughtBuilder.setCarId(input.getCarId());
40         carBoughtBuilder.setPersonId(input.getPersonId());
41         notificationProvider.publish(carBoughtBuilder.build());
42         futureResult.set(RpcResultBuilder.<Void>success().build());
43         return futureResult;
44     }
45
46     @Override
47     public void close() {
48     }
49 }

©2013 OpenDaylight, A Linux Foundation Collaborative Project. All Rights Reserved.
OpenDaylight is a registered trademark of The OpenDaylight Project, Inc.
Linux Foundation and OpenDaylight are registered trademarks of the Linux Foundation.
Linux is a registered trademark of Linus Torvalds.