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 Dependency Manager - Using Annotations - Components
Date Mon, 23 Aug 2010 17:44:00 GMT
<html>
<head>
    <base href="https://cwiki.apache.org/confluence">
            <link rel="stylesheet" href="/confluence/s/1810/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+Dependency+Manager+-+Using+Annotations+-+Components">Apache
Felix Dependency Manager - Using Annotations - Components</a></h2>
    <h4>Page <b>edited</b> by             <a href="https://cwiki.apache.org/confluence/display/~pderop">Pierre
De Rop</a>
    </h4>
        <br/>
                         <h4>Changes (15)</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" >h2. Component Types <br> <br></td></tr>
            <tr><td class="diff-changed-lines" >Before diving into all annotations,
we must first introduce the  different types of components DependencyManager is supporting.
In  Dependency Manager, you may use the following types of components,  depending on what
<span class="diff-changed-words">you<span class="diff-deleted-chars"style="color:#999;background-color:#fdd;text-decoration:line-through;">r</span></span>
need: <br></td></tr>
            <tr><td class="diff-unchanged" > <br> <br></td></tr>
            <tr><td class="diff-changed-lines" >* *Service* component: This kind
of component is rather like an <span class="diff-deleted-words"style="color:#999;background-color:#fdd;text-decoration:line-through;">
</span> OSGi Service: it&#39;s an implementation class that may publish an OSGi
<span class="diff-deleted-words"style="color:#999;background-color:#fdd;text-decoration:line-through;">
</span> service, and/or refer to other dependencies, along with eventual service  properties.
A Service has a lifecycle: it is started once the component <span class="diff-deleted-words"style="color:#999;background-color:#fdd;text-decoration:line-through;">
</span> bundle is started and all required dependencies are injected, and it is <span
class="diff-deleted-words"style="color:#999;background-color:#fdd;text-decoration:line-through;">
</span> then stopped if a required dependency is lost, or if the bundle is <span
class="diff-deleted-words"style="color:#999;background-color:#fdd;text-decoration:line-through;">
</span> stopped. However, notice that in DependencyManager, a Service may not  necessarily
publish a Service into the OSGi registry: in this case, the <span class="diff-deleted-words"style="color:#999;background-color:#fdd;text-decoration:line-through;">
</span> component can still have a managed lifecycle, with dependencies. <br></td></tr>
            <tr><td class="diff-unchanged" > <br></td></tr>
            <tr><td class="diff-changed-lines" >* *Aspect Service* component:
A Service that provides a <span class="diff-deleted-words"style="color:#999;background-color:#fdd;text-decoration:line-through;">
</span> non-functional aspect on top of an existing service. In aspect oriented <span
class="diff-deleted-words"style="color:#999;background-color:#fdd;text-decoration:line-through;">
</span> programming, an aspect, or interceptor can sit between a client and <span
class="diff-deleted-words"style="color:#999;background-color:#fdd;text-decoration:line-through;">
</span> another target service used by the client. An Aspect Service <span class="diff-changed-words">first<span
class="diff-deleted-chars"style="color:#999;background-color:#fdd;text-decoration:line-through;">s
</span></span> tracks a target service and is created once the target service
is <span class="diff-deleted-words"style="color:#999;background-color:#fdd;text-decoration:line-through;">
</span> detected. <span class="diff-changed-words">Then<span class="diff-deleted-chars"style="color:#999;background-color:#fdd;text-decoration:line-through;">,</span></span>
the Aspect Service is provided, but with a higher  ranking, and the client is transparently
updated with the aspect. <span class="diff-deleted-words"style="color:#999;background-color:#fdd;text-decoration:line-through;">
</span> Aspects can be chained and may apply to the same target service (and in <span
class="diff-deleted-words"style="color:#999;background-color:#fdd;text-decoration:line-through;">
</span> this case, the ranking of the Aspect service is used to chain aspects in  the
proper order). <br></td></tr>
            <tr><td class="diff-unchanged" > <br></td></tr>
            <tr><td class="diff-changed-lines" >* *Adapter Service*&amp;nbsp;
component: A Service that adapts another <span class="diff-deleted-words"style="color:#999;background-color:#fdd;text-decoration:line-through;">
</span> existing service into a new one. Like with aspects, sometimes you want <span
class="diff-deleted-words"style="color:#999;background-color:#fdd;text-decoration:line-through;">
</span> to create adapters for certain services, which add certain behavior that <span
class="diff-deleted-words"style="color:#999;background-color:#fdd;text-decoration:line-through;">
</span> results in the publication of (in this case) a different service. <span class="diff-deleted-words"style="color:#999;background-color:#fdd;text-decoration:line-through;">
</span> Adapters can dynamically be added and removed and allow you to keep your <span
class="diff-deleted-words"style="color:#999;background-color:#fdd;text-decoration:line-through;">
</span> basic services implementations clean and simple, adding extra features <span
class="diff-deleted-words"style="color:#999;background-color:#fdd;text-decoration:line-through;">
</span> on top of them in a modular way. <br></td></tr>
            <tr><td class="diff-unchanged" > <br></td></tr>
            <tr><td class="diff-changed-lines" >Now we have introduced the different
types of components, here is the <span class="diff-deleted-words"style="color:#999;background-color:#fdd;text-decoration:line-through;">
</span> list of annotations, allowing to declare DependencyManager service <span
class="diff-deleted-words"style="color:#999;background-color:#fdd;text-decoration:line-through;">
</span> components: <br></td></tr>
            <tr><td class="diff-unchanged" > <br>* *@Service:* for declaring
a component that publishes a singleton OSGi service as long as its dependencies are resolved.
<br></td></tr>
            <tr><td class="diff-snipped" >...<br></td></tr>
            <tr><td class="diff-unchanged" >h2. @Service <br> <br></td></tr>
            <tr><td class="diff-changed-lines" >This annotation annotates an implementation
class that optionally <span class="diff-deleted-words"style="color:#999;background-color:#fdd;text-decoration:line-through;">
</span> publishes an OSGi service, and optionally has some dependencies, with a <span
class="diff-deleted-words"style="color:#999;background-color:#fdd;text-decoration:line-through;">
</span> managed lifecycle. The annotation has the following attributes: <br></td></tr>
            <tr><td class="diff-unchanged" > <br></td></tr>
            <tr><td class="diff-changed-lines" >* *provides*: By default, the
component is registered into the <span class="diff-deleted-words"style="color:#999;background-color:#fdd;text-decoration:line-through;">
</span> OSGi registry under all directly implemented interfaces. If no <span class="diff-deleted-words"style="color:#999;background-color:#fdd;text-decoration:line-through;">
</span> interfaces are implemented, then the component is not registered, but it <span
class="diff-deleted-words"style="color:#999;background-color:#fdd;text-decoration:line-through;">
</span> still has a managed lifecycle, and have dependencies. If you need to  explicitly
define the list of interfaces (or classes) under which the  component must be registered in
the OSGi registry, then use the <span class="diff-deleted-words"style="color:#999;background-color:#fdd;text-decoration:line-through;">provides
</span> <span class="diff-added-words"style="background-color: #dfd;">_provides_</span>
attribute. You can also set this property to an <span class="diff-deleted-words"style="color:#999;background-color:#fdd;text-decoration:line-through;">emtpy</span>
<span class="diff-added-words"style="background-color: #dfd;">empty</span> array
of classes  if you don&#39;t want at all your component to be exposed in the OSGi  registry
(even if it implements some interfaces). <br></td></tr>
            <tr><td class="diff-unchanged" > <br></td></tr>
            <tr><td class="diff-changed-lines" >* *properties*: enumerates the
list of properties that are part  of the Service exposed by the component in the OSGi Registry.
Each  property is defined using the @Property annotation, which represents a  key/value pair.
When a value is actually an array of <span class="diff-changed-words"><span class="diff-deleted-chars"style="color:#999;background-color:#fdd;text-decoration:line-through;">S</span><span
class="diff-added-chars"style="background-color: #dfd;">s</span>trings,</span>
then the <span class="diff-deleted-words"style="color:#999;background-color:#fdd;text-decoration:line-through;">
values</span> <span class="diff-added-words"style="background-color: #dfd;">_values_</span>
attribute of the @Property annotation can be used. This attribute  is not the only way to
specify OSGi Service properties (see Setting  Service properties in the lifecycle section).
<br></td></tr>
            <tr><td class="diff-unchanged" > <br></td></tr>
            <tr><td class="diff-changed-lines" >* *factoryMethod*: may match a
static method name from the <span class="diff-deleted-words"style="color:#999;background-color:#fdd;text-decoration:line-through;">
</span> annotated class which can be used to instantiate the component instance. <span
class="diff-deleted-words"style="color:#999;background-color:#fdd;text-decoration:line-through;">
</span> Normally, DependencyManager instantiates the component using its class <span
class="diff-deleted-words"style="color:#999;background-color:#fdd;text-decoration:line-through;">
</span> name, <span class="diff-added-words"style="background-color: #dfd;">and
with the default constructor of the class,</span> but there are some cases where it
is required to take control of  how the component is created. For instance, this method may
be used to <span class="diff-deleted-words"style="color:#999;background-color:#fdd;text-decoration:line-through;">
</span> create the component as a dynamic proxy ... <br></td></tr>
            <tr><td class="diff-unchanged" > <br></td></tr>
            <tr><td class="diff-deleted-lines" style="color:#999;background-color:#fdd;text-decoration:line-through;">*
*factorySet*: The component factory ID. By default, a Service  component is automatically
instantiated as a singleton when the bundle  is started, and when all required dependencies
are satisfied. But when a  component must be created/configured/disposed dynamically, and
when  multiple instances of the same component are needed, a factorySet should  be used. When
you use this attribute, a java.util.Set&lt;Dictionary&gt;  object is registered into
the OSGi regitry, with a specific  &quot;dm.factory.name&quot; property matching the
ID you specify in the attribute.  This Set&lt;Dictionary&gt; will act as a Factory
API, and another  component may use this Set and add some configuration dictionaries in  it,
in order to fire some component instantiation/activation. There is  one component instantiated
per added dictionary, which is passed to  component instances via a configurable callback
method (using the  factoryConfigure attribute). All public properties will be propagated 
along with eventual published service. A public property is a property  which does not start
with a dot (&quot;.&quot;). Properties starting with a dot  are considered private
to the component, and won&#39;t be propagated to  published service. This model is actually
similar to the Declarative  Service &quot;Component  Factories&quot;, excepts that
you don&#39;t have a dependency  on a specific API,  but rather on a basic jdk class 
(java.util.Set&lt;Dictionary&gt;).  Notice that, unlike in Declarative  Service, the
component factory is&amp;nbsp;  provided once the component bundle  is started, even if
required  dependencies are not satisfied. This is  useful when the component want  to dynamically
configure its dependency  filters. So, to summarize: <br></td></tr>
            <tr><td class="diff-added-lines" style="background-color: #dfd;">*
*factorySet*: The component factory ID. By default, a Service component is automatically instantiated
as a singleton when the bundle is started, and when all required dependencies are satisfied.
But when a component must be created, configured, or disposed dynamically, and when multiple
instances of the same component are needed, a factorySet should  be used. When you use this
attribute, a java.util.Set&lt;Dictionary&gt;  object is registered into the OSGi regitry,
with a specific *{_}dm.factory.name{_}* property matching the ID you specify in the attribute.
This Set&lt;Dictionary&gt; will act as a Factory API, and another component may define
a dependency on this Set and add some configuration dictionaries in  it, in order to fire
some component instantiation/activation. There is one component instantiated per added dictionary,
which is passed to component instances via a configurable callback method (using the *{_}factoryConfigure{_}*
attribute). All public properties will be propagated  along with eventual published service.
A public property is a property  which does not start with a dot (&quot;.&quot;).
Properties starting with a dot are considered private to the component, and won&#39;t
be propagated to published service. This model is actually similar to the Declarative Service
&quot;Component Factories&quot; concept, except that you don&#39;t have a dependency
on a specific API, but rather on a basic jdk class  (java.util.Set&lt;Dictionary&gt;).
Notice that, unlike in Declarative Service, the component factory is&amp;nbsp; provided
once the component bundle is started, even if required dependencies are not satisfied. This
is useful when the component want  to dynamically configure its dependency filters. So, to
summarize: <br></td></tr>
            <tr><td class="diff-changed-lines" >** Each time a new Dictionary
is added into the Set, then a new <span class="diff-deleted-words"style="color:#999;background-color:#fdd;text-decoration:line-through;">
</span> instance of the annotated service will be instantiated, and this <span class="diff-deleted-words"style="color:#999;background-color:#fdd;text-decoration:line-through;">
</span> dictionary is passed to the component callback specified with the <span class="diff-deleted-words"style="color:#999;background-color:#fdd;text-decoration:line-through;">
</span> factoryConfigure attribute. <br></td></tr>
            <tr><td class="diff-changed-lines" >** Each time an existing Dictionary
is re-added into the Set, then <span class="diff-deleted-words"style="color:#999;background-color:#fdd;text-decoration:line-through;">
</span> the corresponding Service instance is updated, and the updated <span class="diff-deleted-words"style="color:#999;background-color:#fdd;text-decoration:line-through;">
</span> dictionary is also passed to the callback specified in the <span class="diff-deleted-words"style="color:#999;background-color:#fdd;text-decoration:line-through;">
</span> factoryConfigure attribute. <br></td></tr>
            <tr><td class="diff-unchanged" >** Each time an existing Dictionary
is removed from the Set, then the  corresponding component instance will be stopped and destroyed.
<br> <br></td></tr>
            <tr><td class="diff-changed-lines" >* *factoryConfigure*: Sets the
