Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Services are more commonly used and they should normally be your first choice unless you have a compelling reason to design a new extender.</p> <p>OSGi is a service-oriented platform. A service API forms a contract between two parties, a consumer and a provider. The contract is defined in terms of a Java package containing interfaces, and the provider provides it by implementing those interfaces. The consumer uses the service registry to find instances of an interface it wants to use.</p> <p>The extender pattern is somewhat more flexible and abstract, but more complicated to understand and use. Essentially, an extender bundle provides additional functionality <em>on behalf of</em> some other bundle(s), which normally opt in by containing some kind of declaration.</p> <p>For example, suppose you want to implement a Help System for your application. Bundles could simply contain an HTML document under some agreed path, and the central Help System bundle could scan bundles to find these docs and add them to the main Help Index. Doing this with services would be quite cumbersome: assuming you follow the "whiteboard" style you would have to define a <code>HelpProvider</code> Java interface with a <code>getHelpDocuments()</code> method; every bundle wishing to provide help would have to implement this interface and register it as a service. On the other hand, the Help System extender bundle needs to be relatively smart because it has to track bundles coming and going. But at least you only have to write this smart code once.</p> <p>Real-life examples of extenders are as follows:</p> <ul> <li>Declarative Services is an extender that looks for the <code>Service-Component</code> declaration in other bundles and does all kinds of stuff on their behalf – instantiating components, publishing services etc.</li> <li>Blueprint is an extender that does something similar. It looks for the <code>Bundle-Blueprint</code> declaration, or XML files under an agreed path.</li> <li>The OSGi enterprise specification defines a JPA extender that looks for bundles containing a <code>persistence.xml</code> file declared by the <code>Meta-Persistence</code> header. When it finds one it creates a Persistence Unit for that bundle.</li> <li>Eclipse contains an extender (confusingly called the Extension Registry) for creating things like Views, Perspectives, Menus etc. These are all declared in a <code>plugin.xml</code> file in the root of a bundle.</li> </ul> <p>To summarise... services are used for registering and finding objects based on a contract. Extenders are for extending the functionality of bundles, usually based on some kind of declarative resource or header rather than executable code.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload