You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@felix.apache.org by pd...@apache.org on 2018/10/01 20:32:05 UTC

svn commit: r1842562 - /felix/site/trunk/content/documentation/subprojects/apache-felix-dependency-manager/reference/component-resource-adapter.mdtext

Author: pderop
Date: Mon Oct  1 20:32:05 2018
New Revision: 1842562

URL: http://svn.apache.org/viewvc?rev=1842562&view=rev
Log:
[FELIX-5941] - DM APi enhancements

Modified:
    felix/site/trunk/content/documentation/subprojects/apache-felix-dependency-manager/reference/component-resource-adapter.mdtext

Modified: felix/site/trunk/content/documentation/subprojects/apache-felix-dependency-manager/reference/component-resource-adapter.mdtext
URL: http://svn.apache.org/viewvc/felix/site/trunk/content/documentation/subprojects/apache-felix-dependency-manager/reference/component-resource-adapter.mdtext?rev=1842562&r1=1842561&r2=1842562&view=diff
==============================================================================
--- felix/site/trunk/content/documentation/subprojects/apache-felix-dependency-manager/reference/component-resource-adapter.mdtext (original)
+++ felix/site/trunk/content/documentation/subprojects/apache-felix-dependency-manager/reference/component-resource-adapter.mdtext Mon Oct  1 20:32:05 2018
@@ -4,49 +4,31 @@ Resource adapters work just like adapter
 
 A resource adapter will be applied to any resource that matches the specified filter condition. For each matching resource an adapter will be created based on the adapter implementation class. The adapter will be registered with the specified interface and existing properties from the original resource plus any extra properties you supply here. It will also inherit all dependencies, and if you declare the original service as a member it will be injected.
 
-Usage Example:
-
-	manager.createResourceAdapterService("(&(path=/test)(repository=TestRepository))", true)
-		.setInterface(AdapterService.class.getName(), new Hashtable() {{ put("foo", "bar"); }})
-		.setImplementation(AdapterServiceImpl.class);
-
-## @ResourceAdapterService
-
-Resource adapters are things that adapt a resource instead of a service, and 
-provide an adapter service on top of this 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.
-
-The adapter will be applied to any resource that matches the specified filter 
-condition, which can match some part of the resource URL (with "path", 
-"protocol", "port", or "host" filters). For each matching resource an 
-adapter will be created based on the adapter implementation class. 
-The adapter will be registered with the specified interface and with any 
-extra service properties you supply here. Moreover, the following service 
-properties will be propagated from the resource URL:
-
-* *host*: this property exposes the host part of the resource URL
-* *path*: the resource URL path
-* *protocol*: the resource URL protocol
-* *port*: the resource URL port 
-
-### Annotation attributes
-
-TBD
-
-### Usage Examples:
+## Usage Example using API:
 
 Here, the "VideoPlayer" service provides a video service on top of any movie 
 resources, with service properties "host"/"port"/"protocol"/"path" extracted 
 from the resource URL:
 
     :::java
-    @ResourceAdapterService(filter = "(&(path=/videos/*.mkv)(host=localhost))", propagate = true)
     public class VideoPlayerImpl implements VideoPlayer {
         // Injected by reflection
-        URL resource;
+        volatile URL resource;
              
         void play() {} // play video referenced by this.resource     
         void stop() {} // stop playing the video
         void transcode() {} // ...
     }
 
+    public class Activator extends DependencyManagerActivator {
+        public void init(BundleContext ctx, DependencyManager dm) throws Exception {
+            Component c = manager.createResourceComponent()
+                .setResourceFilter("(&(path=/videos/*.mkv)(host=localhost))")
+                .setPropate(true)
+                .setInterface(AdapterService.class.getName(), new Hashtable() {{ put("foo", "bar"); }})
+                .setImplementation(AdapterServiceImpl.class);
+            dm.add(c);
+        }
+    }
+
+Notice that resource adapters are only supported with the DM API, not using annotations or using DM lambda.