felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pde...@apache.org
Subject svn commit: r1626911 - in /felix/sandbox/pderop/dependencymanager-prototype/org.apache.felix.dependencymanager.samples: ./ src/org/apache/felix/dependencymanager/samples/conf/ src/org/apache/felix/dependencymanager/samples/device/ src/org/apache/felix/...
Date Mon, 22 Sep 2014 22:04:13 GMT
Author: pderop
Date: Mon Sep 22 22:04:12 2014
New Revision: 1626911

URL: http://svn.apache.org/r1626911
Log:
code cleanup.
Added a sample code showing an adapter example with some "instance bound" dependencies (inspired
from 
http://www.mail-archive.com/users@felix.apache.org/msg15687.html).

Added:
    felix/sandbox/pderop/dependencymanager-prototype/org.apache.felix.dependencymanager.samples/device.bnd
    felix/sandbox/pderop/dependencymanager-prototype/org.apache.felix.dependencymanager.samples/src/org/apache/felix/dependencymanager/samples/device/
    felix/sandbox/pderop/dependencymanager-prototype/org.apache.felix.dependencymanager.samples/src/org/apache/felix/dependencymanager/samples/device/Activator.java
    felix/sandbox/pderop/dependencymanager-prototype/org.apache.felix.dependencymanager.samples/src/org/apache/felix/dependencymanager/samples/device/Device.java
    felix/sandbox/pderop/dependencymanager-prototype/org.apache.felix.dependencymanager.samples/src/org/apache/felix/dependencymanager/samples/device/DeviceConsumer.java
    felix/sandbox/pderop/dependencymanager-prototype/org.apache.felix.dependencymanager.samples/src/org/apache/felix/dependencymanager/samples/device/DeviceImpl.java
    felix/sandbox/pderop/dependencymanager-prototype/org.apache.felix.dependencymanager.samples/src/org/apache/felix/dependencymanager/samples/device/DeviceParameter.java
    felix/sandbox/pderop/dependencymanager-prototype/org.apache.felix.dependencymanager.samples/src/org/apache/felix/dependencymanager/samples/device/DeviceParameterImpl.java
    felix/sandbox/pderop/dependencymanager-prototype/org.apache.felix.dependencymanager.samples/src/org/apache/felix/dependencymanager/samples/hello/ServiceProvider.java
    felix/sandbox/pderop/dependencymanager-prototype/org.apache.felix.dependencymanager.samples/src/org/apache/felix/dependencymanager/samples/hello/ServiceProviderImpl.java
    felix/sandbox/pderop/dependencymanager-prototype/org.apache.felix.dependencymanager.samples/src/org/apache/felix/dependencymanager/samples/tpool/ThreadPool.java
Removed:
    felix/sandbox/pderop/dependencymanager-prototype/org.apache.felix.dependencymanager.samples/src/org/apache/felix/dependencymanager/samples/conf/MyComponent.java
    felix/sandbox/pderop/dependencymanager-prototype/org.apache.felix.dependencymanager.samples/src/org/apache/felix/dependencymanager/samples/hello/ServiceImplementation.java
    felix/sandbox/pderop/dependencymanager-prototype/org.apache.felix.dependencymanager.samples/src/org/apache/felix/dependencymanager/samples/hello/ServiceInterface.java
Modified:
    felix/sandbox/pderop/dependencymanager-prototype/org.apache.felix.dependencymanager.samples/bnd.bnd
    felix/sandbox/pderop/dependencymanager-prototype/org.apache.felix.dependencymanager.samples/src/org/apache/felix/dependencymanager/samples/conf/Activator.java
    felix/sandbox/pderop/dependencymanager-prototype/org.apache.felix.dependencymanager.samples/src/org/apache/felix/dependencymanager/samples/conf/Configurator.java
    felix/sandbox/pderop/dependencymanager-prototype/org.apache.felix.dependencymanager.samples/src/org/apache/felix/dependencymanager/samples/hello/Activator.java
    felix/sandbox/pderop/dependencymanager-prototype/org.apache.felix.dependencymanager.samples/src/org/apache/felix/dependencymanager/samples/hello/ServiceConsumer.java
    felix/sandbox/pderop/dependencymanager-prototype/org.apache.felix.dependencymanager.samples/src/org/apache/felix/dependencymanager/samples/tpool/Activator.java

Modified: felix/sandbox/pderop/dependencymanager-prototype/org.apache.felix.dependencymanager.samples/bnd.bnd
URL: http://svn.apache.org/viewvc/felix/sandbox/pderop/dependencymanager-prototype/org.apache.felix.dependencymanager.samples/bnd.bnd?rev=1626911&r1=1626910&r2=1626911&view=diff
==============================================================================
--- felix/sandbox/pderop/dependencymanager-prototype/org.apache.felix.dependencymanager.samples/bnd.bnd
(original)
+++ felix/sandbox/pderop/dependencymanager-prototype/org.apache.felix.dependencymanager.samples/bnd.bnd
Mon Sep 22 22:04:12 2014
@@ -18,14 +18,15 @@ Bundle-Version: 1.0.0.${tstamp}
 	org.apache.felix.dependencymanager.samples.hello;version=latest,\
 	org.apache.felix.dependencymanager.samples.tpool;version=latest,\
 	org.apache.felix.dependencymanager.samples.conf;version=latest,\
-	org.apache.felix.configadmin;version=1.8.0
+	org.apache.felix.configadmin;version=1.8.0,\
+	org.apache.felix.dependencymanager.samples.device;version=latest
 Private-Package: \
 	org.apache.felix.dependencymanager.samples.tpool,\
 	org.apache.felix.dependencymanager.samples.hello
 -runproperties:  \
-	org.apache.felix.log.maxSize=100000,\
-	org.apache.felix.dependencymanager.parallel=!org.apache.felix.dependencymanager.samples.hello,
*,\
-	org.apache.felix.dependencymanager.runtime.log=debug
+	org.apache.felix.dependencymanager.parallel='!org.apache.felix.dependencymanager.samples.tpool,
*',\
+	org.apache.felix.dependencymanager.runtime.log=debug,\
+	org.apache.felix.log.maxSize=100000
 -plugin: org.apache.felix.dm.annotation.plugin.bnd.AnnotationPlugin;log=debug;\
 	path:=${workspace}/org.apache.felix.dependencymanager.annotation/generated/org.apache.felix.dependencymanager.annotation.jar
 Bundle-Activator: org.apache.felix.dependencymanager.samples.tpool.Activator

Added: felix/sandbox/pderop/dependencymanager-prototype/org.apache.felix.dependencymanager.samples/device.bnd
URL: http://svn.apache.org/viewvc/felix/sandbox/pderop/dependencymanager-prototype/org.apache.felix.dependencymanager.samples/device.bnd?rev=1626911&view=auto
==============================================================================
--- felix/sandbox/pderop/dependencymanager-prototype/org.apache.felix.dependencymanager.samples/device.bnd
(added)
+++ felix/sandbox/pderop/dependencymanager-prototype/org.apache.felix.dependencymanager.samples/device.bnd
Mon Sep 22 22:04:12 2014
@@ -0,0 +1,3 @@
+Bundle-Activator: org.apache.felix.dependencymanager.samples.device.Activator
+Private-Package:  \
+	org.apache.felix.dependencymanager.samples.device
\ No newline at end of file

Modified: felix/sandbox/pderop/dependencymanager-prototype/org.apache.felix.dependencymanager.samples/src/org/apache/felix/dependencymanager/samples/conf/Activator.java
URL: http://svn.apache.org/viewvc/felix/sandbox/pderop/dependencymanager-prototype/org.apache.felix.dependencymanager.samples/src/org/apache/felix/dependencymanager/samples/conf/Activator.java?rev=1626911&r1=1626910&r2=1626911&view=diff
==============================================================================
--- felix/sandbox/pderop/dependencymanager-prototype/org.apache.felix.dependencymanager.samples/src/org/apache/felix/dependencymanager/samples/conf/Activator.java
(original)
+++ felix/sandbox/pderop/dependencymanager-prototype/org.apache.felix.dependencymanager.samples/src/org/apache/felix/dependencymanager/samples/conf/Activator.java
Mon Sep 22 22:04:12 2014
@@ -1,23 +1,27 @@
 package org.apache.felix.dependencymanager.samples.conf;
 
+import java.util.Hashtable;
+import java.util.concurrent.Executor;
+
+import org.apache.felix.dependencymanager.samples.tpool.ThreadPool;
 import org.apache.felix.dm.DependencyActivatorBase;
 import org.apache.felix.dm.DependencyManager;
 import org.osgi.framework.BundleContext;
 import org.osgi.service.cm.ConfigurationAdmin;
 
+/**
+ * This Activator defines a component that is used to injects configuration into the Configuration
Admin service, 
+ * in order to configure some other components defined in other sample sub-projects.
+ *
+ * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
+ */
 public class Activator extends DependencyActivatorBase {
     @Override
-    public void init(BundleContext context, DependencyManager dm) throws Exception {
-        dm.add(createComponent()
-            .setImplementation(MyComponent.class)
-            .add(createConfigurationDependency()
-                .setPid(MyComponent.class.getName())
-                .setCallback("updated")));
-        
+    public void init(BundleContext context, DependencyManager dm) throws Exception {    
   
         dm.add(createComponent()
             .setImplementation(Configurator.class)
             .add(createServiceDependency()
                 .setService(ConfigurationAdmin.class)
-                .setRequired(true)));
+                .setRequired(true)));        
     }
 }

Modified: felix/sandbox/pderop/dependencymanager-prototype/org.apache.felix.dependencymanager.samples/src/org/apache/felix/dependencymanager/samples/conf/Configurator.java
URL: http://svn.apache.org/viewvc/felix/sandbox/pderop/dependencymanager-prototype/org.apache.felix.dependencymanager.samples/src/org/apache/felix/dependencymanager/samples/conf/Configurator.java?rev=1626911&r1=1626910&r2=1626911&view=diff
==============================================================================
--- felix/sandbox/pderop/dependencymanager-prototype/org.apache.felix.dependencymanager.samples/src/org/apache/felix/dependencymanager/samples/conf/Configurator.java
(original)
+++ felix/sandbox/pderop/dependencymanager-prototype/org.apache.felix.dependencymanager.samples/src/org/apache/felix/dependencymanager/samples/conf/Configurator.java
Mon Sep 22 22:04:12 2014
@@ -7,17 +7,22 @@ import java.util.Properties;
 import org.osgi.service.cm.Configuration;
 import org.osgi.service.cm.ConfigurationAdmin;
 
+/**
+ * Configurator class used to inject configuration into Configuration Admin Service.
+ * 
+ * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
+ */
 public class Configurator {
     private volatile ConfigurationAdmin m_ca;
-    Configuration m_conf;
-    
+    volatile Configuration m_serviceConsumerConf;
+
     public void start() {
         try {
-            System.out.println("Starting " + this.getClass().getName());
-            m_conf = m_ca.getConfiguration(MyComponent.class.getName(), null);
+            System.out.println(Thread.currentThread().getName() + ": Starting " + this.getClass().getName());
+            m_serviceConsumerConf = m_ca.getConfiguration("org.apache.felix.dependencymanager.samples.hello.ServiceConsumer",
null);
             Hashtable props = new Properties();
             props.put("key", "value");
-            m_conf.update(props);
+            m_serviceConsumerConf.update(props);
         }
         catch (IOException e) {
             e.printStackTrace();
@@ -25,6 +30,6 @@ public class Configurator {
     }
     
     public void destroy() throws IOException {
-    	m_conf.delete();  
+    	m_serviceConsumerConf.delete();
     }
 }

Added: felix/sandbox/pderop/dependencymanager-prototype/org.apache.felix.dependencymanager.samples/src/org/apache/felix/dependencymanager/samples/device/Activator.java
URL: http://svn.apache.org/viewvc/felix/sandbox/pderop/dependencymanager-prototype/org.apache.felix.dependencymanager.samples/src/org/apache/felix/dependencymanager/samples/device/Activator.java?rev=1626911&view=auto
==============================================================================
--- felix/sandbox/pderop/dependencymanager-prototype/org.apache.felix.dependencymanager.samples/src/org/apache/felix/dependencymanager/samples/device/Activator.java
(added)
+++ felix/sandbox/pderop/dependencymanager-prototype/org.apache.felix.dependencymanager.samples/src/org/apache/felix/dependencymanager/samples/device/Activator.java
Mon Sep 22 22:04:12 2014
@@ -0,0 +1,34 @@
+package org.apache.felix.dependencymanager.samples.device;
+
+import java.util.Hashtable;
+
+import org.apache.felix.dm.DependencyActivatorBase;
+import org.apache.felix.dm.DependencyManager;
+import org.osgi.framework.BundleContext;
+
+/**
+ *
+ * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
+ */
+public class Activator extends DependencyActivatorBase {
+    @Override
+    public void init(BundleContext context, DependencyManager dm) throws Exception { 
+        createDeviceAndParameter(dm, 1);
+        createDeviceAndParameter(dm, 2);
+
+        dm.add(createAdapterService(Device.class, null)
+            .setImplementation(DeviceConsumer.class));
+    }
+    
+    private void createDeviceAndParameter(DependencyManager dm, int id) {
+        Hashtable<String, Object> props = new Hashtable<>();
+        props.put("device.id", id);
+        dm.add(createComponent()
+            .setImplementation(new DeviceImpl(id)).setInterface(Device.class.getName(), props));
+           
+        props = new Hashtable<>();
+        props.put("device.id", id);
+        dm.add(createComponent()
+            .setImplementation(new DeviceParameterImpl(id)).setInterface(DeviceParameter.class.getName(),
props));        
+    }
+}

Added: felix/sandbox/pderop/dependencymanager-prototype/org.apache.felix.dependencymanager.samples/src/org/apache/felix/dependencymanager/samples/device/Device.java
URL: http://svn.apache.org/viewvc/felix/sandbox/pderop/dependencymanager-prototype/org.apache.felix.dependencymanager.samples/src/org/apache/felix/dependencymanager/samples/device/Device.java?rev=1626911&view=auto
==============================================================================
--- felix/sandbox/pderop/dependencymanager-prototype/org.apache.felix.dependencymanager.samples/src/org/apache/felix/dependencymanager/samples/device/Device.java
(added)
+++ felix/sandbox/pderop/dependencymanager-prototype/org.apache.felix.dependencymanager.samples/src/org/apache/felix/dependencymanager/samples/device/Device.java
Mon Sep 22 22:04:12 2014
@@ -0,0 +1,5 @@
+package org.apache.felix.dependencymanager.samples.device;
+
+public interface Device {
+    int getDeviceId();
+}

Added: felix/sandbox/pderop/dependencymanager-prototype/org.apache.felix.dependencymanager.samples/src/org/apache/felix/dependencymanager/samples/device/DeviceConsumer.java
URL: http://svn.apache.org/viewvc/felix/sandbox/pderop/dependencymanager-prototype/org.apache.felix.dependencymanager.samples/src/org/apache/felix/dependencymanager/samples/device/DeviceConsumer.java?rev=1626911&view=auto
==============================================================================
--- felix/sandbox/pderop/dependencymanager-prototype/org.apache.felix.dependencymanager.samples/src/org/apache/felix/dependencymanager/samples/device/DeviceConsumer.java
(added)
+++ felix/sandbox/pderop/dependencymanager-prototype/org.apache.felix.dependencymanager.samples/src/org/apache/felix/dependencymanager/samples/device/DeviceConsumer.java
Mon Sep 22 22:04:12 2014
@@ -0,0 +1,21 @@
+package org.apache.felix.dependencymanager.samples.device;
+
+import org.apache.felix.dm.Component;
+import org.apache.felix.dm.DependencyManager;
+
+public class DeviceConsumer {
+    volatile Device device;
+    volatile DeviceParameter deviceParameter;
+    
+    void init(Component c) {
+        DependencyManager dm = c.getDependencyManager();
+        c.add(dm.createServiceDependency()
+            .setService(DeviceParameter.class, "(device.id=" + device.getDeviceId() + ")")
+            .setRequired(true));
+    }
+    
+    void start() {
+        System.out.println("Created a DeviceConsumer for device id " + device.getDeviceId()
+ ", device parameter id "
+            + deviceParameter.getDeviceId());
+    }
+}

Added: felix/sandbox/pderop/dependencymanager-prototype/org.apache.felix.dependencymanager.samples/src/org/apache/felix/dependencymanager/samples/device/DeviceImpl.java
URL: http://svn.apache.org/viewvc/felix/sandbox/pderop/dependencymanager-prototype/org.apache.felix.dependencymanager.samples/src/org/apache/felix/dependencymanager/samples/device/DeviceImpl.java?rev=1626911&view=auto
==============================================================================
--- felix/sandbox/pderop/dependencymanager-prototype/org.apache.felix.dependencymanager.samples/src/org/apache/felix/dependencymanager/samples/device/DeviceImpl.java
(added)
+++ felix/sandbox/pderop/dependencymanager-prototype/org.apache.felix.dependencymanager.samples/src/org/apache/felix/dependencymanager/samples/device/DeviceImpl.java
Mon Sep 22 22:04:12 2014
@@ -0,0 +1,14 @@
+package org.apache.felix.dependencymanager.samples.device;
+
+public class DeviceImpl implements Device {
+    final int id;
+    
+    DeviceImpl(int id) {
+        this.id = id;
+    }
+    
+    @Override
+    public int getDeviceId() {
+        return id;
+    }
+}

Added: felix/sandbox/pderop/dependencymanager-prototype/org.apache.felix.dependencymanager.samples/src/org/apache/felix/dependencymanager/samples/device/DeviceParameter.java
URL: http://svn.apache.org/viewvc/felix/sandbox/pderop/dependencymanager-prototype/org.apache.felix.dependencymanager.samples/src/org/apache/felix/dependencymanager/samples/device/DeviceParameter.java?rev=1626911&view=auto
==============================================================================
--- felix/sandbox/pderop/dependencymanager-prototype/org.apache.felix.dependencymanager.samples/src/org/apache/felix/dependencymanager/samples/device/DeviceParameter.java
(added)
+++ felix/sandbox/pderop/dependencymanager-prototype/org.apache.felix.dependencymanager.samples/src/org/apache/felix/dependencymanager/samples/device/DeviceParameter.java
Mon Sep 22 22:04:12 2014
@@ -0,0 +1,5 @@
+package org.apache.felix.dependencymanager.samples.device;
+
+public interface DeviceParameter {
+    int getDeviceId();
+}

Added: felix/sandbox/pderop/dependencymanager-prototype/org.apache.felix.dependencymanager.samples/src/org/apache/felix/dependencymanager/samples/device/DeviceParameterImpl.java
URL: http://svn.apache.org/viewvc/felix/sandbox/pderop/dependencymanager-prototype/org.apache.felix.dependencymanager.samples/src/org/apache/felix/dependencymanager/samples/device/DeviceParameterImpl.java?rev=1626911&view=auto
==============================================================================
--- felix/sandbox/pderop/dependencymanager-prototype/org.apache.felix.dependencymanager.samples/src/org/apache/felix/dependencymanager/samples/device/DeviceParameterImpl.java
(added)
+++ felix/sandbox/pderop/dependencymanager-prototype/org.apache.felix.dependencymanager.samples/src/org/apache/felix/dependencymanager/samples/device/DeviceParameterImpl.java
Mon Sep 22 22:04:12 2014
@@ -0,0 +1,14 @@
+package org.apache.felix.dependencymanager.samples.device;
+
+public class DeviceParameterImpl implements DeviceParameter {
+    final int id;
+    
+    DeviceParameterImpl(int id) {
+        this.id = id;
+    }
+
+    @Override
+    public int getDeviceId() {
+        return id;
+    }
+}

Modified: felix/sandbox/pderop/dependencymanager-prototype/org.apache.felix.dependencymanager.samples/src/org/apache/felix/dependencymanager/samples/hello/Activator.java
URL: http://svn.apache.org/viewvc/felix/sandbox/pderop/dependencymanager-prototype/org.apache.felix.dependencymanager.samples/src/org/apache/felix/dependencymanager/samples/hello/Activator.java?rev=1626911&r1=1626910&r2=1626911&view=diff
==============================================================================
--- felix/sandbox/pderop/dependencymanager-prototype/org.apache.felix.dependencymanager.samples/src/org/apache/felix/dependencymanager/samples/hello/Activator.java
(original)
+++ felix/sandbox/pderop/dependencymanager-prototype/org.apache.felix.dependencymanager.samples/src/org/apache/felix/dependencymanager/samples/hello/Activator.java
Mon Sep 22 22:04:12 2014
@@ -6,18 +6,25 @@ import org.osgi.framework.BundleContext;
 
 /**
  * Simple Activator with one service consumer and a service provider.
+ * The ServiceConsumer is also depending on a configuration pid 
+ * (see org.apache.felix.dependencymanager.samples.conf.Configurator)
+ * 
+ * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
  */
 public class Activator extends DependencyActivatorBase {
     @Override
     public void init(BundleContext ctx, DependencyManager dm) throws Exception {
         dm.add(createComponent()
-            .setImplementation(ServiceImplementation.class)
-            .setInterface(ServiceInterface.class.getName(), null));
+            .setImplementation(ServiceProviderImpl.class)
+            .setInterface(ServiceProvider.class.getName(), null));
         
         dm.add(createComponent()
-            .setImplementation(ServiceConsumer.class)
+            .setImplementation(ServiceConsumer.class)            
+            .add(createConfigurationDependency()
+                .setPid("org.apache.felix.dependencymanager.samples.hello.ServiceConsumer")
+                .setCallback("updated"))
             .add(createServiceDependency()
-                .setService(ServiceInterface.class)
+                .setService(ServiceProvider.class)
                 .setRequired(true)));
     
     }

Modified: felix/sandbox/pderop/dependencymanager-prototype/org.apache.felix.dependencymanager.samples/src/org/apache/felix/dependencymanager/samples/hello/ServiceConsumer.java
URL: http://svn.apache.org/viewvc/felix/sandbox/pderop/dependencymanager-prototype/org.apache.felix.dependencymanager.samples/src/org/apache/felix/dependencymanager/samples/hello/ServiceConsumer.java?rev=1626911&r1=1626910&r2=1626911&view=diff
==============================================================================
--- felix/sandbox/pderop/dependencymanager-prototype/org.apache.felix.dependencymanager.samples/src/org/apache/felix/dependencymanager/samples/hello/ServiceConsumer.java
(original)
+++ felix/sandbox/pderop/dependencymanager-prototype/org.apache.felix.dependencymanager.samples/src/org/apache/felix/dependencymanager/samples/hello/ServiceConsumer.java
Mon Sep 22 22:04:12 2014
@@ -1,10 +1,21 @@
 package org.apache.felix.dependencymanager.samples.hello;
 
+import java.util.Dictionary;
+
+/**
+ * Our service consumer. We depend on a ServiceProvider, and on a configuration.
+ * 
+ * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
+ */
 public class ServiceConsumer {
-	volatile ServiceInterface service;
+	volatile ServiceProvider service;
 	
+    protected void update(Dictionary<?, ?> conf) {
+        System.out.println("ServiceConsumer updated with conf " + conf);
+    }
+    
 	public void start() {
-        System.out.println("Starting " + this.getClass().getName());
+        System.out.println(Thread.currentThread().getName() + ": Starting " + this.getClass().getName());
 		this.service.hello();
 	}
 }

Added: felix/sandbox/pderop/dependencymanager-prototype/org.apache.felix.dependencymanager.samples/src/org/apache/felix/dependencymanager/samples/hello/ServiceProvider.java
URL: http://svn.apache.org/viewvc/felix/sandbox/pderop/dependencymanager-prototype/org.apache.felix.dependencymanager.samples/src/org/apache/felix/dependencymanager/samples/hello/ServiceProvider.java?rev=1626911&view=auto
==============================================================================
--- felix/sandbox/pderop/dependencymanager-prototype/org.apache.felix.dependencymanager.samples/src/org/apache/felix/dependencymanager/samples/hello/ServiceProvider.java
(added)
+++ felix/sandbox/pderop/dependencymanager-prototype/org.apache.felix.dependencymanager.samples/src/org/apache/felix/dependencymanager/samples/hello/ServiceProvider.java
Mon Sep 22 22:04:12 2014
@@ -0,0 +1,10 @@
+package org.apache.felix.dependencymanager.samples.hello;
+
+/**
+ * The interface for our service provider.
+ *
+ * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
+ */
+public interface ServiceProvider {
+	public void hello();
+}

Added: felix/sandbox/pderop/dependencymanager-prototype/org.apache.felix.dependencymanager.samples/src/org/apache/felix/dependencymanager/samples/hello/ServiceProviderImpl.java
URL: http://svn.apache.org/viewvc/felix/sandbox/pderop/dependencymanager-prototype/org.apache.felix.dependencymanager.samples/src/org/apache/felix/dependencymanager/samples/hello/ServiceProviderImpl.java?rev=1626911&view=auto
==============================================================================
--- felix/sandbox/pderop/dependencymanager-prototype/org.apache.felix.dependencymanager.samples/src/org/apache/felix/dependencymanager/samples/hello/ServiceProviderImpl.java
(added)
+++ felix/sandbox/pderop/dependencymanager-prototype/org.apache.felix.dependencymanager.samples/src/org/apache/felix/dependencymanager/samples/hello/ServiceProviderImpl.java
Mon Sep 22 22:04:12 2014
@@ -0,0 +1,14 @@
+package org.apache.felix.dependencymanager.samples.hello;
+
+
+/**
+ * The implementation for our service provider.
+ * 
+ * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
+ */
+public class ServiceProviderImpl implements ServiceProvider {
+	@Override
+	public void hello() {
+        System.out.println(Thread.currentThread().getName() + ": Hello");
+	}
+}

Modified: felix/sandbox/pderop/dependencymanager-prototype/org.apache.felix.dependencymanager.samples/src/org/apache/felix/dependencymanager/samples/tpool/Activator.java
URL: http://svn.apache.org/viewvc/felix/sandbox/pderop/dependencymanager-prototype/org.apache.felix.dependencymanager.samples/src/org/apache/felix/dependencymanager/samples/tpool/Activator.java?rev=1626911&r1=1626910&r2=1626911&view=diff
==============================================================================
--- felix/sandbox/pderop/dependencymanager-prototype/org.apache.felix.dependencymanager.samples/src/org/apache/felix/dependencymanager/samples/tpool/Activator.java
(original)
+++ felix/sandbox/pderop/dependencymanager-prototype/org.apache.felix.dependencymanager.samples/src/org/apache/felix/dependencymanager/samples/tpool/Activator.java
Mon Sep 22 22:04:12 2014
@@ -2,7 +2,6 @@ package org.apache.felix.dependencymanag
 
 import java.util.Hashtable;
 import java.util.concurrent.Executor;
-import java.util.concurrent.Executors;
 
 import org.apache.felix.dm.DependencyActivatorBase;
 import org.apache.felix.dm.DependencyManager;
@@ -13,17 +12,21 @@ import org.osgi.framework.BundleContext;
  * DependencyManager core will use the threadpool when handling components dependencies and
  * components lifecycle callbacks.
  * 
- * To turn on parallelism, the "org.apache.felix.dependencymanager.parallel" system property
must also be set
- * to "true".
+ * Important note: since we are using the DM API to declare our threadpool, we have to disable
+ * parallelism for our "org.apache.felix.dependencymanager.samples.tpool.ThreadPool" component.
+ * To do so, we use the 
+ * "org.apache.felix.dependencymanager.parallelism=!org.apache.felix.dependencymanager.samples.tpool,*"
+ * OSGI service property (see the bnd.bnd file).
+ * 
+ * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
  */
 public class Activator extends DependencyActivatorBase {  
     @Override
     public void init(BundleContext context, DependencyManager mgr) throws Exception {
-        System.out.println("Declaring ThreadPool for DependencyManager.");
         Hashtable props = new Hashtable();
         props.put("target", DependencyManager.THREADPOOL);
         mgr.add(createComponent()
             .setInterface(Executor.class.getName(), props)
-            .setImplementation(Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors())));
+            .setImplementation(ThreadPool.class));
     }
 }

