Java Reference
In-Depth Information
<entry>
<key type="java.lang.String">Bananas</key>
<value type="java.lang.Double">1.39</value>
</entry>
Blueprint also allows you to define your own type converters, turning String values
from the XML into arbitrary Objects , but because the default Blueprint type con-
verter works in so many situations, it's unlikely you'll ever need to write your own.
SPECIAL PROPERTIES
In chapter 3, you saw how special <jpa:context> elements could be used to inject
JPA persistence contexts. Blueprint also has a number of other predefined proper-
ties that can be used to get hold of special objects. For example, in the following
example, the blueprintBundleContext reference is a precanned reference to the
bundle's BundleContext :
<bean class="SomeClass">
<property name="context" ref="blueprintBundleContext"/>
</bean>
(If you followed our advice about always using Blueprint instead of old-style OSG i, you
shouldn't ever need to get hold of a bundle context. But there are exceptions to every
rule!)
6.3.3
Understanding bean scopes
Blueprint beans may have one of two scopes: singleton or prototype. If you're keen, you
can also write your own custom scopes. The scope determines the lifespan and visibil-
ity of the beans.
THE SINGLETON SCOPE
When the singleton scope is used, a single instance of the bean is created. As figure 6.2
shows, the exact same instance is used every time the bean is required, even if it's already
in use. The singleton scope requires—but doesn't enforce—that beans are stateless and
thread safe. There's only one instance created, regardless of the number of requests, so
it's an extremely scalable model.
A
B
C
Singleton
D
F
Figure 6.2 When the singleton scope is
used for a bean, every consumer of the
bean is wired to the same instance.
E
Search WWH ::




Custom Search