|
OSGi™ Service Platform Release 2 |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | 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.util.Dictionary |
getHeaders()
Returns this bundle's Manifest headers and values. |
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. |
boolean |
hasPermission(java.lang.Object permission)
Determines if this bundle has the specified permissions. |
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.BUNDLE_NATIVECODE
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
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
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.
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.
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.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.
|
OSGi™ Service Platform Release 2 |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |