Java Reference
In-Depth Information
export
javax.servlet
version="2.4.0"
Servlet
A P I
import
javax.servlet
version="2.4.0"
Web
application
?
Tomcat
Figure 2.17 How does the framework
choose between multiple exporters of
a package?
export
javax.servlet
version="2.5.0"
When the framework tries to resolve the dependencies of the web application, it sees
that the web application requires javax.servlet with a minimum version of 2.4.0 and
both the servlet API and Tomcat bundles meet this requirement. Because the web
application can be wired to only one version of the package, how does the framework
choose between the candidates? As you may intuitively expect, the framework favors
the highest matching version, so in this case it selects Tomcat to resolve the web appli-
cation's dependency. Sounds simple enough. What happens if both bundles export
the same version, say 2.4.0?
In this case, the framework chooses between candidates based on the order in
which they're installed in the framework. Bundles installed earlier are given priority
over bundles installed later; as we mentioned, the next chapter will show you what it
means to install a bundle in the framework. If you assume the servlet API was installed
before Tomcat, the servlet API will be selected to resolve the web application's depen-
dency. The framework makes one more consideration when prioritizing matching
candidates: maximizing collaboration.
So far, you've been working under the assumption that you start the resolve pro-
cess on a cleanly installed set of bundles. But the OSG i framework allows bundles to
be dynamically installed at any time during execution. In other words, the framework
doesn't always start from a clean slate. It's possible for some bundles to be installed,
resolved, and already in use when new bundles are installed. This creates another
means to differentiate among exporters: already-resolved exporters and not-yet-
resolved exporters. The framework gives priority to already-resolved exporters, so if it
must choose between two matching candidates where one is resolved and one isn't, it
chooses the resolved candidate. Consider again the example with the servlet
API exporting version 2.4.0 of the javax.servlet package and Tomcat exporting ver-
sion 2.5.0. If the servlet API is already resolved, the framework will choose it to resolve
the web application's dependency, even though it isn't exporting the highest version,
as shown in figure 2.18. Why?
It has to do with maximizing the potential for collaboration. Bundles can only col-
laborate if they're using the same version of a shared package. When resolving, the
Search WWH ::




Custom Search