Return-Path: X-Original-To: apmail-felix-commits-archive@www.apache.org Delivered-To: apmail-felix-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 0E21710A9A for ; Fri, 20 Sep 2013 22:55:31 +0000 (UTC) Received: (qmail 44246 invoked by uid 500); 20 Sep 2013 22:55:30 -0000 Delivered-To: apmail-felix-commits-archive@felix.apache.org Received: (qmail 44217 invoked by uid 500); 20 Sep 2013 22:55:30 -0000 Mailing-List: contact commits-help@felix.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@felix.apache.org Delivered-To: mailing list commits@felix.apache.org Received: (qmail 44210 invoked by uid 99); 20 Sep 2013 22:55:30 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 20 Sep 2013 22:55:30 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 20 Sep 2013 22:55:27 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 491F1238890B for ; Fri, 20 Sep 2013 22:55:07 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r879262 - in /websites/staging/felix/trunk/content: ./ documentation/subprojects/apache-felix-dependency-manager/ documentation/subprojects/apache-felix-dependency-manager/apache-felix-dependency-manager-using-annotations/ Date: Fri, 20 Sep 2013 22:55:07 -0000 To: commits@felix.apache.org From: buildbot@apache.org X-Mailer: svnmailer-1.0.9 Message-Id: <20130920225507.491F1238890B@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: buildbot Date: Fri Sep 20 22:55:06 2013 New Revision: 879262 Log: Staging update by buildbot for felix Added: websites/staging/felix/trunk/content/documentation/subprojects/apache-felix-dependency-manager/apache-felix-dependency-manager-using-annotations/dependencymanager-annotations-dependencies.html Removed: websites/staging/felix/trunk/content/documentation/subprojects/apache-felix-dependency-manager/apache-felix-dependency-manager-using-annotations/apache-felix-dependency-manager-using-annotations-dependencies.html Modified: websites/staging/felix/trunk/content/ (props changed) websites/staging/felix/trunk/content/documentation/subprojects/apache-felix-dependency-manager/apache-felix-dependency-manager-using-annotations.html websites/staging/felix/trunk/content/sitemap.html Propchange: websites/staging/felix/trunk/content/ ------------------------------------------------------------------------------ --- cms:source-revision (original) +++ cms:source-revision Fri Sep 20 22:55:06 2013 @@ -1 +1 @@ -1525164 +1525166 Modified: websites/staging/felix/trunk/content/documentation/subprojects/apache-felix-dependency-manager/apache-felix-dependency-manager-using-annotations.html ============================================================================== --- websites/staging/felix/trunk/content/documentation/subprojects/apache-felix-dependency-manager/apache-felix-dependency-manager-using-annotations.html (original) +++ websites/staging/felix/trunk/content/documentation/subprojects/apache-felix-dependency-manager/apache-felix-dependency-manager-using-annotations.html Fri Sep 20 22:55:06 2013 @@ -84,14 +84,14 @@ components can interact with the dynamic
- Rev. 1525160 by pderop on Fri, 20 Sep 2013 22:31:51 +0000 + Rev. 1525166 by pderop on Fri, 20 Sep 2013 22:51:11 +0000
Apache Felix, Felix, Apache, the Apache feather logo, and the Apache Felix project Added: websites/staging/felix/trunk/content/documentation/subprojects/apache-felix-dependency-manager/apache-felix-dependency-manager-using-annotations/dependencymanager-annotations-dependencies.html ============================================================================== --- websites/staging/felix/trunk/content/documentation/subprojects/apache-felix-dependency-manager/apache-felix-dependency-manager-using-annotations/dependencymanager-annotations-dependencies.html (added) +++ websites/staging/felix/trunk/content/documentation/subprojects/apache-felix-dependency-manager/apache-felix-dependency-manager-using-annotations/dependencymanager-annotations-dependencies.html Fri Sep 20 22:55:06 2013 @@ -0,0 +1,321 @@ + + + + + Apache Felix - Dependency Manager Dependencies Annotations + + + + + + +
+ +
+ + Apache + +
+
+ + + +
+ + + +
+ This page is a translated version of /site/dependencymanager-annotations-dependencies.html. In case of + doubt you might want to refer to the old page. +
+ + +

Dependency Manager Dependencies Annotations

+

This section describes the various dependencies supported with annotations.

+

@ServiceDependency

+

Annotates a method or a field for injecting a Service Dependency on it. When applied on a class field, optional unavailable dependencies are injected with a NullObject.

+

Annotation attributes:

+
    +
  • added: The callback method to be invoked when the service is available. This attribute is only meaningful when the annotation is applied on a class field.
  • +
  • changed: The callback method to be invoked when the service properties have changed.
  • +
  • removed: The callback method to invoke when the service is lost.
  • +
  • timeout: The max time in millis to wait for when the dependency is temporarily unavailable. Specifying a positive number allow to block the caller thread between service updates. Only useful for required stateless dependencies that can be replaced transparently. A Dynamic Proxy is used to wrap the actual service dependency (which must be an interface). When the dependency goes away, an attempt is made to replace it with another one which satisfies the service dependency criteria. If no service replacement is available, then any method invocation (through the dynamic proxy) will block during a configurable timeout. On timeout, an unchecked IllegalStateException exception is raised (but the service is not deactivated). +Notice that the changed/removed callbacks are not used when the timeout parameter is > -1. +-1 means no timeout at all (default). 0 means that invocation on a missing service will fail immediately. A positive number represents the max timeout in millis to wait for the service availability.
  • +
  • name: The name used when dynamically configuring this dependency from the init method. Specifying this attribute allows to dynamically configure the dependency filter and required flag from the Service's init method. All unnamed dependencies will be injected before the init() method; so from the init() method, you can then pick up whatever information needed from already injected (unnamed) dependencies, and configure dynamically your named dependencies, which will then be calculated once the init() method returns. Please refer to Apache Felix Dependency Manager - Using Annotations - Lifecycle#Dynamic Dependency Configuration.
  • +
  • propagate: Returns true if the dependency service properties must be published along with the service. Any additional service properties specified directly are merged with these.
  • +
+

Usage Example: Here, the MyComponent component is injected with a dependency over a "MyDependency" service.

+
@Component
+class MyComponent {
+     @ServiceDependency(timeout=15000)
+     MyDependency dependency;
+     // ...
+}
+
+ + +

