Java Reference
In-Depth Information
desktop icons. For modular development approaches, such as servlets, Java EE , and Net-
Beans, each has its own specific mechanism of handling the lifecycle of its components.
This leads us to the question of why you need lifecycle management at all.
3.1.2
Why lifecycle management?
Cast your mind back to the earlier discussion about why you should modularize your
application code into separate bundles. We talked about the benefits of separating dif-
ferent concerns into bundles and avoiding tight coupling among them. The OSG i
module layer provides the necessary means to do this at the class level, but it doesn't
address when a particular set of classes or objects is needed in an application.
An explicit lifecycle API lets the providing application take care of how to config-
ure, initialize, and maintain a piece of code that's installed so it can decide how it
should operate at execution time. For example, if a database driver is in use, should it
start any threads or initialize any cache tables to improve performance? If it does any
of these things, when are these resources released? Do they exist for the lifetime of the
application as a whole? And if not, how are they removed? Because the OSG i specifica-
tion provides an explicit lifecycle API , you can take any bundle providing the function-
ality you need and let it worry about how to manage its internal functions. In essence,
it's a matter of compose versus control .
Because you can architect your application such that parts of it may come and go
at any point in time, the application's flexibility is greatly increased. You can easily
manage installation, update, and removal of an application and its required modules.
You can configure or tailor applications to suit specific needs, breaking the mono-
lithic approach of standard development approaches. Instead of “you get what you
get,” wouldn't it be great if you could offer “you get what you need”?
Another great benefit of the standard lifecycle API is that it allows for a diverse set
of management applications that can manage your application. There's no magic
going on; lifecycle management can be done completely using the provided API .
We hope this discussion has piqued your interest. Now, let's focus specifically on
defining the OSG i bundle lifecycle and the management API associated with it.
3.2
OSGi bundle lifecycle
The OSG i lifecycle layer is how you use the bundles; it's where the rubber meets the
road. The module metadata from chapter 2 is all well and good, but creating bundles
in and of itself is useful only if you use them. You need to interact with the OSG i lifecy-
cle layer in order to use the bundles. Unlike the module layer, which relies on meta-
data, the lifecycle layer relies on API s. Because introducing API s can be a boring
endeavor (Javadoc, anyone?), we'll move in a top-down fashion and use an example to
show what the lifecycle layer API allows you to do.
It's important to note that the OSG i core framework doesn't mandate any particu-
lar mechanism of interacting with the lifecycle API (such as the command line, a GUI ,
or an XML configuration file); the core is purely a Java API . This turns out to be
Search WWH ::




Custom Search