felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From conflue...@apache.org
Subject [CONF] Apache Felix > Apache Felix Service Component Runtime
Date Mon, 17 Oct 2011 10:04:00 GMT
<html>
<head>
    <base href="https://cwiki.apache.org/confluence">
            <link rel="stylesheet" href="/confluence/s/2042/9/1/_/styles/combined.css?spaceKey=FELIX&amp;forWysiwyg=true"
type="text/css">
    </head>
<body style="background: white;" bgcolor="white" class="email-body">
<div id="pageContent">
<div id="notificationFormat">
<div class="wiki-content">
<div class="email">
    <h2><a href="https://cwiki.apache.org/confluence/display/FELIX/Apache+Felix+Service+Component+Runtime">Apache
Felix Service Component Runtime</a></h2>
    <h4>Page <b>edited</b> by             <a href="https://cwiki.apache.org/confluence/display/~fmeschbe">Felix
Meschberger</a>
    </h4>
        <br/>
                         <h4>Changes (1)</h4>
                                 
    
<div id="page-diffs">
                    <table class="diff" cellpadding="0" cellspacing="0">
    
            <tr><td class="diff-snipped" >...<br></td></tr>
            <tr><td class="diff-unchanged" >| {{ds.factory.enabled}} | {{false}}
| Enables Component Factory functionality not compliant with the Declarative Services 1.1
specification if set to {{true}}. Only set this if you really know you need this. See the
_Non-Standard Component Factory Behaviour_ section below for more details. | <br>| {{ds.ctworkaround}}
| {{false}} | Enables workaround functionality to pass the OSGi CT. Generally this property
should not be set to {{true}} because it enables behaviour which is not compliant with the
Declarative Services 1.1 specification. See [FELIX-2526|https://issues.apache.org/jira/browse/FELIX-2526]
for details. | <br></td></tr>
            <tr><td class="diff-added-lines" style="background-color: #dfd;">|
{{ds.delayed.keepInstances}} | {{false}} | Whether or not to keep instances of delayed components
once they are not referred to any more. The Declarative Services specifications suggests that
instances of delayed components are disposed off if there is not used any longer. Setting
this flag causes the components to not be disposed off and thus prevent them from being constantly
recreated if often used. Examples of such components may be EventHandler services. The default
is to dispose off unused components. See [FELIX-3039|https://issues.apache.org/jira/browse/FELIX-3039]
for details. | <br></td></tr>
            <tr><td class="diff-unchanged" > <br>This configuration mechanism
is implemented in the [ScrConfiguration|http://svn.apache.org/repos/asf/felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/config/ScrConfiguration.java]
and its helper classes. <br></td></tr>
            <tr><td class="diff-snipped" >...<br></td></tr>
    
            </table>
    </div>                            <h4>Full Content</h4>
                    <div class="notificationGreySide">
        <div>[ <a href='#ApacheFelixServiceComponentRuntime-Example'>Example</a>
] [ <a href='#ApacheFelixServiceComponentRuntime-Component'>Component</a> ] [
<a href='#ApacheFelixServiceComponentRuntime-Declaration'>Declaration</a> ] [
<a href='#ApacheFelixServiceComponentRuntime-Activation'>Activation</a> ] [ <a
href='#ApacheFelixServiceComponentRuntime-ServiceBinding'>Service Binding</a> ] [
<a href='#ApacheFelixServiceComponentRuntime-LookinguptheService'>Looking up the Service</a>
] [ <a href='#ApacheFelixServiceComponentRuntime-ReceivingtheService'>Receiving the
Service</a> ] [ <a href='#ApacheFelixServiceComponentRuntime-MavenSCRPlugin'>Maven
SCR Plugin</a> ] [ <a href='#ApacheFelixServiceComponentRuntime-Configuration'>Configuration</a>
] [ <a href='#ApacheFelixServiceComponentRuntime-NonStandardComponentFactoryBehaviour'>Non-Standard
Component Factory Behaviour</a> ] [ <a href='#ApacheFelixServiceComponentRuntime-Administration'>Administration</a>
] [ <a href='#ApacheFelixServiceComponentRuntime-ShellCommand'>Shell Command</a>
] [ <a href='#ApacheFelixServiceComponentRuntime-APIUse'>API Use</a> ] [ <a
href='#ApacheFelixServiceComponentRuntime-Summary'>Summary</a> ]</div>

<p>The Apache Felix Service Component Runtime described by the OSGi Declarative Services
Specification is implemented by the <tt>org.apache.felix.scr</tt> bundle. As specified,
the components must be declared in XML-formatted descriptor files which in turn must be listed
in the <tt>Service-Component</tt> header of the declaring bundle.</p>

<p>The component declarations are read when the declaring bundle is started and the
respective components are verified and activated depending on their declaration.</p>

<p>The Apache Felix Declarative Services implementation with the OSGi Declarative Services
Specification Version 1.1  passes the OSGi CT.</p>

<h2><a name="ApacheFelixServiceComponentRuntime-Example"></a>Example</h2>

<p>To help you get a head start, here is an example of using Declarative Services. You
will find more examples in the <tt>trunk/examples</tt> folder of the Apache Felix
Project.</p>

<h2><a name="ApacheFelixServiceComponentRuntime-Component"></a>Component</h2>

<p>First of all the component must be implemented in a simple Java class. The Declarative
Services Specification basically places no restrictions on the contents of this class. If
you make use of advanced functionality such as providing an <tt>activate()</tt>
or <tt>deactivate()</tt> method or using service loopup by <em>event strategy</em>
(see 112.3.1 Accessing Services) you will of course have to provide the respective methods.</p>

<p>For the sake of example, lets define a very simple class, which implements a <tt>java.util.Comparator</tt>
service:</p>

<div class="code panel" style="border-width: 1px;"><div class="codeHeader panelHeader"
style="border-bottom-width: 1px;"><b>sample/SampleComparator.java</b></div><div
class="codeContent panelContent">
<pre class="code-java">
<span class="code-keyword">package</span> sample;
<span class="code-keyword">import</span> java.util.Comparator;
<span class="code-keyword">public</span> class SampleComparator <span class="code-keyword">implements</span>
Comparator
{
    <span class="code-keyword">public</span> <span class="code-object">int</span>
compare( <span class="code-object">Object</span> o1, <span class="code-object">Object</span>
o2 )
    {
        <span class="code-comment">// TODO: calculate the result
</span>        <span class="code-keyword">return</span> o1.equals( o2 )
? 0 : -1;
    }
}
</pre>
</div></div>

<p>This is of course a very simple and not very intelligently implemented comparator...</p>

<h2><a name="ApacheFelixServiceComponentRuntime-Declaration"></a>Declaration</h2>

<p>The next step consists of writing the declaration. I usually put these files in the
<tt>OSGI-INF</tt> folder of the bundle, but the files may be placed anywhere within
the bundle or any of the bundle's fragments as long as its path is listed in the <tt>Service-Component</tt>
bundle manifest header.</p>

<p>So here we go with the file:</p>

<div class="code panel" style="border-width: 1px;"><div class="codeHeader panelHeader"
style="border-bottom-width: 1px;"><b>OSGI-INF/sample.xml</b></div><div
class="codeContent panelContent">
<pre class="code-java">
&lt;?xml version=<span class="code-quote">"1.0"</span> encoding=<span class="code-quote">"UTF-8"</span>?&gt;
&lt;component name=<span class="code-quote">"sample.component"</span> immediate=<span
class="code-quote">"<span class="code-keyword">true</span>"</span>&gt;
  &lt;implementation class=<span class="code-quote">"sample.SampleComparator"</span>
/&gt;
  &lt;property name=<span class="code-quote">"service.description"</span>
value=<span class="code-quote">"Sample Comparator Service"</span> /&gt;
  &lt;property name=<span class="code-quote">"service.vendor"</span> value=<span
class="code-quote">"Apache Software Foundation"</span> /&gt;
  &lt;service&gt;
    &lt;provide <span class="code-keyword">interface</span>=<span class="code-quote">"java.util.Comparator"</span>
/&gt;
  &lt;/service&gt;
&lt;/component&gt;
</pre>
</div></div>

<p>There are some noteworthy settings in this descriptor already:</p>

<ul>
	<li><b>name</b> - Uniquely identifies this component and is also used to
retrieve optional configuration from the Configuration Admin Service (if available).</li>
	<li><b>immediate</b> - Defines whether the component is to be instantiated
immediately (<tt>true</tt>) or on-demand (<tt>false</tt>).</li>
	<li><b>implementation.class</b> - The fully qualified name of the class
implementing the component. This class must be public and have a public default constructor
for it to be usable by the Service Component Runtime. This class is not required to be exported
and may as well be private to the bundle. In fact, you will generally not export the component
implementation class.</li>
	<li><b>property</b> - These elements define configuration properties to
the component. These properties are available through the <tt>ComponentContext</tt>
which is presented to the component in the <tt>activate</tt> method (see below).</li>
	<li><b>service</b> - If the component is to be registered as a service,
the service names are listed in <b>provide</b> elements inside the <b>service</b>
element. These names will generally be interfaces and must be visible to other bundles for
the service to be usable. In this sample, the service is the Java <tt>java.util.Comparator</tt>
class, which is always visible.</li>
</ul>


<p>To finalize this declaration, add the following header to the bundle manifest:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
Service-Component: OSGI-INF/sample.xml
</pre>
</div></div>

<h2><a name="ApacheFelixServiceComponentRuntime-Activation"></a>Activation</h2>

<p>It may well be that the component needs to be notified, when it is activated and
deactivated. For this, the component may implement an <tt>activate</tt> method
and a <tt>deactivate</tt> method. Both methods must be <tt>public</tt>
or <tt>protected</tt> and take a single argument, the <tt>org.osgi.service.ComponentContext</tt>.
It is recommended for this method to the <tt>protected</tt> as it is only used
by the Service Component Runtime and should of course not be part of the public API of the
component.</p>

<p>Here is the initial class extended with activation and deactivation methods:</p>

<div class="code panel" style="border-width: 1px;"><div class="codeHeader panelHeader"
style="border-bottom-width: 1px;"><b>sample/SampleComparator.java</b></div><div
class="codeContent panelContent">
<pre class="code-java">
<span class="code-keyword">package</span> sample;
<span class="code-keyword">import</span> java.util.Comparator;
<span class="code-keyword">import</span> org.osgi.service.component.ComponentContext;
<span class="code-keyword">public</span> class SampleComparator <span class="code-keyword">implements</span>
Comparator
{
    <span class="code-keyword">public</span> <span class="code-object">int</span>
compare( <span class="code-object">Object</span> o1, <span class="code-object">Object</span>
o2 )
    {
        <span class="code-comment">// TODO: calculate the result
</span>        <span class="code-keyword">return</span> o1.equals( o2 )
? 0 : -1;
    }

    <span class="code-keyword">protected</span> void activate(ComponentContext
context)
    {
        <span class="code-comment">// TODO: Do something on activation
</span>    }
    
    <span class="code-keyword">protected</span> void deactivate(ComponentContext
context)
    {
        <span class="code-comment">// TODO: Do something on deactivation
</span>    }
}
</pre>
</div></div>

<p>Nothing more needs to be done as the Service Component Runtime automatically recognizes
and calls these methods.</p>

<h2><a name="ApacheFelixServiceComponentRuntime-ServiceBinding"></a>Service
Binding</h2>

<p>The next step would probably be to do some service binding. This is somewhat more
overhead, as the referred to services must be declared. On the other hand, you do not have
to care to listen for these services. As examples of these strategies we will first use the
lookup strategy to access an OSGi <tt>HttpService</tt> and then we will use the
event strategy to access an OSGi <tt>LogService</tt> (I personally prefer the
event strategy, but your mileage may vary).</p>

<h3><a name="ApacheFelixServiceComponentRuntime-LookinguptheService"></a>Looking
up the Service</h3>

<p>To use the service, the reference must be declared in the service declaration in
an <b>reference</b> element. Here is the respective declaration for a log service
to lookup:</p>

<div class="code panel" style="border-width: 1px;"><div class="codeHeader panelHeader"
style="border-bottom-width: 1px;"><b>LogService Reference</b></div><div
class="codeContent panelContent">
<pre class="code-java">
&lt;component...&gt;
   ...
    &lt;reference name=<span class="code-quote">"http"</span>
        <span class="code-keyword">interface</span>=<span class="code-quote">"org.osgi.service.http.HttpService"</span>
        cardinality=<span class="code-quote">"1..1"</span> 
        policy=<span class="code-quote">"<span class="code-keyword">static</span>"</span>
    /&gt;
   ...
&lt;/component&gt;
</pre>
</div></div>

<p>To use this service you call the <tt>ComponentContext.getService(String)</tt>
method, for example in the <tt>activate</tt> method:</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
<span class="code-keyword">protected</span> void activate(ComponentContext context)
{
    HttpService http = ( HttpService ) context.locateService( <span class="code-quote">"http"</span>
);
}
</pre>
</div></div>

<h3><a name="ApacheFelixServiceComponentRuntime-ReceivingtheService"></a>Receiving
the Service</h3>

<p>The event strategy works by declaring bind and unbind methods in the component descriptor.
These methods take a single parameter of the type defined in the <b>reference.interface</b>
attribute and must be declared <tt>public</tt> or <tt>protected</tt>.
As with the <tt>activate</tt> and <tt>deactive</tt> it is recommended
for the bind and unbind methods to be declared <tt>protected</tt> as they are
generally not part of the public API of the component.</p>

<p>When using the event strategy, you will want to store the service in a private field
of the component for later use.</p>

<p>First here is the reference declaration:</p>

<div class="code panel" style="border-width: 1px;"><div class="codeHeader panelHeader"
style="border-bottom-width: 1px;"><b>LogService Reference</b></div><div
class="codeContent panelContent">
<pre class="code-java">
&lt;component...&gt;
   ...
   &lt;reference name=<span class="code-quote">"log"</span>
         <span class="code-keyword">interface</span>=<span class="code-quote">"org.osgi.service.log.LogService"</span>
         cardinality=<span class="code-quote">"1..1"</span>
         policy=<span class="code-quote">"<span class="code-keyword">static</span>"</span>
         bind=<span class="code-quote">"bindLog"</span>
         unbind=<span class="code-quote">"unbindLog"</span>
   /&gt;
   ...
&lt;/component&gt;
</pre>
</div></div>

<p>And here is some code:</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
<span class="code-keyword">private</span> LogService log;

<span class="code-keyword">protected</span> void activate(ComponentContext context)
{
    log.log(LogService.LOG_INFO, <span class="code-quote">"Hello Components!"</span>);
}

<span class="code-keyword">protected</span> void bindLog(LogService log)
{
    <span class="code-keyword">this</span>.log = log;
}

<span class="code-keyword">protected</span> void unbindLog(LogService log)
{
    <span class="code-keyword">this</span>.log = <span class="code-keyword">null</span>;
}
</pre>
</div></div>

<p>Note, that you may refer to the <tt>log</tt> field in the <tt>activate</tt>
method as we declared the reference as required. In this case the reference is provided to
the component in the <tt>bind</tt> method before the <tt>activate</tt>
method is called.</p>


<h2><a name="ApacheFelixServiceComponentRuntime-MavenSCRPlugin"></a>Maven
SCR Plugin</h2>

<p>To simplify the tasks of generating the SCR Desriptor and adding the <tt>Service-Component</tt>
header to the bundle manifest, the <a href="/confluence/display/FELIX/Apache+Felix+Maven+SCR+Plugin"
title="Apache Felix Maven SCR Plugin">Apache Felix Maven SCR Plugin</a> may be used.
This helps keeping the descriptor and the code in sync especially during development.</p>


<h2><a name="ApacheFelixServiceComponentRuntime-Configuration"></a>Configuration</h2>

<p>The Apache Felix Declarative Services implementation can be configured with Framework
properties which are read on startup of the implementation bundle and Configuration Admin
Service configuraiton which is provided by the Configuration Admin Service to the service
PID <tt>org.apache.felix.scr.ScrService</tt>.</p>

<p>The following properties are supported:</p>

<div class='table-wrap'>
<table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'> Property </th>
<th class='confluenceTh'> Default Value </th>
<th class='confluenceTh'> Description </th>
</tr>
<tr>
<td class='confluenceTd'> <tt>ds.loglevel</tt> </td>
<td class='confluenceTd'> 1 </td>
<td class='confluenceTd'> Defines a logging level at which messages are logged. This
configuration property is converted to an <tt>int</tt> number used as the OSGi
Log Service logging level.
<ul>
	<li>If the property is a number, the <tt>int</tt> value of the number is
used</li>
	<li>If the property is a string parseable to an <tt>int</tt> the parsed
value is used</li>
	<li>If the property is any of the strings <em>debug</em>, <em>info</em>,
<em>warn</em>, or <em>error</em>, the respective log level of <tt>4</tt>,
<tt>3</tt>, <tt>2</tt>, or <tt>1</tt> is used.</li>
	<li>Otherwise, unless the <tt>ds.showtrace</tt> or <tt>ds.showerrors</tt>
property is set, the default value is assumed</li>
</ul>
</td>
</tr>
<tr>
<td class='confluenceTd'> <tt>ds.showtrace</tt> </td>
<td class='confluenceTd'> <tt>false</tt> </td>
<td class='confluenceTd'> sets the log level to <tt>debug</tt> if set to
<tt>true</tt> and the <tt>ds.loglevel</tt> cannot be converted to
a value log level </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>ds.showerrors</tt> </td>
<td class='confluenceTd'> <tt>true</tt> </td>
<td class='confluenceTd'> Disables logging completely if set to <tt>false</tt>
and the <tt>ds.loglevel</tt> cannot be converted to a value log level and the
<tt>ds.showtrace</tt> is not set to <tt>true</tt> </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>ds.factory.enabled</tt> </td>
<td class='confluenceTd'> <tt>false</tt> </td>
<td class='confluenceTd'> Enables Component Factory functionality not compliant with
the Declarative Services 1.1 specification if set to <tt>true</tt>. Only set this
if you really know you need this. See the <em>Non-Standard Component Factory Behaviour</em>
section below for more details. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>ds.ctworkaround</tt> </td>
<td class='confluenceTd'> <tt>false</tt> </td>
<td class='confluenceTd'> Enables workaround functionality to pass the OSGi CT. Generally
this property should not be set to <tt>true</tt> because it enables behaviour
which is not compliant with the Declarative Services 1.1 specification. See <a href="https://issues.apache.org/jira/browse/FELIX-2526"
class="external-link" rel="nofollow">FELIX-2526</a> for details. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>ds.delayed.keepInstances</tt> </td>
<td class='confluenceTd'> <tt>false</tt> </td>
<td class='confluenceTd'> Whether or not to keep instances of delayed components once
they are not referred to any more. The Declarative Services specifications suggests that instances
of delayed components are disposed off if there is not used any longer. Setting this flag
causes the components to not be disposed off and thus prevent them from being constantly recreated
if often used. Examples of such components may be EventHandler services. The default is to
dispose off unused components. See <a href="https://issues.apache.org/jira/browse/FELIX-3039"
class="external-link" rel="nofollow">FELIX-3039</a> for details. </td>
</tr>
</tbody></table>
</div>


<p>This configuration mechanism is implemented in the <a href="http://svn.apache.org/repos/asf/felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/config/ScrConfiguration.java"
class="external-link" rel="nofollow">ScrConfiguration</a> and its helper classes.</p>


<h2><a name="ApacheFelixServiceComponentRuntime-NonStandardComponentFactoryBehaviour"></a>Non-Standard
Component Factory Behaviour</h2>

<div class='panelMacro'><table class='noteMacro'><colgroup><col width='24'><col></colgroup><tr><td
valign='top'><img src="/confluence/images/icons/emoticons/warning.gif" width="16" height="16"
align="absmiddle" alt="" border="0"></td><td>If you don't know what this section
is about, just ignore it and leave the <tt>ds.factory.enabled</tt> configuration
property unconfigured.</td></tr></table></div>

<p>Versions of the Apache Felix Declarative Services implementation prior to 1.2.0 supported
handling of Component Factory components which is not specification compliant.</p>

<p>This behaviour assumes the component name of the Component Factory component to be
Service Factory PID and each configuration with this Service Factory PID causes the service
component runtime to actually create and activate an instance of the Component Factory component
automatically. This is not foreseen by the specification which defines instantiation of Component
Factory components as being purely application controled and not configuration induced.</p>

<p>To have components instantiated with factory configurations, regular components should
be used. This case each factory configuration instance will create a component instance.</p>

<p>If you know that you are using Component Factory components depending on this non-standard
behaviour you may set the <tt>ds.factory.enabled</tt> configuration property to
<tt>true</tt> (the default of this property is <tt>false</tt> thus
disabling this functionality for specification compliance).</p>

<p>For details also refer to <a href="https://issues.apache.org/jira/browse/FELIX-1416"
class="external-link" rel="nofollow">FELIX-1416</a></p>


<h2><a name="ApacheFelixServiceComponentRuntime-Administration"></a>Administration</h2>

<p>The OSGi Compendium specification defines no administrative API for Declarative Services.
As of version 0.9.0-20071123.131249-8 a simple administrative API is provided the Apache Felix
implementation. The bundle itself also has a Felix Shell Command providing easy commands to
introspect the states of the registered components.</p>

<p>The <a href="/confluence/display/FELIX/Apache+Felix+Web+Console" title="Apache
Felix Web Console">Apache Felix Web Console</a> has built-in support for Declarative
Services administration based on this API.</p>


<h3><a name="ApacheFelixServiceComponentRuntime-ShellCommand"></a>Shell
Command</h3>

<p>The management API is made available to the Felix Shell as the <tt>scr</tt>
command with a short list of subcommands:</p>

<div class='table-wrap'>
<table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'> Synopsis </th>
<th class='confluenceTh'> Description </th>
</tr>
<tr>
<td class='confluenceTd'> <tt>scr help [ &lt;subcommand&gt; ]</tt>
</td>
<td class='confluenceTd'> Show help of the specific <tt>&lt;subcommand&gt;</tt>
or list all known subcommands </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>scr list [ &lt;bundleId&gt; ]</tt>
</td>
<td class='confluenceTd'> List registered components of the bundle specified by <tt>&lt;bundleId&gt;</tt>
or list all components. Each component is listed with its component ID, the state and the
name. <tt>&lt;bundleId&gt;</tt> man be either the ID of a bundle or the
symbolic name of a bundle. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>scr info &lt;componentId&gt;</tt>
</td>
<td class='confluenceTd'> Show a complete information dump of the given component. This
dump includes the name, status, provided services and information on the service references.
<tt>&lt;componentId&gt;</tt> may be either the ID of a component or the
component's name. The component name must be used for disabled components. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>scr enable &lt;componentId&gt;</tt>
</td>
<td class='confluenceTd'> Enable the given component if not already enabled. If the
component is already destroyed or enabled, this command has no effect. <tt>&lt;componentId&gt;</tt>
may be either the ID of a component or the component's name. The component name must be used
for disabled components. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>scr disable &lt;componentId&gt;</tt>
</td>
<td class='confluenceTd'> Disable the given component if not already disabled. If the
component is already destroyed or disabled, this command has no effect. <tt>&lt;componentId&gt;</tt>
may be either the ID of a component or the component's name. The component name must be used
for disabled components. </td>
</tr>
</tbody></table>
</div>


<p>The administrative API commands are also available in the Gogo shell where the subcommand
names must be prefixed with the name space <tt>scr</tt>. Thus the <tt>list</tt>
command corresponds to <tt>scr:list</tt> in the Gogo shell.</p>


<h3><a name="ApacheFelixServiceComponentRuntime-APIUse"></a>API Use</h3>

<p>The API consists of the main interface <tt>org.apache.felix.scr.ScrService</tt>
and two helper interfaces <tt>org.apache.felix.scr.Component</tt> describing a
registered component and <tt>org.apache.felix.scr.Reference</tt> describing a
single reference of a registered component. To access the management API, client applications
just ask for the <tt>ScrService</tt> as usual:</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
....
ServiceReference scrServiceRef = bundleContext.getServiceReference( ScrService.class.getName()
);
ScrService scrService = (ScrService) bundleContext.getService(scrServiceRef);
....
</pre>
</div></div>

<p>Alternatively, you may of course use the <tt>ServiceTracker</tt> or if
you are using the <tt>ScrService</tt> in a component, you may have the <tt>ScrService</tt>
bound according to the component declaration.</p>

<p>The <tt>ScrService</tt> allows access to all registered components, to
a specific component by component ID or to all registered components of a specific bundle.</p>


<h2><a name="ApacheFelixServiceComponentRuntime-Summary"></a>Summary</h2>

<p>This tutorial just listed some very basic information on Declarative Service. To
get more information, for example on hoe the Configuration Admin Service may be used to configure
components, refer to the Declarative Services Sepecification in the OSGi Service Platform
<em>Service Compendium</em> book.</p>

<p>Have Fun !</p>
    </div>
        <div id="commentsSection" class="wiki-content pageSection">
        <div style="float: right;">
            <a href="https://cwiki.apache.org/confluence/users/viewnotifications.action"
class="grey">Change Notification Preferences</a>
        </div>
        <a href="https://cwiki.apache.org/confluence/display/FELIX/Apache+Felix+Service+Component+Runtime">View
Online</a>
        |
        <a href="https://cwiki.apache.org/confluence/pages/diffpagesbyversion.action?pageId=7967&revisedVersion=16&originalVersion=15">View
Changes</a>
                |
        <a href="https://cwiki.apache.org/confluence/display/FELIX/Apache+Felix+Service+Component+Runtime?showComments=true&amp;showCommentArea=true#addcomment">Add
Comment</a>
            </div>
</div>
</div>
</div>
</div>
</body>
</html>

Mime
View raw message