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
10 * http://www.apache.org/licenses/LICENSE-2.0
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
16 * ============LICENSE_END==========================================================================
17 ******************************************************************************/
18 package org.onap.ccsdk.features.sdnr.wt.odlux;
20 import java.util.ArrayList;
21 import java.util.Comparator;
22 import java.util.Iterator;
23 import java.util.List;
24 import java.util.concurrent.ConcurrentSkipListSet;
25 import org.onap.ccsdk.features.sdnr.wt.odlux.model.bundles.OdluxBundle;
26 import org.onap.ccsdk.features.sdnr.wt.odlux.model.bundles.OdluxBundleLoader;
27 import org.onap.ccsdk.features.sdnr.wt.odlux.model.bundles.OdluxBundleResourceAccess;
28 import org.slf4j.Logger;
29 import org.slf4j.LoggerFactory;
31 public class OdluxBundleLoaderImpl implements OdluxBundleLoader {
33 private final static Logger LOG = LoggerFactory.getLogger(OdluxBundleLoaderImpl.class);
35 private static OdluxBundleLoaderImpl singleton = null;
38 // private List<OdluxBundle> bundles;
39 private ConcurrentSkipListSet<OdluxBundle> bundles2;
40 private Comparator<OdluxBundle> sortorderbundlecomparator;
42 public OdluxBundleLoaderImpl() {
43 if (singleton != null) {
44 LOG.error("Multiple intializations of singleton");
47 sortorderbundlecomparator = (arg0, arg1) -> {
48 int diff = arg0.getIndex() - arg1.getIndex();
49 return diff > 0 ? 1 : diff < 0 ? -1 : 0;
51 bundles2 = new ConcurrentSkipListSet<>(sortorderbundlecomparator);
57 public static OdluxBundleLoaderImpl getInstance() {
58 if (singleton == null) {
59 LOG.warn("Test initialization order");
60 new OdluxBundleLoaderImpl();
66 public int getNumberOfBundles() {
68 return this.bundles2.size();
73 public void addBundle(OdluxBundle bundle) {
74 LOG.debug("odlux bundle " + bundle.getBundleName() + " added");
75 this.bundles2.add(bundle);
81 public void removeBundle(OdluxBundle bundle) {
82 this.bundles2.remove(bundle);
83 LOG.debug("odlux bundle " + bundle.getBundleName() + " removed");
87 private Comparator<OdluxBundle> getBundleSorter() {
88 return this.sortorderbundlecomparator;
92 public List<String> getLoadedBundles(String myBundleName) {
93 List<String> list = new ArrayList<>();
94 for (OdluxBundle b : bundles2) {
95 list.add(b.getBundleName());
97 list.add(myBundleName);
101 private List<String> getBundleNames(String myBundleName) {
102 final List<String> names = new ArrayList<>();
103 for (OdluxBundle b : bundles2) {
104 names.add(b.getBundleName());
106 names.add(myBundleName);
110 public String getResource(String fn, OdluxBundleResourceAccess indexBundle) {
111 String fileContent = null;
113 if (indexBundle.hasResource(fn)) {
114 fileContent = indexBundle.getResourceFileContent(fn, getBundleNames(indexBundle.getBundleName()));
116 LOG.debug("not found in framework res. try to find in applications");
117 final Iterator<OdluxBundle> it = bundles2.iterator();
118 while (it.hasNext()) {
119 OdluxBundle b = it.next();
120 if (b.hasResource(fn)) {
121 LOG.debug("found res in " + b.getBundleName());
122 fileContent = b.getResourceFileContent(fn);