Fix TAPI Sonar issues
[transportpce.git] / tapi / src / main / java / org / opendaylight / transportpce / tapi / impl / TapiProvider.java
1 /*
2  * Copyright © 2018 Orange, 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.transportpce.tapi.impl;
9
10 import org.eclipse.jdt.annotation.NonNull;
11 import org.opendaylight.mdsal.binding.api.DataBroker;
12 import org.opendaylight.mdsal.binding.api.DataTreeIdentifier;
13 import org.opendaylight.mdsal.binding.api.RpcProviderService;
14 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
15 import org.opendaylight.transportpce.servicehandler.service.ServiceHandlerOperations;
16 import org.opendaylight.transportpce.tapi.topology.TapiTopologyImpl;
17 import org.opendaylight.transportpce.tapi.utils.TapiListener;
18 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.connectivity.rev181210.TapiConnectivityService;
19 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.TapiTopologyService;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.tapi.rev180928.ServiceInterfacePoints;
21 import org.opendaylight.yangtools.concepts.ObjectRegistration;
22 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
23 import org.slf4j.Logger;
24 import org.slf4j.LoggerFactory;
25
26 /**
27  * Class to register TAPI interface Service and Notification.
28  *
29  * @author Gilles Thouenon (gilles.thouenon@orange.com) on behalf of Orange
30  *
31  */
32 public class TapiProvider {
33
34     private static final Logger LOG = LoggerFactory.getLogger(TapiProvider.class);
35
36     private final DataBroker dataBroker;
37     private final RpcProviderService rpcProviderService;
38     private ObjectRegistration<TapiConnectivityService> rpcRegistration;
39     private final ServiceHandlerOperations serviceHandler;
40     private final TapiListener tapiListener;
41
42     public TapiProvider(DataBroker dataBroker, RpcProviderService rpcProviderService,
43             ServiceHandlerOperations serviceHanlder, TapiListener tapiListener) {
44         this.dataBroker = dataBroker;
45         this.rpcProviderService = rpcProviderService;
46         this.serviceHandler = serviceHanlder;
47         this.tapiListener = tapiListener;
48     }
49
50     /**
51      * Method called when the blueprint container is created.
52      */
53     public void init() {
54         LOG.info("TapiProvider Session Initiated");
55         TapiImpl tapi = new TapiImpl(this.serviceHandler);
56         TapiTopologyImpl topo = new TapiTopologyImpl(this.dataBroker);
57         rpcRegistration = rpcProviderService.registerRpcImplementation(TapiConnectivityService.class, tapi);
58         rpcProviderService.registerRpcImplementation(TapiTopologyService.class, topo);
59         @NonNull
60         InstanceIdentifier<ServiceInterfacePoints> sipIID = InstanceIdentifier.create(ServiceInterfacePoints.class);
61         dataBroker.registerDataTreeChangeListener(DataTreeIdentifier.create(
62             LogicalDatastoreType.CONFIGURATION, sipIID), tapiListener);
63     }
64
65     /**
66      * Method called when the blueprint container is destroyed.
67      */
68     public void close() {
69         LOG.info("TapiProvider Session Closed");
70         rpcRegistration.close();
71     }
72
73 }