Java Reference
In-Depth Information
Finally, you use the <service> element to publish the paint frame bean as a service
in the OSG i service registry. Recall that you can't register classes as services in Blue-
print; you must use an interface. As a result, you must define a new interface class to
provide the java.awt.Window methods you need to use in the window-listener compo-
nent. You define this new interface as
public interface Window {
void addWindowListener(WindowListener listener);
void removeWindowListener(WindowListener listener);
}
The addShape() and removeShape() methods for the paint frame component look
basically the same as the Declarative Services example, but with one minor difference.
Here's the addShape() method:
public void addShape(SimpleShape shape, Map attrs) {
final DefaultShape delegate = new DefaultShape(shape);
final String name = (String) attrs.get(SimpleShape.NAME_PROPERTY);
final Icon icon = (Icon) attrs.get(SimpleShape.ICON_PROPERTY);
m_shapes.put(name, delegate);
SwingUtils.invokeAndWait(new Runnable() {
public void run() {
//...
}
});
}
You're given the Icon object directly versus having to look it up from the shape's class
loader, as is required for Declarative Services.
You've now seen how to define a component, how to publish services, and how to
consume services. The next area of the Blueprint specification we'll explore is the
component lifecycle.
12.1.4
Blueprint component lifecycle
Similar to Declarative Services, Blueprint is responsible for managing the lifecycles of
its components. Blueprint also supports lifecycle callbacks, eager/lazy component
activation, and access to the execution-time container environment. Additionally,
Blueprint introduces some new concepts, such as service damping and grace periods.
We'll look into each of these topics in more detail, starting with general Blueprint
component lifecycle management.
COMPONENT LIFECYCLE MANAGEMENT
Similar to Declarative Services, a Blueprint component's lifecycle is controlled over-
all by its containing bundle's lifecycle. For individual beans, their lifecycle is tied to
the state of their service dependencies. All mandatory service dependencies must be
satisfied for a bean to become enabled. When a bean is enabled, any service manag-
ers associated with it can register their associated service interfaces in the OSG i ser-
vice registry.
Search WWH ::




Custom Search