felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pde...@apache.org
Subject svn commit: r947496 - in /felix/trunk/dependencymanager: core/src/main/java/org/apache/felix/dm/ core/src/main/java/org/apache/felix/dm/impl/ runtime/src/main/java/org/apache/felix/dm/runtime/ test/src/test/java/org/apache/felix/dm/test/
Date Sun, 23 May 2010 21:05:27 GMT
Author: pderop
Date: Sun May 23 21:05:27 2010
New Revision: 947496

URL: http://svn.apache.org/viewvc?rev=947496&view=rev
Log:
reworked ResourceAdapter API in order to allow to provide adapter parameters by reusing the
Service interface methods (setInterface, setImplementation, etc ...)

Added:
    felix/trunk/dependencymanager/core/src/main/java/org/apache/felix/dm/impl/ResourceAdapterServiceImpl.java
      - copied, changed from r947494, felix/trunk/dependencymanager/core/src/main/java/org/apache/felix/dm/impl/ResourceAdapterImpl.java
Removed:
    felix/trunk/dependencymanager/core/src/main/java/org/apache/felix/dm/impl/ResourceAdapterImpl.java
Modified:
    felix/trunk/dependencymanager/core/src/main/java/org/apache/felix/dm/DependencyActivatorBase.java
    felix/trunk/dependencymanager/core/src/main/java/org/apache/felix/dm/DependencyManager.java
    felix/trunk/dependencymanager/runtime/src/main/java/org/apache/felix/dm/runtime/ResourceAdapterServiceBuilder.java
    felix/trunk/dependencymanager/test/src/test/java/org/apache/felix/dm/test/FELIX2348_ResourceAdapterTest.java

Modified: felix/trunk/dependencymanager/core/src/main/java/org/apache/felix/dm/DependencyActivatorBase.java
URL: http://svn.apache.org/viewvc/felix/trunk/dependencymanager/core/src/main/java/org/apache/felix/dm/DependencyActivatorBase.java?rev=947496&r1=947495&r2=947496&view=diff
==============================================================================
--- felix/trunk/dependencymanager/core/src/main/java/org/apache/felix/dm/DependencyActivatorBase.java
(original)
+++ felix/trunk/dependencymanager/core/src/main/java/org/apache/felix/dm/DependencyActivatorBase.java
Sun May 23 21:05:27 2010
@@ -165,11 +165,8 @@ public abstract class DependencyActivato
         return m_manager.createAdapterService(serviceInterface, serviceFilter);
     }
     
-    public Service createResourceAdapter(String resourceFilter, Object adapterHandler, String
adapterInterface, Dictionary adapterProperties, Object adapterImplementation, boolean propagate)
{
-        return m_manager.createResourceAdapterService(resourceFilter, adapterHandler, adapterInterface,
adapterProperties, adapterImplementation, propagate);
-    }
-    public Service createResourceAdapter(String resourceFilter, Object adapterHandler, String[]
adapterInterface, Dictionary adapterProperties, Object adapterImplementation, boolean propagate)
{
-        return m_manager.createResourceAdapterService(resourceFilter, adapterHandler, adapterInterface,
adapterProperties, adapterImplementation, propagate);
+    public Service createResourceAdapter(String resourceFilter, boolean propagate) {
+        return m_manager.createResourceAdapterService(resourceFilter, propagate);
     }
     
     public Service createBundleAdapterService(int bundleStateMask, String bundleFilter, Object
adapterImplementation, String adapterInterface, Dictionary adapterProperties, boolean propagate)
{

Modified: felix/trunk/dependencymanager/core/src/main/java/org/apache/felix/dm/DependencyManager.java
URL: http://svn.apache.org/viewvc/felix/trunk/dependencymanager/core/src/main/java/org/apache/felix/dm/DependencyManager.java?rev=947496&r1=947495&r2=947496&view=diff
==============================================================================
--- felix/trunk/dependencymanager/core/src/main/java/org/apache/felix/dm/DependencyManager.java
(original)
+++ felix/trunk/dependencymanager/core/src/main/java/org/apache/felix/dm/DependencyManager.java
Sun May 23 21:05:27 2010
@@ -36,7 +36,7 @@ import org.apache.felix.dm.impl.BundleAd
 import org.apache.felix.dm.impl.FactoryConfigurationAdapterImpl;
 import org.apache.felix.dm.impl.FactoryConfigurationAdapterMetaTypeImpl;
 import org.apache.felix.dm.impl.Logger;
-import org.apache.felix.dm.impl.ResourceAdapterImpl;
+import org.apache.felix.dm.impl.ResourceAdapterServiceImpl;
 import org.apache.felix.dm.impl.ServiceImpl;
 import org.apache.felix.dm.impl.dependencies.BundleDependencyImpl;
 import org.apache.felix.dm.impl.dependencies.ConfigurationDependencyImpl;
@@ -213,7 +213,7 @@ public class DependencyManager {
      * 
      * <blockquote>
      *  manager.createAdapterService(AdapteeService.class, "(foo=bar)")
-     *         // The the interface to use when registering adapters
+     *         // The interface to use when registering adapter
      *         .setInterface(AdapterService.class, new Hashtable() {{ put("additional", "properties");
}})
      *         // the implementation of the adapter
      *         .setImplementation(AdapterImpl.class);
@@ -237,35 +237,29 @@ public class DependencyManager {
      * It will also inherit all dependencies, and if you declare the original
      * service as a member it will be injected.
      * 
+     * <h3>Usage Example</h3>
+     * 
+     * <blockquote>
+     *  manager.createResourceAdapterService("(&(path=/test)(repository=TestRepository))",
true)
+     *         // The interface to use when registering adapter
+     *         .setInterface(AdapterService.class, new Hashtable() {{ put("foo", "bar");
}})
+     *         // the implementation of the adapter
+     *         .setImplementation(AdapterServiceImpl.class)
+     *         // The callback invoked on adapter lifecycle events
+     *         .setCallbacks(new Handler(), "init", "start", "stop", "destroy");
+     * <pre>
+     * </pre>
+     * </blockquote>
+     *
      * @param resourceFilter the filter condition to use with the resource
-     * @param adapterHandler a handler to invoke life cycle methods on for the adapter instance,
or <code>null</code>
-     *     if you want to invoke these methods on the instance
-     * @param adapterInterface the interface to use when registering adapters
-     * @param adapterProperties additional properties to use with the adapter service registration
-     * @param adapterImplementation the implementation of the adapter
      * @param propagate <code>true</code> if properties from the resource should
be propagated to the service
      * @return a service that acts as a factory for generating resource adapters
      * @see Resource
      */
-    public Service createResourceAdapterService(String resourceFilter, Object adapterHandler,
String adapterInterface, Dictionary adapterProperties, Object adapterImplementation, boolean
propagate) {
-        return createService()
-            .setImplementation(new ResourceAdapterImpl(resourceFilter, adapterHandler, adapterImplementation,
adapterInterface, adapterProperties, propagate))
-            .add(createResourceDependency()
-                .setFilter(resourceFilter)
-                .setAutoConfig(false)
-                .setCallbacks("added", "removed")
-            );
+    public Service createResourceAdapterService(String resourceFilter, boolean propagate)
{
+        return new ResourceAdapterServiceImpl(this, resourceFilter, propagate);
     }
-    public Service createResourceAdapterService(String resourceFilter, Object adapterHandler,
String[] adapterInterface, Dictionary adapterProperties, Object adapterImplementation, boolean
propagate) {
-        return createService()
-            .setImplementation(new ResourceAdapterImpl(resourceFilter, adapterHandler, adapterImplementation,
adapterInterface, adapterProperties, propagate))
-            .add(createResourceDependency()
-                .setFilter(resourceFilter)
-                .setAutoConfig(false)
-                .setCallbacks("added", "removed")
-            );
-    }
-
+    
     /**
      * Creates a new bundle adapter. The adapter will be applied to any bundle that
      * matches the specified bundle state mask and filter condition. For each matching

Copied: felix/trunk/dependencymanager/core/src/main/java/org/apache/felix/dm/impl/ResourceAdapterServiceImpl.java
(from r947494, felix/trunk/dependencymanager/core/src/main/java/org/apache/felix/dm/impl/ResourceAdapterImpl.java)
URL: http://svn.apache.org/viewvc/felix/trunk/dependencymanager/core/src/main/java/org/apache/felix/dm/impl/ResourceAdapterServiceImpl.java?p2=felix/trunk/dependencymanager/core/src/main/java/org/apache/felix/dm/impl/ResourceAdapterServiceImpl.java&p1=felix/trunk/dependencymanager/core/src/main/java/org/apache/felix/dm/impl/ResourceAdapterImpl.java&r1=947494&r2=947496&rev=947496&view=diff
==============================================================================
--- felix/trunk/dependencymanager/core/src/main/java/org/apache/felix/dm/impl/ResourceAdapterImpl.java
(original)
+++ felix/trunk/dependencymanager/core/src/main/java/org/apache/felix/dm/impl/ResourceAdapterServiceImpl.java
Sun May 23 21:05:27 2010
@@ -18,82 +18,69 @@
  */
 package org.apache.felix.dm.impl;
 
-import java.util.Dictionary;
 import java.util.Enumeration;
 import java.util.List;
 import java.util.Properties;
 
+import org.apache.felix.dm.DependencyManager;
 import org.apache.felix.dm.resources.Resource;
 import org.apache.felix.dm.service.Service;
 
-public class ResourceAdapterImpl extends AbstractDecorator {
-    private volatile Service m_service;
-    private final String m_resourceFilter;
-    private final Object m_adapterImplementation;
-    private final Object m_adapterInterface;
-    private final Dictionary m_adapterProperties;
-    private final boolean m_propagate;
-    private final Object m_adapterHandler;
-
-    public ResourceAdapterImpl(String resourceFilter, Object adapterHandler, Object adapterImplementation,
String adapterInterface, Dictionary adapterProperties, boolean propagate) {
-        m_resourceFilter = resourceFilter;
-        m_adapterHandler = adapterHandler;
-        m_adapterImplementation = adapterImplementation;
-        m_adapterInterface = adapterInterface;
-        m_adapterProperties = adapterProperties;
-        m_propagate = propagate;
+/**
+ * Resource adapter service implementation. This class extends the FilterService in order
to catch
+ * some Service methods for configuring actual resource adapter service implementation.
+ */
+public class ResourceAdapterServiceImpl extends FilterService
+{
+    /**
+     * Creates a new Resource Adapter Service implementation.
+     * @param dm the dependency manager used to create our internal adapter service
+     */
+    public ResourceAdapterServiceImpl(DependencyManager dm, String resourceFilter, boolean
propagate)    {
+        super(dm.createService()); // This service will be filtered by our super class, allowing
us to take control.
+        m_service.setImplementation(new ResourceAdapterImpl(resourceFilter, propagate))
+                 .add(dm.createResourceDependency()
+                      .setFilter(resourceFilter)
+                      .setAutoConfig(false)
+                      .setCallbacks("added", "removed"));
     }
+    
+    public class ResourceAdapterImpl extends AbstractDecorator {
+        private final String m_resourceFilter;
+        private final boolean m_propagate;
+
+        public ResourceAdapterImpl(String resourceFilter, boolean propagate) {
+            m_resourceFilter = resourceFilter;
+            m_propagate = propagate;
+        }
 
-    public ResourceAdapterImpl(String resourceFilter, Object adapterHandler, Object adapterImplementation,
String[] adapterInterfaces, Dictionary adapterProperties, boolean propagate) {
-        m_resourceFilter = resourceFilter;
-        m_adapterHandler = adapterHandler;
-        m_adapterImplementation = adapterImplementation;
-        m_adapterInterface = adapterInterfaces;
-        m_adapterProperties = adapterProperties;
-        m_propagate = propagate;
-    }	    
-
-    public Service createService(Object[] properties) {
-        Resource resource = (Resource) properties[0]; 
-        Properties props = new Properties();
-        if (m_adapterProperties != null) {
-            Enumeration e = m_adapterProperties.keys();
-            while (e.hasMoreElements()) {
-                Object key = e.nextElement();
-                props.put(key, m_adapterProperties.get(key));
+        public Service createService(Object[] properties) {
+            Resource resource = (Resource) properties[0]; 
+            Properties props = new Properties();
+            if (m_serviceProperties != null) {
+                Enumeration e = m_serviceProperties.keys();
+                while (e.hasMoreElements()) {
+                    Object key = e.nextElement();
+                    props.put(key, m_serviceProperties.get(key));
+                }
             }
-        }
-        List dependencies = m_service.getDependencies();
-        // the first dependency is always the dependency on the resource, which
-        // will be replaced with a more specific dependency below
-        dependencies.remove(0);
-        if (m_adapterInterface instanceof String) {
-            return m_manager.createService()
-                .setInterface((String) m_adapterInterface, props)
-                .setImplementation(m_adapterImplementation)
-                .setCallbacks(m_adapterHandler, "init", "start", "stop", "destroy")
-                .add(dependencies)
-                .add(m_manager.createResourceDependency()
-                    .setResource(resource)
-                    .setPropagate(m_propagate)
-                    .setCallbacks(null, "changed", null)
-                    .setAutoConfig(true)
-                    .setRequired(true)
-                );
-        }
-        else {
+            List dependencies = m_service.getDependencies();
+            // the first dependency is always the dependency on the resource, which
+            // will be replaced with a more specific dependency below
+            dependencies.remove(0);
             return m_manager.createService()
-                .setInterface((String[]) m_adapterInterface, props)
-                .setImplementation(m_adapterImplementation)
-                .setCallbacks(m_adapterHandler, "init", "start", "stop", "destroy")
-                .add(dependencies)
-                .add(m_manager.createResourceDependency()
-                    .setResource(resource)
-                    .setPropagate(m_propagate)
-                    .setCallbacks(null, "changed", null)
-                    .setAutoConfig(true)
-                    .setRequired(true)
-                );
+                            .setInterface(m_serviceInterfaces, props)
+                            .setImplementation(m_serviceImpl)
+                            .setFactory(m_factory, m_factoryCreateMethod) // if not set,
no effect
+                            .setComposition(m_compositionInstance, m_compositionMethod) //
if not set, no effect
+                            .setCallbacks(m_callbackObject, m_init, m_start, m_stop, m_destroy)
// if not set, no effect
+                            .add(dependencies)
+                            .add(m_manager.createResourceDependency()
+                                 .setResource(resource)
+                                 .setPropagate(m_propagate)
+                                 .setCallbacks(null, "changed", null)
+                                 .setAutoConfig(true)
+                                 .setRequired(true));            
         }
     }
 }

Modified: felix/trunk/dependencymanager/runtime/src/main/java/org/apache/felix/dm/runtime/ResourceAdapterServiceBuilder.java
URL: http://svn.apache.org/viewvc/felix/trunk/dependencymanager/runtime/src/main/java/org/apache/felix/dm/runtime/ResourceAdapterServiceBuilder.java?rev=947496&r1=947495&r2=947496&view=diff
==============================================================================
--- felix/trunk/dependencymanager/runtime/src/main/java/org/apache/felix/dm/runtime/ResourceAdapterServiceBuilder.java
(original)
+++ felix/trunk/dependencymanager/runtime/src/main/java/org/apache/felix/dm/runtime/ResourceAdapterServiceBuilder.java
Sun May 23 21:05:27 2010
@@ -46,7 +46,9 @@ public class ResourceAdapterServiceBuild
         String[] service = serviceMetaData.getStrings(Params.service, null);
         Dictionary<String, Object> properties = serviceMetaData.getDictionary(Params.properties,
null);
         boolean propagate = "true".equals(serviceMetaData.getString(Params.propagate, "false"));
-        Service srv = dm.createResourceAdapterService(filter, null, service, properties,
impl, propagate);  
+        Service srv = dm.createResourceAdapterService(filter, propagate)
+                        .setInterface(service, properties)
+                        .setImplementation(impl);
         setCommonServiceParams(srv, serviceMetaData);
         for (MetaData dependencyMetaData: serviceDependencies)
         {

Modified: felix/trunk/dependencymanager/test/src/test/java/org/apache/felix/dm/test/FELIX2348_ResourceAdapterTest.java
URL: http://svn.apache.org/viewvc/felix/trunk/dependencymanager/test/src/test/java/org/apache/felix/dm/test/FELIX2348_ResourceAdapterTest.java?rev=947496&r1=947495&r2=947496&view=diff
==============================================================================
--- felix/trunk/dependencymanager/test/src/test/java/org/apache/felix/dm/test/FELIX2348_ResourceAdapterTest.java
(original)
+++ felix/trunk/dependencymanager/test/src/test/java/org/apache/felix/dm/test/FELIX2348_ResourceAdapterTest.java
Sun May 23 21:05:27 2010
@@ -64,11 +64,8 @@ public class FELIX2348_ResourceAdapterTe
         DependencyManager m = new DependencyManager(context);
         // helper class that ensures certain steps get executed in sequence
         Ensure e = new Ensure();
-        m.add(m.createResourceAdapterService("(&(path=/test)(name=*.txt)(repository=TestRepository))",

-                                            null, 
-                                            (String) null, null,
-                                            new ResourceAdapter(e), 
-                                            false));
+        m.add(m.createResourceAdapterService("(&(path=/test)(name=*.txt)(repository=TestRepository))",
false)
+              .setImplementation(new ResourceAdapter(e)));
         m.add(m.createService().setImplementation(new ResourceProvider(e)).add(m.createServiceDependency().setService(ResourceHandler.class).setCallbacks("add",
"remove")));
         e.waitForStep(3, 5000);
      }



Mime
View raw message