public interface OsgiFramework
This is an abstraction of the OSGi framework that hides the actual implementation details. If you need access to
this interface, simply inject it into your Application. In most cases, however, you are better of injecting a
BundleInstaller
since that provides common convenience methods.
Modifier and Type | Method and Description |
---|---|
org.osgi.framework.BundleContext |
bundleContext()
Returns the BundleContext of this framework's system bundle.
|
List<org.osgi.framework.Bundle> |
bundles()
Returns an iterable collection of all installed bundles.
|
List<org.osgi.framework.Bundle> |
installBundle(String bundleLocation)
Installs a bundle from the specified location.
|
void |
refreshPackages()
This method synchronously refreshes all bundles currently loaded.
|
void |
start()
This method starts the framework instance.
|
void |
startBundles(List<org.osgi.framework.Bundle> bundles,
boolean privileged)
Starts the given
Bundle s. |
void |
stop()
This method synchronously shuts down the framework.
|
List<org.osgi.framework.Bundle> installBundle(String bundleLocation) throws org.osgi.framework.BundleException
Installs a bundle from the specified location. The specified location identifier will be used as the identity
of the bundle. If a bundle containing the same location identifier is already installed, the Bundle
object for that bundle is returned. All bundles listed in the OsgiHeader.PREINSTALL_BUNDLE
manifest
header are also installed. The bundle at index 0 of the returned list matches the bundleLocation
argument.
NOTE: When this method installs more than one bundle, AND one of those bundles throw an
exception during installation, the bundles installed prior to throwing the expcetion will remain installed. To
enable the caller to recover from such a situation, this method wraps any thrown exception within a BundleInstallationException
that contains the list of successfully installed bundles.
It would be preferable if this method was exception-safe (that it would roll-back all installed bundles in the case of an exception), but that can not be implemented thread-safely since an Application may choose to install bundles concurrently through any available BundleContext.
bundleLocation
- The location identifier of the bundle to install.BundleInstallationException
- If the input stream cannot be read, or the installation of a bundle failed,
or the caller does not have the appropriate permissions, or the system BundleContext
is no longer valid.org.osgi.framework.BundleException
void startBundles(List<org.osgi.framework.Bundle> bundles, boolean privileged) throws org.osgi.framework.BundleException
Starts the given Bundle
s. The parameter privileged tells the framework whether or not
privileges are available, and is checked against the OsgiHeader.PRIVILEGED_ACTIVATOR
header of each
Bundle being started. Any bundle that is a fragment is silently ignored.
bundles
- The bundles to start.privileged
- Whether or not privileges are available.org.osgi.framework.BundleException
- If a bundle could not be started. This could be because a code dependency could not
be resolved or the specified BundleActivator could not be loaded or threw an
exception.SecurityException
- If the caller does not have the appropriate permissions.IllegalStateException
- If this bundle has been uninstalled or this bundle tries to change its own state.void refreshPackages()
This method synchronously refreshes all bundles currently loaded. Once this method returns, the class loaders of all bundles will reflect on the current set of loaded bundles.
org.osgi.framework.BundleContext bundleContext()
Returns the BundleContext of this framework's system bundle. The returned BundleContext can be used by the caller to act on behalf of this bundle. This method may return null if it has no valid BundleContext.
SecurityException
- If the caller does not have the appropriate permissions.List<org.osgi.framework.Bundle> bundles()
Returns an iterable collection of all installed bundles. This method returns a list of all bundles installed in the OSGi environment at the time of the call to this method. However, since the OsgiFramework is a very dynamic environment, bundles can be installed or uninstalled at anytime.
void start() throws org.osgi.framework.BundleException
This method starts the framework instance. Before this method is called, any call to installBundle(String)
or bundles()
will generate a NullPointerException
.
org.osgi.framework.BundleException
- If any error occurs.void stop() throws org.osgi.framework.BundleException
This method synchronously shuts down the framework. It must be called at the end of a session in order to shutdown all active bundles.
org.osgi.framework.BundleException
- If any error occurs.Copyright © 2018. All rights reserved.