Java Reference
In-Depth Information
1
If the framework isn't in the
Bundle.STARTING
state, the
init()
method is
invoked.
2
The framework sets its beginning start level to the configured value, which
causes all reloaded bundles to be started in accordance with their activation
policy and start level.
3
The framework's state is set to
Bundle.ACTIVE
.
4
A framework event of type
FrameworkEvent.STARTED
is fired.
You may wonder why the
init()
method is necessary and why all the steps aren't per-
formed in the
start()
method. In some cases, you may want to interact with the
framework instance before restarting cached bundles, but some interactions can only
happen via the framework's
BundleContext
object. Because bundles (including the
framework) don't have a
BundleContext
object until they've been started,
init()
is
necessary to transition the framework to the
Bundle.STARTING
state so you can
acquire its context with
Bundle.getBundleContext()
.
To summarize, in the normal case, call
start()
. But if you want to perform some
actions before all the cached bundles restart, call
init()
first to do what you need to
do followed by a call to
start()
. When the framework is active, subsequent calls to
init()
and
start()
have no effect.
Next, we'll look at how you shut down a running framework.
13.1.5
Stopping a framework instance
As you may guess, stopping an active framework involves invoking the
stop()
method inherited from the
Bundle
interface. This method asynchronously stops the
framework on another thread, so the method returns immediately to the caller. If
you want to know when the framework has finished shutting down, call
Framework.
waitForStop()
after calling
stop()
, which blocks the calling thread until shutdown
is complete.
The following steps are performed when you stop a framework:
The framework's state is set to
Bundle.STOPPING
.
1
All installed bundles are stopped without changing each bundle's persistent
activation state and according to start levels.
2
The framework's start level is set to 0.
3
Framework event handling is disabled.
4
The framework's state is set to
Bundle.RESOLVED
.
5
All resources held by the framework are released.
6
All threads waiting on
Framework.waitForStop()
are awakened.
7
NOTE
Calling
waitForStop()
doesn't start the framework shutdown process,
it waits for it to occur. If you want to stop the framework, you must call
stop()
on it first.