Java Reference
In-Depth Information
Reference listener != service dependency
One important point to note is that for a Blueprint container to treat a bean as depen-
dent on a service reference, the bean must be bound to the service via an injection
mechanism—either a property or a constructor argument. A reference-listener call-
back is not treated as an injection mechanism. So, even though a bean receives a
callback when the service appears and disappears, it won't necessarily stop provid-
ing its services unless it has the property or argument injection relationship as well.
For Declarative Services, you learned that if a mandatory service dependency is bro-
ken, the component instance immediately becomes invalid. Blueprint handles this dif-
ferently via the concepts of damping and grace periods.
SERVICE DAMPING
As we previously mentioned, Blueprint injects proxies into components instead of the
actual service objects. These proxies are the mechanism Blueprint uses to provide
service-dynamism damping; said a different way, it uses this approach to hide service
dynamism from the component.
When a mandatory service is removed from the service registry, the Blueprint con-
tainer first stops providing any services offered by the impacted component. Addition-
ally, any attempts by the component to use the proxy associated with the missing
service block the calling thread. Blueprint proxies block for a configurable amount of
time (five minutes by default). If the timeout expires and no new service is found to
replace the missing service, the proxy throws a ServiceUnavailableException . Client
code should therefore be coded defensively to gracefully deal with execution-time
exceptions, but this is true in general and not just in Blueprint.
The benefit of this approach is it eliminates service unpublish/publish waves rip-
pling throughout the framework during bundle updates. But if you're unaware, it can
lead to unexpected lockups in your application, which is particularly interesting in
GUI scenarios.
To configure the timeout behavior, you specify the timeout attribute on a service
reference. This value specifies the number of milliseconds to wait until the service
reappears. The timeout value must be equal to or greater than zero, where a timeout
of zero signifies an indefinite wait. In the window-listener component, you can see this
in action:
<reference id="window" interface="org.foo.windowlistener.api.Window"
timeout="1">
Damping isn't the only mechanism Blueprint employs to hide service dynamism;
another one is grace periods.
GRACE PERIODS
Normally, a Blueprint component container doesn't enable its component until the
component's mandatory service dependencies are satisfied. The grace period is a period
Search WWH ::




Custom Search