All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.apache.aries.util.tracker.BundleTrackerFactory Maven / Gradle / Ivy

There is a newer version: 2024.11.18751.20241128T090041Z-241100
Show newest version
/**
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */
package org.apache.aries.util.tracker;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.concurrent.ConcurrentHashMap;

import org.osgi.framework.Version;
import org.osgi.util.tracker.BundleTracker;

/**
 * This is the factory for BundleTracker
 */
public class BundleTrackerFactory {
    private static ConcurrentHashMap> btMap = new ConcurrentHashMap>();

    /**
     * get bundle tracker based on bundle name and version
     * 
     * @param bundleScope
     *            composite bundle's - SymbolicName_Version
     * @return the list of bundle tracker associated with the bundle scope
     */
    public static List getBundleTrackerList(String bundleScope) {
        return (List) btMap.get(bundleScope);
    }

    /**
     * get bundle tracker based on composite bundle's symbolicName and version
     * 
     * @param symbolicName
     *            composite bundle's symbolicName
     * @param version
     *            composite bundle's version
     * @return the list of bundle tracker associated with the bundle scope
     */
    public static List getBundleTrackerList(String symbolicName,
            Version version) {
        return (List) btMap.get(symbolicName + "_"
                + version.toString());
    }

    /**
     * get all bundle tracker registered in this factory
     * 
     * @return all the trackers registered. The collection contains a List for each bundle scope.
     */
    public static Collection> getAllBundleTracker() {
        return btMap.values();
    }

    /**
     * register the bundle tracker
     * 
     * @param bundleScope
     *            composite bundle's SymbolicName_Version
     * @param bt
     *            the bundle tracker to be registered
     */
    public static void registerBundleTracker(String bundleScope,
            BundleTracker bt) {
        List list = btMap.get(bundleScope);
        if (list == null) {
            list = new ArrayList();
        }
        list.add(bt);
        btMap.putIfAbsent(bundleScope, list);
    }

    /**
     * unregister and close the bundle tracker(s) associated with composite
     * bundle's - SymbolicName_Version
     * 
     * @param bundleScope
     *            composite bundle's - SymbolicName_Version
     */
    public static void unregisterAndCloseBundleTracker(String bundleScope) {
        List list = btMap.get(bundleScope);
        if (list == null) {
            return;
        } else {
            for (BundleTracker bt : list) {
                bt.close();
            }
        }
        btMap.remove(bundleScope);
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy