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/12/19 14:40:49 UTC

svn commit: r1849304 [2/2] - in /felix/trunk/dependencymanager: ./ org.apache.felix.dependencymanager.itest/src/org/apache/felix/dm/itest/api/ org.apache.felix.dependencymanager.lambda.itest/src/org/apache/felix/dm/lambda/itest/ org.apache.felix.depend...

Modified: felix/trunk/dependencymanager/org.apache.felix.dependencymanager/src/org/apache/felix/dm/ResourceComponent.java
URL: http://svn.apache.org/viewvc/felix/trunk/dependencymanager/org.apache.felix.dependencymanager/src/org/apache/felix/dm/ResourceComponent.java?rev=1849304&r1=1849303&r2=1849304&view=diff
==============================================================================
--- felix/trunk/dependencymanager/org.apache.felix.dependencymanager/src/org/apache/felix/dm/ResourceComponent.java (original)
+++ felix/trunk/dependencymanager/org.apache.felix.dependencymanager/src/org/apache/felix/dm/ResourceComponent.java Wed Dec 19 14:40:48 2018
@@ -18,6 +18,10 @@
  */
 package org.apache.felix.dm;
 
+import java.util.Dictionary;
+
+import org.apache.felix.dm.Component.ServiceScope;
+
 /**
  * Interface used to configure the various parameters needed when defining 
  * a Dependency Manager resource adapter component.
@@ -40,7 +44,7 @@ package org.apache.felix.dm;
  * public class Activator extends DependencyActivatorBase {
  *     &Override
  *     public void init(BundleContext context, DependencyManager dm) throws Exception {
- *          Component resourceComponent = dm.createResourceComponent()
+ *          ResourceComponent resourceComponent = dm.createResourceComponent()
  *             .setResourceFilter("(path=/videos/*.mkv)")
  *             .setInterface(VideoPlayer.class, null)
  *             .setImplementation(VideoPlayerImpl.class);
@@ -76,9 +80,248 @@ package org.apache.felix.dm;
  * 
  * @see DependencyManager#createBundleComponent()
  */
