Use constructor injection in OSGiClusterAdmin
[controller.git] / opendaylight / md-sal / sal-cluster-admin-impl / src / main / java / org / opendaylight / controller / cluster / datastore / admin / OSGiClusterAdmin.java
1 /*
2  * Copyright (c) 2020 PANTHEON.tech, s.r.o. 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.cluster.datastore.admin;
9
10 import org.opendaylight.controller.cluster.datastore.DistributedDataStoreInterface;
11 import org.opendaylight.controller.eos.akka.DataCenterControl;
12 import org.opendaylight.mdsal.binding.api.RpcProviderService;
13 import org.opendaylight.mdsal.binding.dom.codec.api.BindingNormalizedNodeSerializer;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.cluster.admin.rev151013.ClusterAdminService;
15 import org.opendaylight.yangtools.concepts.Registration;
16 import org.osgi.service.component.annotations.Activate;
17 import org.osgi.service.component.annotations.Component;
18 import org.osgi.service.component.annotations.Deactivate;
19 import org.osgi.service.component.annotations.Reference;
20 import org.slf4j.Logger;
21 import org.slf4j.LoggerFactory;
22
23 @Component(service = { })
24 public final class OSGiClusterAdmin {
25     private static final Logger LOG = LoggerFactory.getLogger(OSGiClusterAdmin.class);
26
27     private final Registration reg;
28
29     @Activate
30     public OSGiClusterAdmin(
31             @Reference(target = "(type=distributed-config)") final DistributedDataStoreInterface configDatastore,
32             @Reference(target = "(type=distributed-operational)") final DistributedDataStoreInterface operDatastore,
33             @Reference final BindingNormalizedNodeSerializer serializer,
34             @Reference final RpcProviderService rpcProviderService,
35             @Reference final DataCenterControl dataCenterControls,
36             @Reference final DataCenterControl dataCenterControl) {
37         reg = rpcProviderService.registerRpcImplementation(ClusterAdminService.class,
38             new ClusterAdminRpcService(configDatastore, operDatastore, serializer, dataCenterControl));
39         LOG.info("Cluster Admin services started");
40     }
41
42     @Deactivate
43     void deactivate() {
44         reg.close();
45         LOG.info("Cluster Admin services stopped");
46     }
47 }