Java Reference
In-Depth Information
(continued)
Recall from chapter 5 that we discussed bundle fragments. With fragments, it's pos-
sible to define different component configurations by installing different fragments
into the OSGi framework, where the host bundle is the base component bundle. In
real-world scenarios, you can use this approach to specify entirely new object graphs
or service relationships. This is potentially powerful but also very low level because
it relies on intimate knowledge of the components being extended in this fashion.
Thus you should use this feature with care.
We've covered the basics of providing services with Blueprint; next, let's look at how
you consume them.
Bar
12.1.3
Consuming services with Blueprint
Blueprint tries to simplify dealing with
the dynamic nature of OSG i services by
using a proxy approach, instead of bind-
ing components directly to an OSG i ser-
vice. The injected proxy is backed by
actual service objects from the service
registry, as shown in figure 12.1.
Service proxies are injected into
Blueprint components using either the
reference or reference-list manager.
Let's look into both.
Foo
BarImpl1
Barlmpl
Foolmpl
Blueprint
proxy
Bar
Bar 1..1
Barlmpl
BarImpl2
Figure 12.1 Blueprint injects a proxy object, which
masks changes in the OSGi service registry. If the
underlying service provider goes away and returns,
the client code is insulated from this dynamism.
BLUEPRINT REFERENCES A, B, C'S
The easiest way to demonstrate service reference behavior is with a simple example of
injecting a service A into a client B . The following code defines the service interface:
public interface A {
void doit();
}
And here's the simple client:
public class B {
private A a;
public void setService(A a) { this.a = a }
public void someAction() { a.doit(); }
}
In this example, you have a class B that depends on a service A , which will be injected
via a setService() method. In Blueprint, you can express this dependency as
<reference id="a" interface="A"/>
<bean id="b" class="B">
<property name="service" ref="a"/>
</bean>
 
Search WWH ::




Custom Search