Usage example of a Service whose dependency filter is configured from ConfigAdmin, using a "named" dependency +(please check Apache Felix Dependency Manager - Using Annotations - Lifecycle#Dynamic Dependency Configuration for more informations about "named" dependencies):

+
/**
+  * A Service whose service dependency "otherService" filter is configured from ConfigAdmin
+  */
+@Service
+class X {
+    private Dictionary m_config;
+
+     /**
+       * Initialize our service from config ... and store the config for later usage (from our init method)
+       */
+     @ConfigurationDependency(pid="MyPid")
+     void configure(Dictionary conf) {
+           m_config = config;
+     }
+
+     /**
+      * All unnamed dependencies are injected: we can now configure other named
+      * dependencies, using the already injected configuration.
+      * The returned Map will be used to configure our "otherService" Dependency.
+      */
+     @Init
+     Map init() {
+         return new HashMap() ;
+     }
+
+     /**
+      * This named dependency filter/required flag will be configured by our init method (see above).
+      */
+     @ServiceDependency(name="otherService")
+         void bindOtherService(OtherService other) {
+     }
+
+     /**
+      * All dependencies are injected and our service is now ready to be published.
+      * Notice that you can also use the publisher service attribute if you need
+      * to take control on service exposition.
+      */
+     @Start
+     void start() {
+     }
+ }
+
+ + +

@ConfigurationDependency

+

A configuration dependency is always required, and allows you to depend on the availability of a valid configuration for your component. This dependency requires the OSGi Configuration Admin Service.

+

Annotation attributes:

+
    +
  • pid: Returns the pid for a given service (by default, the pid is the service class name).
  • +
  • propagate: Returns true if the configuration properties must be published along with the service. Any additional service properties specified directly are merged with these.
  • +
  • heading: The label used to display the tab name (or section) where the properties are displayed. Example: "Printer Service".
  • +
  • description: A human readable description of the PID this annotation is associated with. Example: "Configuration for the PrinterService bundle".
  • +
  • metadata: an array of PropertyMetadaData[]() annotation describing property types (see the FactoryConfigurationAdapterService section in the "Writing Components" section.
  • +
+

Usage Examples

+

In the following example, the "Printer" component depends on a configuration whose PID name is "org.apache.felix.sample.Printer". This service will initialize its ip/port number from the provided configuration:

+
package org.apache.felix.sample;
+
+@Component
+public class Printer {
+    @ConfigurationDependency
+    void updated(Dictionary config) {
+        // load printer ip/port from the provided dictionary.
+    }
+}
+
+ + +

This other example shows how to specify a configuration dependency, as well as meta data used to customize the WebConsole GUI. Using these meta data, you can specify for example the default value for your configurations data, some descriptions, the cardinality of configuration values, etc ...

+
package org.apache.felix.sample;
+
+@Component
+public class Printer {
+    @ConfigurationDependency(
+        heading = "Printer Service",
+        description = "Declare here parameters used to configure the Printer service",
+        metadata = {
+            @PropertyMetaData(heading = "Ip Address",
+                              description = "Enter the ip address for the Printer service",
+                              defaults = { "127.0.0.1" },
+                              type = String.class,
+                              id = "IPADDR",
+                              cardinality = 0),
+            @PropertyMetaData(heading = "Port Number",
+                              description = "Enter the port number for the Printer service",
+                              defaults = { "4444" },
+                              type = Integer.class,
+                              id = "PORTNUM",
+                              cardinality = 0)
+             }
+    )
+    void updated(Dictionary config) {
+        // load configuration from the provided dictionary.
+    }
+}
+
+ + +

@BundleDependency

+

A bundle dependency allows you to depend on a bundle in a certain set of states (INSTALLED\|RESOLVED\|STARTED\|...), as indicated by a state mask. You can also use a filter condition that is matched against all manifest entries. When applied on a class field, optional unavailable dependencies are injected with a NullObject.

+

Attributes:

+
    +
  • changed: Returns the callback method to be invoked when the service have changed.
  • +
  • removed: Returns the callback method to invoke when the service is lost.
  • +
  • required: Returns whether the dependency is required or not.
  • +
  • filter: Returns the filter dependency
  • +
  • stateMask: Returns the bundle state mask (Bundle.INSTALLED \| Bundle.ACTIVE etc ...).
  • +
  • propagate: Specifies if the manifest headers from the bundle should be propagated to the service properties.
  • +
  • name: The name used when dynamically configuring this dependency from the init method. Specifying this attribute allows to dynamically configure the dependency filter and required flag from the Service's init method. All unnamed dependencies will be injected before the init() method; so from the init() method, you can then pick up whatever information needed from already injected (unnamed) dependencies, and configure dynamically your named dependencies, which will then be calculated once the init() method returns. +Please refer to Apache Felix Dependency Manager - Using Annotations - Lifecycle#Dynamic Dependency Configuration.
  • +
+

Usage Examples

+

In the following example, the "SCR" Component allows to track all bundles containing a specific "Service-Component" OSGi header, in order to load and manage all Declarative Service components specified in the SCR xml documents referenced by the header:

+
@Component
+public class SCR {
+    @BundleDependency(required = false,
+                      removed = "unloadServiceComponents",
+                      filter = "(Service-Component=*)"
+                      stateMask = Bundle.ACTIVE)
+    void loadServiceComponents(Bundle b) {
+        String descriptorPaths = (String) b.getHeaders().get("Service-Component");
+        // load all service component specified in the XML descriptorPaths files ...
+    }
+
+    void unloadServiceComponents(Bundle b) {
+        // unload all service component we loaded from our "loadServiceComponents" method.
+    }
+}
+
+ + +

@ResourceDependency

+

Annotates a method of field as a Resource Dependency. A resource dependency allows you to depend on a resource. Resources are an abstraction that is introduced by the dependency manager, represented as a URL. They can be implemented to serve resources embedded in bundles, somewhere on a file system or in an http content repository server, or database. +A resource is a URL and you can use a filter condition based on protocol, host, port, and path.

+

Attributes:

+
    +
  • added: Returns the callback method to be invoked when the service is available. This attribute is only meaningful when the annotation is applied on a class field.
  • +
  • changed: Returns the callback method to be invoked when the service properties have changed.
  • +
  • removed: Returns the callback method to invoke when the service is lost.
  • +
  • required: Returns whether the Service dependency is required or not.
  • +
  • filter: Returns the Service dependency OSGi filter.
  • +
  • propagate: Specifies if the resource URL properties must be propagated. If set to true, then the URL properties ("protocol"/"host"/"port"/"path") will be propagated to the service properties of the component which is using this dependency.
  • +
  • name: The name used when dynamically configuring this dependency from the init method. Specifying this attribute allows to dynamically configure the dependency filter and required flag from the Service's init method. All unnamed dependencies will be injected before the init() method; so from the init() method, you can then pick up whatever information needed from already injected (unnamed) dependencies, and configure dynamically your named dependencies, which will then be calculated once the init() method returns. Please refer to Apache Felix Dependency Manager - Using Annotations - Lifecycle#Dynamic Dependency Configuration.
  • +
+

Usage Examples +Here, the "VideoPlayer" component plays any provided MKV video resources

+
@Component
+public class VideoPlayer {
+    @ResourceDependency(required=false, filter="(path=/videos/*.mkv)")
+    void playResource(URL video) { ... }
+}
+
+ + +

And here is an example of a VideoProvider, which provides some videos using a web URL. Notice that Resource providers need to depend on the DependencyManager API:

+
import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.felix.dm.ResourceHandler;
+import org.apache.felix.dm.ResourceUtil;
+import org.apache.felix.dm.annotation.api.Component;
+import org.apache.felix.dm.annotation.api.Init;
+import org.apache.felix.dm.annotation.api.ServiceDependency;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.Filter;
+import org.osgi.framework.InvalidSyntaxException;
+
+@Component
+public class VideoProvider
+{
+    // Injected by reflection
+    private volatile BundleContext context;
+    // List of known resource handlers
+    private Map<ResourceHandler, Filter> m_handlers = new HashMap<ResourceHandler, Filter>();
+    // List of known video resources
+    private URL[] m_videos;
+
+    @Init
+    void init() throws MalformedURLException
+    {
+       m_videos = new URL[] {
+               new URL("http://localhost:8080/videos/video1.mkv"),
+               new URL("http://localhost:8080/videos/video2.mkv"),
+        };
+    }
+
+    // Track resource handlers
+    @ServiceDependency(required = false)
+    public void add(Map<String, String> serviceProperties, ResourceHandler handler) throws InvalidSyntaxException
+    {
+        String filterString = serviceProperties.get("filter");
+        filterString = (filterString != null) ? filterString : "(path=*)";
+        Filter filter = context.createFilter(filterString);
+        synchronized (this)
+        {
+            m_handlers.put(handler, filter);
+        }
+        for (URL video : m_videos)
+        {
+            if (filter.match(ResourceUtil.createProperties(video)))
+            {
+                handler.added(video);
+            }
+        }
+    }
+}
+
+
+ Rev. 1525166 by pderop on Fri, 20 Sep 2013 22:51:11 +0000 +
+
+ Apache Felix, Felix, Apache, the Apache feather logo, and the Apache Felix project + logo are trademarks of The Apache Software Foundation. All other marks mentioned + may be trademarks or registered trademarks of their respective owners. +
+
+ + Modified: websites/staging/felix/trunk/content/sitemap.html ============================================================================== --- websites/staging/felix/trunk/content/sitemap.html (original) +++ websites/staging/felix/trunk/content/sitemap.html Fri Sep 20 22:55:06 2013 @@ -121,9 +121,9 @@
  • Dependency Manager Annotations