75b31d406cf522033e67fb73444f1a96958a7b70
[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 java.util.concurrent.Future;
14 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker;
15 import org.opendaylight.controller.sal.binding.api.RpcProviderRegistry;
16 import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonService;
17 import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonServiceProvider;
18 import org.opendaylight.mdsal.singleton.common.api.ServiceGroupIdentifier;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.controller.basic.rpc.test.rev160120.BasicRpcTestService;
20 import org.opendaylight.yangtools.yang.common.RpcResult;
21 import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
22 import org.slf4j.Logger;
23 import org.slf4j.LoggerFactory;
24
25 public class BasicRpcTestProvider implements ClusterSingletonService, BasicRpcTestService {
26
27     private static final Logger LOG = LoggerFactory.getLogger(BasicRpcTestProvider.class);
28     private static final ServiceGroupIdentifier IDENTIFIER = ServiceGroupIdentifier.create("Basic-rpc-test");
29
30     private final RpcProviderRegistry rpcProviderRegistry;
31     private final ClusterSingletonServiceProvider singletonService;
32     private BindingAwareBroker.RpcRegistration<BasicRpcTestService> rpcRegistration;
33
34     public BasicRpcTestProvider(final RpcProviderRegistry rpcProviderRegistry,
35                                 final ClusterSingletonServiceProvider singletonService) {
36         this.rpcProviderRegistry = rpcProviderRegistry;
37         this.singletonService = singletonService;
38
39         singletonService.registerClusterSingletonService(this);
40     }
41
42     @Override
43     public void instantiateServiceInstance() {
44         LOG.info("Basic testing rpc registered as global");
45         rpcRegistration = rpcProviderRegistry.addRpcImplementation(BasicRpcTestService.class, this);
46     }
47
48     @Override
49     public ListenableFuture<Void> closeServiceInstance() {
50         rpcRegistration.close();
51         rpcRegistration = null;
52
53         return Futures.immediateFuture(null);
54     }
55
56     @Override
57     public ServiceGroupIdentifier getIdentifier() {
58         return IDENTIFIER;
59     }
60
61     @Override
62     public Future<RpcResult<Void>> basicGlobal() {
63         LOG.info("Basic test global rpc invoked");
64
65         return Futures.immediateFuture(RpcResultBuilder.<Void>success().build());
66     }
67 }

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