Java Reference
In-Depth Information
You define a default, no-argument constructor for the component class; Declarative
Services component classes must define such a constructor. You define an activate()
callback method to be invoked by the Declarative Services framework when the com-
ponent is activated, along with a corresponding deactivate() callback method to be
called when the component is deactivated.
Declarative Services callback methods
The names of callback methods ( activate() and deactivate() ) are defaults. If you
wish to use a different pattern or are migrating legacy code, you can define the names
of these callback methods via attributes on the <component> XML element. For ex-
ample, the following code snippet redefines the activation and deactivation methods
to be start() and stop() , respectively:
<component name="org.foo.example"
activate="start"
deactivate="stop">
The activation and deactivation methods are optional, so if your component has no
need to track its activation state, you can leave them out. Also, if you use the default
activate() and deactivate() method names, there's no need to define these in
the component declaration because the Declarative Services framework will discover
them automatically.
Although it isn't shown in the example, there's also a callback method for the modi-
fied component lifecycle stage. Unlike the activation and deactivation methods, this
lifecycle callback has no default method name, so you must define the method name
in the <component> element, as follows:
<component name="org.foo.example" modified="modified">
This indicates that the component is interested in being notified about configuration
updates and specifies the name of the callback method.
You may be wondering about the Map passed into the activate() method, which you
use to configure the size of the component. The Declarative Services lifecycle callback
methods accept a number of different argument types to give the component addi-
tional information, which we'll describe next.
LIFECYCLE CALLBACK METHOD SIGNATURES
The lifecycle callback methods follow the same method-accessibility rules laid out ear-
lier for binding methods. They may also accept zero or more of the following argu-
ment types (ordering isn't important):
ComponentContext —Receives the component context for the component con-
figuration
BundleContext —Receives the bundle context of the component's bundle
Map —Receives an unmodifiable map containing the component's properties
 
Search WWH ::




Custom Search