Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migrated to Confluence 5.3
Include Page
FELIX:apache-felix-ipojo-headerFELIX:
apache-felix-ipojo-header

...

The objective of this handler is to simplify the development of white-board architecture. This architecture-style is based is very close to the extender architecture style but use relies on services instead of bundles.

Div
classtoc
Table of Contents
maxLevel4
minLevel2

...

...

Info
titleChange in the 1.2.0

The 1.2.0 uses the namespace org.apache.felix.ipojo.whiteboard instead of org.apache.felix.ipojo.white-board-pattern

Info
titleChange in the 1.7.0

The 1.7.0 has introduced a new annotations allowing to declare several whiteboard patterns in the same class. The }}@Whiteboards annotation is not available in previous version.

The whiteboard pattern

A whiteboard is based on two different roles:

...

More information on this pattern is available in this document
Implementing a white board pattern could be complex as the extender needs to track these services dynamically. Indeed looked services can be highly dynamic; they can arrive, leave or be modified at runtime.
Several services specified in the OSGi specification use white board pattern such as the Device Access Manager.

...

Code Block
xml
xml
<ipojo xmlns:wbp="org.apache.felix.ipojo.whiteboard">
     <component 
          className="org.apache.felix.ipojo.test.FooWhiteBoardPattern"
      >
        <wbp:wbp 
   	      filter="(my.property=1)" 
              onArrival="onArrival" 
              onDeparture="onDeparture" 
              onModification="onModification"
         />
       
         <provides/>
      </component>

Notice that, this handler is an external handler. So, it uses the "org.apache.felix.ipojo.whiteboard" namespace.
Once described, you can implement your component. The methods specified methods will be called when a matching services arrives or leaves or are modified. The modification callback is optional. A matching service is detected by confronting the service reference against the specified filter.
The filter can target specific service interface (with the objectclass property) or property values.
In the previous example, these methods could be:

Code Block
public class FooWhiteBoardPattern implements Observable {
    List list = new ArrayList();
    int modifications = 0;    
    public synchronized void onArrival(ServiceReference ref) {
        list.add(ref);
    }    
    public synchronized void onDeparture(ServiceReference ref) {
        list.remove(ref);
    }    
    public synchronized void onModification(ServiceReference ref) {
         modifications = modifications + 1;
    }// ...
    } 

All methods received the arriving, leaving or modified service reference.

You can also use annotation to declare the same component:

Code Block

@Component
@Wbp(
  filter="my.property=1", 
  onArrival="onArrival" 
  onDeparture="onDeparture" 
  onModification="onModification")
public class FooWhiteBoardPattern {
    List list = new ArrayList();

    public synchronized Mapvoid getObservationsonArrival(ServiceReference ref) {
        Map map = new HashMap();list.add(ref);
    }    
    public synchronized void onDeparture(ServiceReference ref) {
        maplist.put("list", listremove(ref);
    }    map.put("modifications", new Integer(modifications));
        return map;
    public synchronized void onModification(ServiceReference ref) {
	   //...
    }

...

Configuration

The handler has only three mandatory attributes:

...

The onModification attribute is optional.The filter attribute allows setting the service filter.

In the 1.7.0, a new annotation was introduced to support the declaration of several whiteboard patterns in the same component:

Code Block

@Component
@Whiteboards(whiteboards={
     @Wbp(filter="(foo=true)", 
        onArrival="onArrival", 
        onDeparture="onDeparture",
        onModification="onModification"),
     @Wbp(filter="(bar=true)", 
        onArrival="onArrival2", 
        onDeparture="onDeparture2")}
)
public class WhiteBoardExemple {
    
    // ...

}
Code Block

Download

The handler is available on the download page.
Sources are available on the Felix trunk at the following location: http://svn.apache.org/repos/asf/felix/trunk/ipojo/handler/whiteboard.

Include Page
FELIX:apache-felix-ipojo-footerFELIX:
apache-felix-ipojo-footer