9fad324779d67ad940de94578c722ed315efdf2e
[ccsdk/features.git] /
1 /*
2  * ============LICENSE_START========================================================================
3  * ONAP : ccsdk feature sdnr wt
4  * =================================================================================================
5  * Copyright (C) 2019 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;
19
20 import java.util.Objects;
21 import java.util.concurrent.ConcurrentHashMap;
22 import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.NetconfAccessor;
23 import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.TransactionUtils;
24 import org.opendaylight.mdsal.binding.api.DataBroker;
25 import org.opendaylight.mdsal.binding.api.MountPoint;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.NetconfNode;
27 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
28 import org.slf4j.Logger;
29 import org.slf4j.LoggerFactory;
30
31 public class NetconfAccessorManager {
32
33     private static final Logger log = LoggerFactory.getLogger(NetconfNodeStateServiceImpl.class);
34
35     private static final TransactionUtils TRANSACTIONUTILS = new GenericTransactionUtils();
36     private final ConcurrentHashMap<String, NetconfAccessorImpl> accessorList;
37
38     public NetconfAccessorManager() {
39         accessorList = new ConcurrentHashMap<>();
40     }
41
42     public NetconfAccessor getAccessor(NodeId nNodeId, NetconfNode netconfNode, DataBroker netconfNodeDataBroker,
43             MountPoint mountPoint) {
44         NetconfAccessorImpl res =
45                 new NetconfAccessorImpl(nNodeId, netconfNode, netconfNodeDataBroker, mountPoint, TRANSACTIONUTILS);
46         NetconfAccessor previouse = accessorList.put(nNodeId.getValue(), res);
47         if (Objects.nonNull(previouse)) {
48             log.warn("Accessor with name already available. Replaced with new one.");
49         }
50         return res;
51     }
52
53     public boolean containes(NodeId nNodeId) {
54         return accessorList.containsKey(nNodeId.getValue());
55     }
56
57     public void removeAccessor(NodeId nNodeId) {
58         accessorList.remove(nNodeId.getValue());
59     }
60 }