|
OSGi Service Platform Release 3 |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
An installed bundle in the Framework.
A Bundle object is the access point to define the life cycle of an installed bundle. Each bundle installed in the OSGi environment will have an associated Bundle object.
A bundle will have a unique identity, a long, chosen by the Framework. This identity will not change during the life cycle of a bundle, even when the bundle is updated. Uninstalling and then reinstalling the bundle will create a new unique identity.
A bundle can be in one of six states:
Values assigned to these states have no specified ordering; they represent bit values that may be ORed together to determine if a bundle is in one of the valid states.
A bundle should only execute code when its state is one of STARTING, ACTIVE, or STOPPING. An UNINSTALLED bundle can not be set to another state; it is a zombie and can only be reached because invalid references are kept somewhere.
The Framework is the only entity that is allowed to create Bundle objects, and these objects are only valid within the Framework that created them.
Field Summary | |
---|---|
static int |
ACTIVE
This bundle is now running. |
static int |
INSTALLED
This bundle is installed but not yet resolved. |
static int |
RESOLVED
This bundle is resolved and is able to be started. |
static int |
STARTING
This bundle is in the process of starting. |
static int |
STOPPING
This bundle is in the process of stopping. |
static int |
UNINSTALLED
This bundle is uninstalled and may not be used. |
Method Summary | |
---|---|
long |
getBundleId()
Returns this bundle's identifier. |
java.net.URL |
getEntry(java.lang.String name)
Returns a URL to the specified entry in this bundle. |
java.util.Enumeration |
getEntryPaths(java.lang.String path)
Returns enumeration of all the paths to entries within the bundle whose longest sub-path matches the supplied path argument. |
java.util.Dictionary |
getHeaders()
Returns this bundle's Manifest headers and values. |
java.util.Dictionary |
getHeaders(java.lang.String localeString)
Returns this bundle's Manifest headers and values localized to the specifed locale. |
java.lang.String |
getLocation()
Returns this bundle's location identifier. |
ServiceReference[] |
getRegisteredServices()
Returns this bundle's ServiceReference list for all services it has registered or null if this bundle has no registered services. |
java.net.URL |
getResource(java.lang.String name)
Find the specified resource in this bundle. |
ServiceReference[] |
getServicesInUse()
Returns this bundle's ServiceReference list for all services it is using or returns null if this bundle is not using any services. |
int |
getState()
Returns this bundle's current state. |
java.lang.String |
getSymbolicName()
Returns the symbolic name of this bundle as specified by its Bundle-SymbolicName manifest header. |
boolean |
hasPermission(java.lang.Object permission)
Determines if this bundle has the specified permissions. |
java.lang.Class |
loadClass(java.lang.String name)
Loads the specified class using this bundle’s classloader. |
void |
start()
Starts this bundle. |
void |
stop()
Stops this bundle. |
void |
uninstall()
Uninstalls this bundle. |
void |
update()
Updates this bundle. |
void |
update(java.io.InputStream in)
Updates this bundle from an InputStream. |
Field Detail |
public static final int UNINSTALLED
The UNINSTALLED state is only visible after a bundle is uninstalled; the bundle is in an unusable state and all references to the Bundle object should be released immediately.
The value of UNINSTALLED is 0x00000001.
public static final int INSTALLED
A bundle is in the INSTALLED state when it has been installed in the Framework but cannot run.
This state is visible if the bundle's code dependencies are not resolved. The Framework may attempt to resolve an INSTALLED bundle's code dependencies and move the bundle to the RESOLVED state.
The value of INSTALLED is 0x00000002.
public static final int RESOLVED
A bundle is in the RESOLVED state when the Framework has successfully resolved the bundle's dependencies. These dependencies include:
Constants.BUNDLE_CLASSPATH
Manifest header.
Constants.EXPORT_PACKAGE
and Constants.IMPORT_PACKAGE
Manifest headers.
Note that the bundle is not active yet. A bundle must be put in the RESOLVED state before it can be started. The Framework may attempt to resolve a bundle at any time.
The value of RESOLVED is 0x00000004.
public static final int STARTING
A bundle is in the STARTING state when the start()
method
is active. A bundle will be in this state when the bundle's
BundleActivator.start(org.osgi.framework.BundleContext)
is called. If this method completes
without exception, then the bundle has successfully started and will move to the
ACTIVE state.
The value of STARTING is 0x00000008.
public static final int STOPPING
A bundle is in the STOPPING state when the stop()
method
is active. A bundle will be in this state when the bundle's
BundleActivator.stop(org.osgi.framework.BundleContext)
method is called. When this method completes
the bundle is stopped and will move to the RESOLVED state.
The value of STOPPING is 0x00000010.
public static final int ACTIVE
A bundle is in the ACTIVE state when it has been successfully started.
The value of ACTIVE is 0x00000020.
Method Detail |
public int getState()
A bundle can be in only one state at any time.
public void start() throws BundleException
Otherwise, the following steps are required to start a bundle:
BundleActivator.start(org.osgi.framework.BundleContext)
method of this
bundle's BundleActivator, if one is specified, is called.
If the BundleActivator is invalid or throws an exception, this bundle's state
is set back to RESOLVED.
BundleEvent.STARTED
is broadcast.
BundleException
- If this bundle couldn't 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.java.lang.IllegalStateException
- If this
bundle has been uninstalled or this bundle tries to change its own state.java.lang.SecurityException
- If the caller does not have
the appropriate AdminPermisson, and the Java Runtime Environment
supports permissions.public void stop() throws BundleException
The following steps are required to stop a bundle:
BundleActivator.stop(org.osgi.framework.BundleContext)
method of this
bundle's BundleActivator, if one is specified, is called.
If this method throws an exception, it will continue to stop this bundle.
A BundleException will be thrown after completion of the
remaining steps.
BundleEvent.STOPPED
is broadcast.
BundleException
- If this bundle's
BundleActivator could not be loaded or threw an exception.java.lang.IllegalStateException
- If this
bundle has been uninstalled or this bundle tries to change its own state.java.lang.SecurityException
- If the caller does not have
the appropriate AdminPermission, and the Java Runtime Environment
supports permissions.public void update() throws BundleException
If this bundle's state is ACTIVE, it will be stopped before the update and started after the update successfully completes.
If the bundle being updated has exported any packages, these packages will not be updated. Instead, the previous package version will remain exported until the PackageAdmin.refreshPackages method has been has been called or the Framework is relaunched.
The following steps are required to update a bundle:
Constants.BUNDLE_UPDATELOCATION
Manifest
header (if available) or the bundle's original location.
BundleEvent.UPDATED
is broadcast.
FrameworkEvent.ERROR
is broadcast containing the exception.
BundleException
- If the update fails.java.lang.IllegalStateException
- If this
bundle has been uninstalled or this bundle tries to change its own state.java.lang.SecurityException
- If the caller does not have
the appropriate AdminPermission, and the Java Runtime Environment
supports permissions.stop()
,
start()
public void update(java.io.InputStream in) throws BundleException
This method performs all the steps listed in Bundle.update(), except the bundle will be read from the supplied InputStream, rather than a URL.
This method will always close the InputStream when it is done, even if an exception is thrown.
in
- The InputStream from which to read the new bundle.BundleException
- If the provided stream cannot be read or the update fails.java.lang.IllegalStateException
- If this
bundle has been uninstalled or this bundle tries to change its own state.java.lang.SecurityException
- If the caller does not have
the appropriate AdminPermission, and the Java Runtime Environment
supports permissions.update()
public void uninstall() throws BundleException
This method causes the Framework to notify other bundles that this bundle is being uninstalled, and then puts this bundle into the UNINSTALLED state. The Framework will remove any resources related to this bundle that it is able to remove.
If this bundle has exported any packages, the Framework will continue to make these packages available to their importing bundles until the PackageAdmin.refreshPackages method has been called or the Framework is relaunched.
The following steps are required to uninstall a bundle:
FrameworkEvent.ERROR
is broadcast containing the exception.
BundleEvent.UNINSTALLED
is broadcast.
BundleException
- If the uninstall failed.
This can occur if another thread is attempting to change the bundle's state
and does not complete in a timely manner.java.lang.IllegalStateException
- If this
bundle has been uninstalled or this bundle tries to change its own state.java.lang.SecurityException
- If the caller does not have
the appropriate AdminPermission, and the Java Runtime Environment
supports permissions.stop()
public java.util.Dictionary getHeaders()
Manifest header names are case-insensitive. The methods of the returned Dictionary object will operate on header names in a case-insensitive manner. If a Manifest header value starts with "%", it will be localized with the localization properties file for the default locale.
For example, the following Manifest headers and values are included if they are present in the Manifest file:
Bundle-Name Bundle-Vendor Bundle-Version Bundle-Description Bundle-DocURL Bundle-ContactAddress
This method will continue to return Manifest header information while this bundle is in the UNINSTALLED state.
java.lang.SecurityException
- If the caller does not have
the AdminPermission, and the Java Runtime Environment supports permissions.Constants.BUNDLE_LOCALIZATION
public long getBundleId()
A bundle's unique identifier has the following attributes:
This method will continue to return this bundle's unique identifier while this bundle is in the UNINSTALLED state.
public java.lang.String getLocation()
The bundle location identifier is the location passed to
BundleContext.installBundle(java.lang.String)
when a bundle is installed.
This method will continue to return this bundle's location identifier while this bundle is in the UNINSTALLED state.
java.lang.SecurityException
- If the caller does not have
the appropriate AdminPermission, and the Java Runtime Environment
supports permissions.public ServiceReference[] getRegisteredServices()
If the Java runtime supports permissions, a ServiceReference object to a service is included in the returned list only if the caller has the ServicePermission to get the service using at least one of the named classes the service was registered under.
The list is valid at the time of the call to this method, however, as the Framework is a very dynamic environment, services can be modified or unregistered at anytime.
java.lang.IllegalStateException
- If this bundle has been uninstalled.ServiceRegistration
,
ServiceReference
,
ServicePermission
public ServiceReference[] getServicesInUse()
If the Java Runtime Environment supports permissions, a ServiceReference object to a service is included in the returned list only if the caller has the ServicePermission to get the service using at least one of the named classes the service was registered under.
The list is valid at the time of the call to this method, however, as the Framework is a very dynamic environment, services can be modified or unregistered at anytime.
java.lang.IllegalStateException
- If this bundle has been uninstalled.ServiceReference
,
ServicePermission
public boolean hasPermission(java.lang.Object permission)
If the Java Runtime Environment does not support permissions, this method always returns true.
permission is of type Object to avoid referencing the java.security.Permission class directly. This is to allow the Framework to be implemented in Java environments which do not support permissions.
If the Java Runtime Environment does support permissions, this bundle and all its resources including nested JAR files, belong to the same java.security.ProtectionDomain; that is, they will share the same set of permissions.
permission
- The permission to verify.java.lang.IllegalStateException
- If this bundle has been uninstalled.public java.net.URL getResource(java.lang.String name)
name
- The name of the resource.
See java.lang.ClassLoader.getResource for a description of
the format of a resource name.java.lang.IllegalStateException
- If this bundle has been uninstalled.public java.util.Dictionary getHeaders(java.lang.String localeString)
This method performs the same function as Bundle.getHeaders() except the manifest header values are localized to the specified locale. If a Manifest header value starts with "%", it will be localized with the localization properties file for the specified locale. If null is specified as the locale string, the header values will be localized using the default locale. If the empty string ("") is specified as the locale string, the header values will not be localized but any leading "%"s will be stripped off of the header values.
This method will continue to return Manifest header information while this bundle is in the UNINSTALLED state, however the header values will only be localized to the default locale.
java.lang.SecurityException
- If the caller does not have
the AdminPermission, and the Java Runtime Environment supports permissions.getHeaders()
,
Constants.BUNDLE_LOCALIZATION
public java.lang.String getSymbolicName()
This method will continue to return this bundle's symbolic name while this bundle is in the UNINSTALLED state.
public java.lang.Class loadClass(java.lang.String name) throws java.lang.ClassNotFoundException
If this bundle's state is INSTALLED, this method will attempt to resolve the bundle before attempting to load the class.
If the bundle cannot be resolved, a
Framework event of type FrameworkEvent.ERROR
is
broadcast containing a BundleException with
details of the reason the bundle could not be resolved.
This method must then throw a ClassNotFoundException.
If this bundle's state is UNINSTALLED, then an IllegalStateException is thrown.
name
- The name of the class to load.java.lang.ClassNotFoundException
- If no such class can be found or
if the caller does not have the AdminPermission, and the Java
Runtime Environment supports permissions.java.lang.IllegalStateException
- If this bundle has been uninstalled.public java.util.Enumeration getEntryPaths(java.lang.String path)
Returned paths indicating subdirectory paths end with a "/". The returned paths are all relative to the root of the bundle and have a leading "/".
This method returns an empty enumeration if no entries could be found that match the specified path or if the caller does not have AdminPermission and the Java Runtime Environment supports permissions.
path
- the path name to get the entry path names for.java.lang.IllegalStateException
- If this bundle has been uninstalled.public java.net.URL getEntry(java.lang.String name)
This method returns a URL to the specified entry, or null if the entry could not be found or if the caller does not have the AdminPermission and the Java Runtime Environment supports permissions.
name
- The name of the entry.
See java.lang.ClassLoader.getResource for a description of
the format of a resource name.java.lang.IllegalStateException
- If this bundle has been uninstalled.
|
OSGi Service Platform Release 3 |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |