Java Reference
In-Depth Information
satisfied and will create any Blueprint components contained in the bundle. This
results in components being injected with service proxies, which may or may not have
backing services available. For those components without backing services for manda-
tory dependencies, the Blueprint container won't publish their provided services.
This is similar to the case where required services depart at execution time, which
means that if any threads try to use them, those threads are blocked.
ACTIVATION CALLBACKS
In listing 12.2, you saw that the Blueprint
XML
declaration allows you to define call-
back methods that are invoked by the Blueprint container to initialize and destroy
beans when they're enabled and disabled, respectively. In the paint frame component,
you use these callbacks to control when the component is visible, as shown next.
Listing 12.3 Callback methods used in the
PaintFrame
application
public void activate()
{
SwingUtils.invokeAndWait(new Runnable() {
public void run() {
setVisible(true);
}
});
}
public void deactivate()
{
SwingUtils.invokeLater(new Runnable() {
public void run() {
setVisible(false);
dispose();
}
});
}
You still have an issue regarding precisely when your component—in this case, the
paint frame—is created. We'll deal with that next.
LAZY VS. EAGER INITIALIZATION
As with Declarative Services, Blueprint components are lazy by default, which means
components aren't created in advance to delay class loading until a published service
is requested by another bundle. If you need your component to be created eagerly,
you can request this behavior from the container. You declare Blueprint managers as
eager or lazy using the
activation
attribute on the associated
XML
element with a
Boolean argument. For example:
<bean id="foo" class="Foo" activation="eager" />
<reference id="bar" interface="Bar" activation="lazy" />
<service id="baz" interface="Baz" activation="lazy" />
The laziness of a component is also impacted by how it provides its services. If the
auto-
export
attribute from section 12.1.2 is used, the Blueprint container must activate the
underlying component to perform class loading to calculate the service interfaces.