Adjust for Binding RPC codegen changes
[controller.git] / opendaylight / md-sal / samples / clustering-test-app / provider / src / main / java / org / opendaylight / controller / clustering / it / provider / BasicRpcTestProvider.java
1 /*
2  * Copyright (c) 2017 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.Futures;
12 import com.google.common.util.concurrent.ListenableFuture;
13 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker;
14 import org.opendaylight.controller.sal.binding.api.RpcProviderRegistry;
15 import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonService;
16 import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonServiceProvider;
17 import org.opendaylight.mdsal.singleton.common.api.ServiceGroupIdentifier;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.controller.basic.rpc.test.rev160120.BasicGlobalInput;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.controller.basic.rpc.test.rev160120.BasicGlobalOutput;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.controller.basic.rpc.test.rev160120.BasicGlobalOutputBuilder;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.controller.basic.rpc.test.rev160120.BasicRpcTestService;
22 import org.opendaylight.yangtools.yang.common.RpcResult;
23 import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
24 import org.slf4j.Logger;
25 import org.slf4j.LoggerFactory;
26
27 public class BasicRpcTestProvider implements ClusterSingletonService, BasicRpcTestService {
28
29     private static final Logger LOG = LoggerFactory.getLogger(BasicRpcTestProvider.class);
30     private static final ServiceGroupIdentifier IDENTIFIER = ServiceGroupIdentifier.create("Basic-rpc-test");
31
32     private final RpcProviderRegistry rpcProviderRegistry;
33     private final ClusterSingletonServiceProvider singletonService;
34     private BindingAwareBroker.RpcRegistration<BasicRpcTestService> rpcRegistration;
35
36     public BasicRpcTestProvider(final RpcProviderRegistry rpcProviderRegistry,
37                                 final ClusterSingletonServiceProvider singletonService) {
38         this.rpcProviderRegistry = rpcProviderRegistry;
39         this.singletonService = singletonService;
40
41         singletonService.registerClusterSingletonService(this);
42     }
43
44     @Override
45     public void instantiateServiceInstance() {
46         LOG.info("Basic testing rpc registered as global");
47         rpcRegistration = rpcProviderRegistry.addRpcImplementation(BasicRpcTestService.class, this);
48     }
49
50     @Override
51     public ListenableFuture<Void> closeServiceInstance() {
52         rpcRegistration.close();
53         rpcRegistration = null;
54
55         return Futures.immediateFuture(null);
56     }
57
58     @Override
59     public ServiceGroupIdentifier getIdentifier() {
60         return IDENTIFIER;
61     }
62
63     @Override
64     public ListenableFuture<RpcResult<BasicGlobalOutput>> basicGlobal(final BasicGlobalInput input) {
65         LOG.info("Basic test global rpc invoked");
66
67         return Futures.immediateFuture(RpcResultBuilder.success(new BasicGlobalOutputBuilder().build()).build());
68     }
69 }

©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.