Fixup checkstyle
[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 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 javax.annotation.PreDestroy;
13 import javax.inject.Inject;
14 import javax.inject.Singleton;
15 import org.opendaylight.mdsal.binding.api.RpcProviderService;
16 import org.opendaylight.mdsal.singleton.api.ClusterSingletonService;
17 import org.opendaylight.mdsal.singleton.api.ClusterSingletonServiceProvider;
18 import org.opendaylight.mdsal.singleton.api.ServiceGroupIdentifier;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.controller.basic.rpc.test.rev160120.BasicGlobal;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.controller.basic.rpc.test.rev160120.BasicGlobalOutputBuilder;
21 import org.opendaylight.yangtools.concepts.Registration;
22 import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
23 import org.osgi.service.component.annotations.Activate;
24 import org.osgi.service.component.annotations.Component;
25 import org.osgi.service.component.annotations.Deactivate;
26 import org.osgi.service.component.annotations.Reference;
27 import org.slf4j.Logger;
28 import org.slf4j.LoggerFactory;
29
30 @Singleton
31 @Component(service = { })
32 public final class BasicRpcTestProvider implements ClusterSingletonService {
33     private static final Logger LOG = LoggerFactory.getLogger(BasicRpcTestProvider.class);
34     private static final ServiceGroupIdentifier IDENTIFIER = new ServiceGroupIdentifier("Basic-rpc-test");
35
36     private final RpcProviderService rpcProviderRegistry;
37     private final Registration singletonRegistration;
38
39     private Registration rpcRegistration = null;
40
41     @Inject
42     @Activate
43     public BasicRpcTestProvider(@Reference final RpcProviderService rpcProviderRegistry,
44                                 @Reference final ClusterSingletonServiceProvider singletonService) {
45         this.rpcProviderRegistry = rpcProviderRegistry;
46         singletonRegistration = singletonService.registerClusterSingletonService(this);
47     }
48
49     @PreDestroy
50     @Deactivate
51     public void close() {
52         singletonRegistration.close();
53     }
54
55     @Override
56     public void instantiateServiceInstance() {
57         LOG.info("Basic testing rpc registered as global");
58         rpcRegistration = rpcProviderRegistry.registerRpcImplementation((BasicGlobal) input -> {
59             LOG.info("Basic test global rpc invoked");
60             return RpcResultBuilder.success(new BasicGlobalOutputBuilder().build()).buildFuture();
61         });
62     }
63
64     @Override
65     public ListenableFuture<Void> closeServiceInstance() {
66         rpcRegistration.close();
67         rpcRegistration = null;
68
69         return Futures.immediateFuture(null);
70     }
71
72     @Override
73     public ServiceGroupIdentifier getIdentifier() {
74         return IDENTIFIER;
75     }
76 }