9b9e96c15675a047c8483d97b320244d46667e2b
[ccsdk/features.git] /
1 /*
2  * ============LICENSE_START========================================================================
3  * ONAP : ccsdk feature sdnr wt
4  * =================================================================================================
5  * Copyright (C) 2020 highstreet technologies GmbH Intellectual Property. All rights reserved.
6  * =================================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
8  * in compliance with the License. You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software distributed under the License
13  * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
14  * or implied. See the License for the specific language governing permissions and limitations under
15  * the License.
16  * ============LICENSE_END==========================================================================
17  */
18 package org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.impl.access.binding;
19
20 import java.util.Objects;
21 import java.util.Optional;
22 import org.eclipse.jdt.annotation.NonNull;
23 import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.NetconfBindingAccessor;
24 import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.TransactionUtils;
25 import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.impl.access.NetconfAccessorImpl;
26 import org.opendaylight.mdsal.binding.api.DataBroker;
27 import org.opendaylight.mdsal.binding.api.MountPoint;
28 import org.opendaylight.mdsal.binding.api.NotificationService;
29 import org.opendaylight.yangtools.concepts.ListenerRegistration;
30 import org.opendaylight.yangtools.yang.binding.NotificationListener;
31 import org.slf4j.Logger;
32 import org.slf4j.LoggerFactory;
33
34 public abstract class NetconfBindingAccessorImpl extends NetconfAccessorImpl implements NetconfBindingAccessor {
35
36     private static final Logger log = LoggerFactory.getLogger(NetconfBindingAccessorImpl.class);
37
38     private final static GenericTransactionUtils GENERICTRANSACTIONUTILS = new GenericTransactionUtils();
39
40     private final DataBroker dataBroker;
41     private final MountPoint mountpoint;
42
43     /**
44      * Contains all data to access and manage netconf device
45      *
46      * @param nodeId of managed netconf node
47      * @param netconfNode information
48      * @param dataBroker to access node
49      * @param mountpoint of netconfNode
50      */
51     public NetconfBindingAccessorImpl(NetconfAccessorImpl accessor, DataBroker dataBroker, MountPoint mountpoint) {
52         super(accessor);
53         this.dataBroker = Objects.requireNonNull(dataBroker);
54         this.mountpoint = Objects.requireNonNull(mountpoint);
55     }
56
57     @Override
58     public DataBroker getDataBroker() {
59         return dataBroker;
60     }
61
62     @Override
63     public MountPoint getMountpoint() {
64         return mountpoint;
65     }
66
67     @Override
68     public TransactionUtils getTransactionUtils() {
69         return GENERICTRANSACTIONUTILS;
70     }
71
72     @Override
73     public @NonNull <T extends NotificationListener> ListenerRegistration<NotificationListener> doRegisterNotificationListener(
74             @NonNull T listener) {
75         log.info("Begin register listener for Mountpoint {}", mountpoint.getIdentifier().toString());
76         final Optional<NotificationService> optionalNotificationService =
77                 mountpoint.getService(NotificationService.class);
78         final NotificationService notificationService = optionalNotificationService.get();
79         final ListenerRegistration<NotificationListener> ranListenerRegistration =
80                 notificationService.registerNotificationListener(listener);
81         log.info("End registration listener for Mountpoint {} Listener: {} Result: {}",
82                 mountpoint.getIdentifier().toString(), optionalNotificationService, ranListenerRegistration);
83         return ranListenerRegistration;
84     }
85 }