2 * Copyright (c) 2017 Cisco Systems, Inc. and others. All rights reserved.
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
8 package org.opendaylight.controller.clustering.it.provider;
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;
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");
36 private final RpcProviderService rpcProviderRegistry;
37 private final Registration singletonRegistration;
39 private Registration rpcRegistration = null;
43 public BasicRpcTestProvider(@Reference final RpcProviderService rpcProviderRegistry,
44 @Reference final ClusterSingletonServiceProvider singletonService) {
45 this.rpcProviderRegistry = rpcProviderRegistry;
46 singletonRegistration = singletonService.registerClusterSingletonService(this);
52 singletonRegistration.close();
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();
65 public ListenableFuture<Void> closeServiceInstance() {
66 rpcRegistration.close();
67 rpcRegistration = null;
69 return Futures.immediateFuture(null);
73 public ServiceGroupIdentifier getIdentifier() {