&quot;configure&quot; callback method name <span class="diff-deleted-words"style="color:#999;background-color:#fdd;text-decoration:line-through;">
</span> to be called with the factory configuration. This attribute only makes <span
class="diff-deleted-words"style="color:#999;background-color:#fdd;text-decoration:line-through;">
</span> sense if the factorySet() attribute is used. If specified, then this <span
class="diff-deleted-words"style="color:#999;background-color:#fdd;text-decoration:line-through;">
</span> attribute references a component callback method, which is called for <span
class="diff-deleted-words"style="color:#999;background-color:#fdd;text-decoration:line-through;">
</span> providing the configuration supplied by the factory that instantiated <span
class="diff-deleted-words"style="color:#999;background-color:#fdd;text-decoration:line-through;">
</span> this Service. The current Service properties will be also updated with <span
class="diff-deleted-words"style="color:#999;background-color:#fdd;text-decoration:line-through;">
</span> all public properties (which don&#39;t start with a dot). <br></td></tr>
            <tr><td class="diff-unchanged" > <br>Usage example: <br>
<br>{code} <br></td></tr>
            <tr><td class="diff-added-lines" style="background-color: #dfd;">
/** <br>   * This Service will be activated once the bundle is started and when all
required dependencies <br>   * are available. <br>   */ <br> @Service <br>
class X implements Z { <br>     @ConfigurationDependency(pid=&quot;MyPid&quot;)
<br>     void configure(Dictionary conf) { <br>          // Configure or reconfigure
our service. <br>     } <br> <br>     @Start <br>     void start()
{ <br>         // Our Service is starting and is about to be registered in the OSGi
registry as a Z service. <br>     } <br> <br>     public void doService()
{ <br>         // ... <br>     } <br> } <br> <br>{code} <br>Example
using a factorySet: <br> <br>{code} <br></td></tr>
            <tr><td class="diff-unchanged" >  @Service(factorySet=&quot;MyServiceFactory&quot;,
factoryConfigure=&quot;configure&quot;) <br>  class X implements Z { <br></td></tr>
            <tr><td class="diff-snipped" >...<br></td></tr>
        </table>
</div>                            <h4>Full Content</h4>
                    <div class="notificationGreySide">
        <h1><a name="ApacheFelixDependencyManager-UsingAnnotations-Components-AnnotationsWritingComponents"></a>Annotations
- Writing Components</h1>


<h2><a name="ApacheFelixDependencyManager-UsingAnnotations-Components-ComponentTypes"></a>Component
Types</h2>

<p>Before diving into all annotations, we must first introduce the  different types
of components DependencyManager is supporting. In  Dependency Manager, you may use the following
types of components,  depending on what you need:</p>


<ul>
	<li><b>Service</b> component: This kind of component is rather like an
OSGi Service: it's an implementation class that may publish an OSGi service, and/or refer
to other dependencies, along with eventual service  properties. A Service has a lifecycle:
it is started once the component bundle is started and all required dependencies are injected,
and it is then stopped if a required dependency is lost, or if the bundle is stopped. However,
notice that in DependencyManager, a Service may not  necessarily publish a Service into the
OSGi registry: in this case, the component can still have a managed lifecycle, with dependencies.</li>
</ul>


<ul>
	<li><b>Aspect Service</b> component: A Service that provides a non-functional
aspect on top of an existing service. In aspect oriented programming, an aspect, or interceptor
can sit between a client and another target service used by the client. An Aspect Service
first tracks a target service and is created once the target service is detected. Then the
Aspect Service is provided, but with a higher  ranking, and the client is transparently updated
with the aspect. Aspects can be chained and may apply to the same target service (and in this
case, the ranking of the Aspect service is used to chain aspects in  the proper order).</li>
</ul>


<ul>
	<li><b>Adapter Service</b>&nbsp; component: A Service that adapts another
existing service into a new one. Like with aspects, sometimes you want to create adapters
for certain services, which add certain behavior that results in the publication of (in this
case) a different service. Adapters can dynamically be added and removed and allow you to
keep your basic services implementations clean and simple, adding extra features on top of
them in a modular way.</li>
</ul>


<p>Now we have introduced the different types of components, here is the list of annotations,
allowing to declare DependencyManager service components:</p>

<ul>
	<li><b>@Service:</b> for declaring a component that publishes a singleton
OSGi service as long as its dependencies are resolved.</li>
	<li><b>@AspectService</b>: provides a non-functional aspect on top of an
existing service.</li>
	<li><b>@AdapterService</b>: creates an OSGi service that adapts another
existing service into a new interface.</li>
	<li><b>@BundleAdapterService</b>: creates an OSGi service a service on
top of a given bundle.</li>
	<li><b>@ResourceAdapterService</b>: creates an OSGi service on top of a
specific Resource.</li>
	<li><b>@FactoryConfigurationAdapterService</b>: creates an OSGi service
from ConfigAdmin, using a factoryPid, and a ManagedServiceFactory.</li>
</ul>


<h2><a name="ApacheFelixDependencyManager-UsingAnnotations-Components-@Service"></a>@Service</h2>

<p>This annotation annotates an implementation class that optionally publishes an OSGi
service, and optionally has some dependencies, with a managed lifecycle. The annotation has
the following attributes:</p>

<ul>
	<li><b>provides</b>: By default, the component is registered into the OSGi
registry under all directly implemented interfaces. If no interfaces are implemented, then
the component is not registered, but it still has a managed lifecycle, and have dependencies.
If you need to  explicitly define the list of interfaces (or classes) under which the  component
must be registered in the OSGi registry, then use the <em>provides</em> attribute.
You can also set this property to an empty array of classes  if you don't want at all your
component to be exposed in the OSGi  registry (even if it implements some interfaces).</li>
</ul>


<ul>
	<li><b>properties</b>: enumerates the list of properties that are part
 of the Service exposed by the component in the OSGi Registry. Each  property is defined using
the @Property annotation, which represents a  key/value pair. When a value is actually an
array of strings, then the <em>values</em> attribute of the @Property annotation
can be used. This attribute  is not the only way to specify OSGi Service properties (see Setting
 Service properties in the lifecycle section).</li>
</ul>


<ul>
	<li><b>factoryMethod</b>: may match a static method name from the annotated
class which can be used to instantiate the component instance. Normally, DependencyManager
instantiates the component using its class name, and with the default constructor of the class,
but there are some cases where it is required to take control of  how the component is created.
For instance, this method may be used to create the component as a dynamic proxy ...</li>
</ul>


<ul>
	<li><b>factorySet</b>: The component factory ID. By default, a Service
component is automatically instantiated as a singleton when the bundle is started, and when
all required dependencies are satisfied. But when a component must be created, configured,
or disposed dynamically, and when multiple instances of the same component are needed, a factorySet
should  be used. When you use this attribute, a java.util.Set&lt;Dictionary&gt;  object
is registered into the OSGi regitry, with a specific <b><em>dm.factory.name</em></b>
property matching the ID you specify in the attribute. This Set&lt;Dictionary&gt;
will act as a Factory API, and another component may define a dependency on this Set and add
some configuration dictionaries in  it, in order to fire some component instantiation/activation.
There is one component instantiated per added dictionary, which is passed to component instances
via a configurable callback method (using the <b><em>factoryConfigure</em></b>
attribute). All public properties will be propagated  along with eventual published service.
A public property is a property  which does not start with a dot ("."). Properties starting
with a dot are considered private to the component, and won't be propagated to published service.
This model is actually similar to the Declarative Service "Component Factories" concept, except
that you don't have a dependency on a specific API, but rather on a basic jdk class  (java.util.Set&lt;Dictionary&gt;).
Notice that, unlike in Declarative Service, the component factory is&nbsp; provided once
the component bundle is started, even if required dependencies are not satisfied. This is
useful when the component want  to dynamically configure its dependency filters. So, to summarize:
	<ul>
		<li>Each time a new Dictionary is added into the Set, then a new instance of the annotated
service will be instantiated, and this dictionary is passed to the component callback specified
with the factoryConfigure attribute.</li>
		<li>Each time an existing Dictionary is re-added into the Set, then the corresponding
Service instance is updated, and the updated dictionary is also passed to the callback specified
in the factoryConfigure attribute.</li>
		<li>Each time an existing Dictionary is removed from the Set, then the  corresponding
component instance will be stopped and destroyed.</li>
	</ul>
	</li>
</ul>


<ul>
	<li><b>factoryConfigure</b>: Sets the "configure" callback method name
to be called with the factory configuration. This attribute only makes sense if the factorySet()
attribute is used. If specified, then this attribute references a component callback method,
which is called for providing the configuration supplied by the factory that instantiated
this Service. The current Service properties will be also updated with all public properties
(which don't start with a dot).</li>
</ul>


<p>Usage example:</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java"> /**
   * This Service will be activated once the bundle is started and when all required dependencies
   * are available.
   */
 @Service
 class X <span class="code-keyword">implements</span> Z {
     @ConfigurationDependency(pid=<span class="code-quote">"MyPid"</span>)
     void configure(Dictionary conf) {
          <span class="code-comment">// Configure or reconfigure our service.
</span>     }

     @Start
     void start() {
         <span class="code-comment">// Our Service is starting and is about to be registered
in the OSGi registry as a Z service.
</span>     }

     <span class="code-keyword">public</span> void doService() {
         <span class="code-comment">// ...
</span>     }
 }

</pre>
</div></div>
<p>Example using a factorySet:</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">  @Service(factorySet=<span class="code-quote">"MyServiceFactory"</span>,
factoryConfigure=<span class="code-quote">"configure"</span>)
  class X <span class="code-keyword">implements</span> Z {
      void configure(Dictionary conf) {
          <span class="code-comment">// Configure or reconfigure our service. The conf
is provided by the factory,
</span>          <span class="code-comment">// and all <span class="code-keyword">public</span>
properties (which don't start with a dot) are propagated with the
</span>          <span class="code-comment">// Service properties specified in
the properties's Service attribute.
</span>      }

      @ServiceDependency
      void bindOtherService(OtherService other) {
          <span class="code-comment">// store <span class="code-keyword">this</span>
require dependency
</span>      }

      @Start
      void start() {
          <span class="code-comment">// Our Service is starting and is about to be registered
in the OSGi registry as a Z service.
</span>      }

      <span class="code-keyword">public</span> void doService() {
          <span class="code-comment">// ... part of Z <span class="code-keyword">interface</span>
</span>      }
  }

  /**
    * This class will instantiate some X Service instances
    */
  @Service
  class Y {
      @ServiceDependency(filter=<span class="code-quote">"(dm.factory.name=MyServiceFactory)"</span>)
      Set&lt;Dictionary&gt; _XFactory; <span class="code-comment">// This Set
acts as a Factory API <span class="code-keyword">for</span> creating X Service
instances.
</span>
      @Start
      void start() {
          <span class="code-comment">// Instantiate a X Service instance
</span>          Dictionary x1 = <span class="code-keyword">new</span> Hashtable()
{{ put(<span class="code-quote">"foo"</span>, <span class="code-quote">"bar1"</span>);
}};
          _XFactory.add(x1);

          <span class="code-comment">// Instantiate another X Service instance
</span>          Dictionary x2 = <span class="code-keyword">new</span> Hashtable()
{{ put(<span class="code-quote">"foo"</span>, <span class="code-quote">"bar2"</span>);
}};
          _XFactory.add(x2);

          <span class="code-comment">// Update the first X Service instance
</span>          x1.put(<span class="code-quote">"foo"</span>, <span
class="code-quote">"bar1_modified"</span>);
          _XFactory.add(x1);

          <span class="code-comment">// Destroy X Services (Notice that invoking XFactory.clear()
will destroy all X Service instances)
</span>          _XFactory.remove(x1);
          _XFactory.remove(x2);
      }
  }
</pre>
</div></div>

<h2><a name="ApacheFelixDependencyManager-UsingAnnotations-Components-@AspectService"></a>@AspectService</h2>


<h2><a name="ApacheFelixDependencyManager-UsingAnnotations-Components-@AdapterService"></a>@AdapterService</h2>


<h2><a name="ApacheFelixDependencyManager-UsingAnnotations-Components-@BundleAdapterService"></a>@BundleAdapterService</h2>


<h2><a name="ApacheFelixDependencyManager-UsingAnnotations-Components-@ResourceAdapterService"></a>@ResourceAdapterService</h2>


<h2><a name="ApacheFelixDependencyManager-UsingAnnotations-Components-@FactoryConfigurationAdapterService"></a>@FactoryConfigurationAdapterService</h2>
    </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+Dependency+Manager+-+Using+Annotations+-+Components">View
Online</a>
        |
        <a href="https://cwiki.apache.org/confluence/pages/diffpagesbyversion.action?pageId=23335750&revisedVersion=2&originalVersion=1">View
Changes</a>
                |
        <a href="https://cwiki.apache.org/confluence/display/FELIX/Apache+Felix+Dependency+Manager+-+Using+Annotations+-+Components?showComments=true&amp;showCommentArea=true#addcomment">Add
Comment</a>
            </div>
</div>
</div>
</div>
</div>
</body>
</html>

Mime
View raw message