-public interface ResourceComponent extends Component<ResourceComponent> {
+public interface ResourceComponent extends Component {
+    
+	/**
+	 * Sets the component scope.
+	 * @param scope the component scope (default=SINGLETON)
+	 * 
+	 * @return this component
+	 */
+    ResourceComponent setScope(ServiceScope scope);
     
+   /**
+     * Sets the implementation for this component. You can actually specify
+     * an instance you have instantiated manually, or a <code>Class</code>
+     * that will be instantiated using its default constructor when the
+     * required dependencies are resolved, effectively giving you a lazy
+     * instantiation mechanism.
+     * 
+     * There are four special methods that are called when found through
+     * reflection to give you life cycle management options:
+     * <ol>
+     * <li><code>init()</code> is invoked after the instance has been
+     * created and dependencies have been resolved, and can be used to
+     * initialize the internal state of the instance or even to add more
+     * dependencies based on runtime state</li>
+     * <li><code>start()</code> is invoked right before the service is 
+     * registered</li>
+     * <li><code>stop()</code> is invoked right after the service is
+     * unregistered</li>
+     * <li><code>destroy()</code> is invoked after all dependencies are
+     * removed</li>
+     * </ol>
+     * In short, this allows you to initialize your instance before it is
+     * registered, perform some post-initialization and pre-destruction code
+     * as well as final cleanup. If a method is not defined, it simply is not
+     * called, so you can decide which one(s) you need. If you need even more
+     * fine-grained control, you can register as a service state listener too.
+     * 
+     * @param implementation the implementation
+     * @return this component
+     * @see ComponentStateListener
+     */
+	ResourceComponent setImplementation(Object implementation);
+
+    /**
+     * Adds dependency(ies) to this component, atomically. If the component is already active or if you add
+     * dependencies from the init method, then you should add all the dependencies in one single add method call 
+     * (using the varargs argument), because this method may trigger component activation (like
+     * the ServiceTracker.open() method does).
+     * 
+     * @param dependencies the dependencies to add.
+     * @return this component
+     */
+	ResourceComponent add(Dependency ... dependencies);
+	
+	/**
+	 * Removes a dependency from the component.
+	 * @param d the dependency to remove
+	 * @return this component
+	 */
+	ResourceComponent remove(Dependency d);
+
+    /**
+     * Adds a component state listener to this component.
+     * 
+     * @param listener the state listener
+     */
+	ResourceComponent add(ComponentStateListener listener);
+
+    /**
+     * Removes a component state listener from this component.
+     * 
+     * @param listener the state listener
+     */
+	ResourceComponent remove(ComponentStateListener listener);
+
+    /**
+     * Sets the public interface under which this component should be registered
+     * in the OSGi service registry.
+     *  
+     * @param serviceName the name of the service interface
+     * @param properties the properties for this service
+     * @return this component
+     */
+	ResourceComponent setInterface(String serviceName, Dictionary<?,?> properties);
+
+    /**
+     * Sets the public interfaces under which this component should be registered
+     * in the OSGi service registry.
+     *  
+     * @param serviceNames the names of the service interface
+     * @param properties the properties for these services
+     * @return this component
+     */
+	ResourceComponent setInterface(String[] serviceNames, Dictionary<?, ?> properties);
+
+    /**
+     * Sets the public interface under which this component should be registered
+     * in the OSGi service registry.
+     *  
+     * @param serviceName the name of the service interface
+     * @param properties the properties for this service
+     * @return this component
+     */
+	ResourceComponent setInterface(Class<?> serviceName, Dictionary<?,?> properties);
+
+    /**
+     * Sets the public interfaces under which this component should be registered
+     * in the OSGi service registry.
+     *  
+     * @param serviceNames the names of the service interface
+     * @param properties the properties for these services
+     * @return this component
+     */
+	ResourceComponent setInterface(Class<?>[] serviceNames, Dictionary<?, ?> properties);
+
+	/**
+     * Configures auto configuration of injected classes in the component instance.
+     * The following injections are currently performed, unless you explicitly
+     * turn them off:
+     * <dl>
+     * <dt>BundleContext</dt><dd>the bundle context of the bundle</dd>
+     * <dt>ServiceRegistration</dt><dd>the service registration used to register your service</dd>
+     * <dt>DependencyManager</dt><dd>the dependency manager instance</dd>
+     * <dt>Component</dt><dd>the component instance of the dependency manager</dd>
+     * </dl>
+     * 
+     * @param clazz the class (from the list above)
+     * @param autoConfig <code>false</code> to turn off auto configuration
+     */
+	ResourceComponent setAutoConfig(Class<?> clazz, boolean autoConfig);
+
+    /**
+     * Configures auto configuration of injected classes in the component instance.
+     * 
+     * @param clazz the class (from the list above)
+     * @param instanceName the name of the instance to inject the class into
+     * @see #setAutoConfig(Class, boolean)
+     */
+	ResourceComponent setAutoConfig(Class<?> clazz, String instanceName);
+
+    /**
+     * Sets the service properties associated with the component. If the service
+     * was already registered, it will be updated.
+     * 
+     * @param serviceProperties the properties
+     */
+	ResourceComponent setServiceProperties(Dictionary<?, ?> serviceProperties);
+
+    /**
+     * Sets the names of the methods used as callbacks. These methods, when found, are
+     * invoked as part of the life cycle management of the component implementation. The
+     * dependency manager will look for a method of this name with the following signatures,
+     * in this order:
+     * <ol>
+     * <li>method(Component component)</li>
+     * <li>method()</li>
+     * </ol>
+     * 
+     * @param init the name of the init method
+     * @param start the name of the start method
+     * @param stop the name of the stop method
+     * @param destroy the name of the destroy method
+     * @return the component
+     */
+	ResourceComponent setCallbacks(String init, String start, String stop, String destroy);
+
+    /**
+     * Sets the names of the methods used as callbacks. These methods, when found, are
+     * invoked on the specified instance as part of the life cycle management of the component
+     * implementation.
+     * <p>
+     * See setCallbacks(String init, String start, String stop, String destroy) for more
+     * information on the signatures. Specifying an instance means you can create a manager
+     * that will be invoked whenever the life cycle of a component changes and this manager
+     * can then decide how to expose this life cycle to the actual component, offering an
+     * important indirection when developing your own component models.
+     *
+     * @return this component
+     */
+	ResourceComponent setCallbacks(Object instance, String init, String start, String stop, String destroy);
+
     /**
+     * Sets the factory to use to create the implementation. You can specify
+     * both the factory class and method to invoke. The method should return
+     * the implementation, and can use any method to create it. Actually, this
+     * can be used together with <code>setComposition</code> to create a
+     * composition of instances that work together to implement a component. The
+     * factory itself can also be instantiated lazily by not specifying an
+     * instance, but a <code>Class</code>.
+     * 
+     * @param factory the factory instance or class
+     * @param createMethod the name of the create method
+     * @return this component
+     */
+	ResourceComponent setFactory(Object factory, String createMethod);
+
+    /**
+     * Sets the factory to use to create the implementation. You specify the
+     * method to invoke. The method should return the implementation, and can
+     * use any method to create it. Actually, this can be used together with
+     * <code>setComposition</code> to create a composition of instances that
+     * work together to implement a component.
+     * <p>
+     * Note that currently, there is no default for the factory, so please use
+     * <code>setFactory(factory, createMethod)</code> instead.
+     * 
+     * @param createMethod the name of the create method
+     * @return this component
+     */
+	ResourceComponent setFactory(String createMethod);
+
+    /**
+     * Sets the instance and method to invoke to get back all instances that
+     * are part of a composition and need dependencies injected. All of them
+     * will be searched for any of the dependencies. The method that is
+     * invoked must return an <code>Object[]</code>.
+     * 
+     * @param instance the instance that has the method
+     * @param getMethod the method to invoke
+     * @return this component
+     */
+	ResourceComponent setComposition(Object instance, String getMethod);
+
+    /**
+     * Sets the method to invoke on the service implementation to get back all
+     * instances that are part of a composition and need dependencies injected.
+     * All of them will be searched for any of the dependencies. The method that
+     * is invoked must return an <code>Object[]</code>.
+     * 
+     * @param getMethod the method to invoke
+     * @return this component
+     */
+	ResourceComponent setComposition(String getMethod);
+
+	/**
+	 * Activate debug for this component. Informations related to dependency processing will be displayed
+	 * using osgi log service, our to standard output if no log service is currently available.
+	 * @param label
+	 */
+	ResourceComponent setDebug(String label);
+
+	/**
      * Sets the resource filter used to match a given resource URL.
      * 
      * @param filter the filter condition to use with the resource

Modified: felix/trunk/dependencymanager/org.apache.felix.dependencymanager/src/org/apache/felix/dm/context/ComponentContext.java
URL: http://svn.apache.org/viewvc/felix/trunk/dependencymanager/org.apache.felix.dependencymanager/src/org/apache/felix/dm/context/ComponentContext.java?rev=1849304&r1=1849303&r2=1849304&view=diff
==============================================================================
--- felix/trunk/dependencymanager/org.apache.felix.dependencymanager/src/org/apache/felix/dm/context/ComponentContext.java (original)
+++ felix/trunk/dependencymanager/org.apache.felix.dependencymanager/src/org/apache/felix/dm/context/ComponentContext.java Wed Dec 19 14:40:48 2018
@@ -38,7 +38,7 @@ import org.osgi.framework.BundleContext;
  * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
  */
 @ProviderType
-public interface ComponentContext<T extends Component<T>> extends Component<T> {
+public interface ComponentContext extends Component {
     /**
      * Returns the Component Executor gate that can be used to ensure proper component event serialization.
      * When you schedule a task in the component executor, your task is executed safely and you do not need

Modified: felix/trunk/dependencymanager/org.apache.felix.dependencymanager/src/org/apache/felix/dm/context/packageinfo
URL: http://svn.apache.org/viewvc/felix/trunk/dependencymanager/org.apache.felix.dependencymanager/src/org/apache/felix/dm/context/packageinfo?rev=1849304&r1=1849303&r2=1849304&view=diff
==============================================================================
--- felix/trunk/dependencymanager/org.apache.felix.dependencymanager/src/org/apache/felix/dm/context/packageinfo (original)
+++ felix/trunk/dependencymanager/org.apache.felix.dependencymanager/src/org/apache/felix/dm/context/packageinfo Wed Dec 19 14:40:48 2018
@@ -1 +1 @@
-version 4.4.0
+version 4.4.1

Modified: felix/trunk/dependencymanager/org.apache.felix.dependencymanager/src/org/apache/felix/dm/impl/BundleAdapterImpl.java
URL: http://svn.apache.org/viewvc/felix/trunk/dependencymanager/org.apache.felix.dependencymanager/src/org/apache/felix/dm/impl/BundleAdapterImpl.java?rev=1849304&r1=1849303&r2=1849304&view=diff
==============================================================================
--- felix/trunk/dependencymanager/org.apache.felix.dependencymanager/src/org/apache/felix/dm/impl/BundleAdapterImpl.java (original)
+++ felix/trunk/dependencymanager/org.apache.felix.dependencymanager/src/org/apache/felix/dm/impl/BundleAdapterImpl.java Wed Dec 19 14:40:48 2018
@@ -91,7 +91,7 @@ public class BundleAdapterImpl extends F
 	public class BundleAdapterDecorator extends AbstractDecorator {
 		
 		@SuppressWarnings("unchecked")
-		public Component<?> createService(Object[] properties) {
+		public Component createService(Object[] properties) {
             Bundle bundle = (Bundle) properties[0];
             Hashtable<String, Object> props = new Hashtable<>();
             if (m_serviceProperties != null) {
@@ -105,7 +105,7 @@ public class BundleAdapterImpl extends F
             // the first dependency is always the dependency on the bundle, which
             // will be replaced with a more specific dependency below
             dependencies.remove(0);
-            Component<?> service = m_manager.createComponent()
+            Component service = m_manager.createComponent()
                 .setInterface(m_serviceInterfaces, props)
                 .setImplementation(m_serviceImpl)
                 .setFactory(m_factory, m_factoryCreateMethod) // if not set, no effect

Modified: felix/trunk/dependencymanager/org.apache.felix.dependencymanager/src/org/apache/felix/dm/impl/ComponentImpl.java
URL: http://svn.apache.org/viewvc/felix/trunk/dependencymanager/org.apache.felix.dependencymanager/src/org/apache/felix/dm/impl/ComponentImpl.java?rev=1849304&r1=1849303&r2=1849304&view=diff
==============================================================================
--- felix/trunk/dependencymanager/org.apache.felix.dependencymanager/src/org/apache/felix/dm/impl/ComponentImpl.java (original)
+++ felix/trunk/dependencymanager/org.apache.felix.dependencymanager/src/org/apache/felix/dm/impl/ComponentImpl.java Wed Dec 19 14:40:48 2018
@@ -75,7 +75,7 @@ import org.osgi.service.log.LogService;
  * 
  * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
  */
-public class ComponentImpl implements Component<ComponentImpl>, ComponentContext<ComponentImpl>, ComponentDeclaration {
+public class ComponentImpl implements Component, ComponentContext, ComponentDeclaration {
     /**
      * NullObject ServiceRegistration that is injected in components that don't provide any services. 
      */

Modified: felix/trunk/dependencymanager/org.apache.felix.dependencymanager/src/org/apache/felix/dm/impl/FilterComponent.java
URL: http://svn.apache.org/viewvc/felix/trunk/dependencymanager/org.apache.felix.dependencymanager/src/org/apache/felix/dm/impl/FilterComponent.java?rev=1849304&r1=1849303&r2=1849304&view=diff
==============================================================================
--- felix/trunk/dependencymanager/org.apache.felix.dependencymanager/src/org/apache/felix/dm/impl/FilterComponent.java (original)
+++ felix/trunk/dependencymanager/org.apache.felix.dependencymanager/src/org/apache/felix/dm/impl/FilterComponent.java Wed Dec 19 14:40:48 2018
@@ -49,7 +49,7 @@ import org.osgi.framework.ServiceRegistr
  * 
  * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
  */
-public abstract class FilterComponent<T extends Component<T>> implements Component<T>, ComponentContext<T>, ComponentDeclaration {
+public abstract class FilterComponent<T extends Component> implements Component, ComponentContext, ComponentDeclaration {
     protected volatile ComponentImpl m_component;
     protected volatile List<ComponentStateListener> m_stateListeners = new CopyOnWriteArrayList<>();
     protected volatile String m_init = "init";
@@ -396,7 +396,7 @@ public abstract class FilterComponent<T
     }
 	
 	@Override
-    public ComponentContext<T> instantiateComponent() {
+    public ComponentContext instantiateComponent() {
 		return m_component.instantiateComponent();
 	}
 }
\ No newline at end of file

Modified: felix/trunk/dependencymanager/org.apache.felix.dependencymanager/src/org/apache/felix/dm/impl/ResourceAdapterImpl.java
URL: http://svn.apache.org/viewvc/felix/trunk/dependencymanager/org.apache.felix.dependencymanager/src/org/apache/felix/dm/impl/ResourceAdapterImpl.java?rev=1849304&r1=1849303&r2=1849304&view=diff
==============================================================================
--- felix/trunk/dependencymanager/org.apache.felix.dependencymanager/src/org/apache/felix/dm/impl/ResourceAdapterImpl.java (original)
+++ felix/trunk/dependencymanager/org.apache.felix.dependencymanager/src/org/apache/felix/dm/impl/ResourceAdapterImpl.java Wed Dec 19 14:40:48 2018
@@ -118,7 +118,7 @@ public class ResourceAdapterImpl extends
             } else {
                 resourceDependency.setPropagate(m_propagate);
             }
-            Component<?> service = m_manager.createComponent()
+            Component service = m_manager.createComponent()
                 .setInterface(m_serviceInterfaces, props)
                 .setImplementation(m_serviceImpl)
                 .setFactory(m_factory, m_factoryCreateMethod) // if not set, no effect

Modified: felix/trunk/dependencymanager/org.apache.felix.dependencymanager/src/org/apache/felix/dm/packageinfo
URL: http://svn.apache.org/viewvc/felix/trunk/dependencymanager/org.apache.felix.dependencymanager/src/org/apache/felix/dm/packageinfo?rev=1849304&r1=1849303&r2=1849304&view=diff
==============================================================================
--- felix/trunk/dependencymanager/org.apache.felix.dependencymanager/src/org/apache/felix/dm/packageinfo (original)
+++ felix/trunk/dependencymanager/org.apache.felix.dependencymanager/src/org/apache/felix/dm/packageinfo Wed Dec 19 14:40:48 2018
@@ -1 +1 @@
-version 4.5.0
\ No newline at end of file
+version 4.6.0

Modified: felix/trunk/dependencymanager/release/build.gradle
URL: http://svn.apache.org/viewvc/felix/trunk/dependencymanager/release/build.gradle?rev=1849304&r1=1849303&r2=1849304&view=diff
==============================================================================
--- felix/trunk/dependencymanager/release/build.gradle (original)
+++ felix/trunk/dependencymanager/release/build.gradle Wed Dec 19 14:40:48 2018
@@ -33,7 +33,7 @@ buildscript {
 }
 
 // Our release number, which has to be monotonically incremented each time we make a new release.
-ext.dmRelease = "r14"
+ext.dmRelease = "r15"
 
 // Our Apache svn Staging repo
 ext.svnStagingPath = "https://dist.apache.org/repos/dist/dev/felix"