Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Given the above bundle activator, it is not now possible to embed Felix into a host application and interact with it as the following snippet illustrates:

Code Block
public class HostApplication
{
    private HostActivator m_activator = null;
    private Felix m_felix = null;

    public HostApplication()
    {
        Map configMap = new StringMap(false);
        configMap.put(Constants.FRAMEWORK_SYSTEMPACKAGES,
            "org.osgi.framework; version=1.3.0," +
            "org.osgi.service.packageadmin; version=1.2.0," +
            "org.osgi.service.startlevel; version=1.0.0," +
            "org.osgi.service.url; version=1.0.0");
        configMap.put(BundleCache.CACHE_PROFILE_DIR_PROP, "cache");

        try
        {
            // Now create an instance of the framework.
            m_felix = new Felix();

            // Create host activator;
            m_activator = new HostActivator();

            // Now start Felix instance with our config properties
            // and activator.
            m_felix.start(
                new MutablePropertyResolverImpl(configMap),
                m_activator);
        }
        catch (Exception ex)
        {
            System.err.println("Could not create framework: " + ex);
            ex.printStackTrace();
        }
    }

    public Bundle[] getInstalledBundles()
    {
        // Use the system bundle activator to gain external
        // access to the set of installed bundles.
        return m_activator.getContext().getBundles();
    }
}

Notice how the HostApplication.getInstalledBundles() method uses its activator instance to get access to the System Bundle's context in order to interact with the embedded Felix framework instance. This approach provides the foundation for all interaction between the host application and the embedded framework instance.

Anchor
host-services
host-services

...