Added: felix/sandbox/pderop/dependencymanager-prototype/org.apache.felix.dependencymanager.samples/src/org/apache/felix/dependencymanager/samples/tpool/ThreadPool.java
URL: http://svn.apache.org/viewvc/felix/sandbox/pderop/dependencymanager-prototype/org.apache.felix.dependencymanager.samples/src/org/apache/felix/dependencymanager/samples/tpool/ThreadPool.java?rev=1626911&view=auto
==============================================================================
--- felix/sandbox/pderop/dependencymanager-prototype/org.apache.felix.dependencymanager.samples/src/org/apache/felix/dependencymanager/samples/tpool/ThreadPool.java
(added)
+++ felix/sandbox/pderop/dependencymanager-prototype/org.apache.felix.dependencymanager.samples/src/org/apache/felix/dependencymanager/samples/tpool/ThreadPool.java
Mon Sep 22 22:04:12 2014
@@ -0,0 +1,12 @@
+package org.apache.felix.dependencymanager.samples.tpool;
+
+import java.util.concurrent.LinkedBlockingQueue;
+import java.util.concurrent.ThreadPoolExecutor;
+import java.util.concurrent.TimeUnit;
+
+public class ThreadPool extends ThreadPoolExecutor {
+    final static int SIZE = Runtime.getRuntime().availableProcessors();
+    public ThreadPool() {
+        super(SIZE, SIZE, 0, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<Runnable>());
+    }
+}



Mime
View raw message