You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@felix.apache.org by do...@apache.org on 2008/01/16 00:05:27 UTC

svn commit: r612292 - in /felix/sandbox/donsez/wireadmin.sample.fictivemeasurementproducer: ./ src/ src/main/ src/main/java/ src/main/java/org/ src/main/java/org/apache/ src/main/java/org/apache/felix/ src/main/java/org/apache/felix/sandbox/ src/main/j...

Author: donsez
Date: Tue Jan 15 15:05:25 2008
New Revision: 612292

URL: http://svn.apache.org/viewvc?rev=612292&view=rev
Log:
creation of the "Fictive Measurement Producer" bundle : a Producer example that poll Measurement objects according to a function sin().

Added:
    felix/sandbox/donsez/wireadmin.sample.fictivemeasurementproducer/
    felix/sandbox/donsez/wireadmin.sample.fictivemeasurementproducer/pom.xml   (with props)
    felix/sandbox/donsez/wireadmin.sample.fictivemeasurementproducer/src/
    felix/sandbox/donsez/wireadmin.sample.fictivemeasurementproducer/src/main/
    felix/sandbox/donsez/wireadmin.sample.fictivemeasurementproducer/src/main/java/
    felix/sandbox/donsez/wireadmin.sample.fictivemeasurementproducer/src/main/java/org/
    felix/sandbox/donsez/wireadmin.sample.fictivemeasurementproducer/src/main/java/org/apache/
    felix/sandbox/donsez/wireadmin.sample.fictivemeasurementproducer/src/main/java/org/apache/felix/
    felix/sandbox/donsez/wireadmin.sample.fictivemeasurementproducer/src/main/java/org/apache/felix/sandbox/
    felix/sandbox/donsez/wireadmin.sample.fictivemeasurementproducer/src/main/java/org/apache/felix/sandbox/util/
    felix/sandbox/donsez/wireadmin.sample.fictivemeasurementproducer/src/main/java/org/apache/felix/sandbox/util/config/
    felix/sandbox/donsez/wireadmin.sample.fictivemeasurementproducer/src/main/java/org/apache/felix/sandbox/util/config/Configuration.java   (with props)
    felix/sandbox/donsez/wireadmin.sample.fictivemeasurementproducer/src/main/java/org/apache/felix/sandbox/util/measurement/
    felix/sandbox/donsez/wireadmin.sample.fictivemeasurementproducer/src/main/java/org/apache/felix/sandbox/util/measurement/UnitUtil.java   (with props)
    felix/sandbox/donsez/wireadmin.sample.fictivemeasurementproducer/src/main/java/org/apache/felix/sandbox/wireadmin/
    felix/sandbox/donsez/wireadmin.sample.fictivemeasurementproducer/src/main/java/org/apache/felix/sandbox/wireadmin/sample/
    felix/sandbox/donsez/wireadmin.sample.fictivemeasurementproducer/src/main/java/org/apache/felix/sandbox/wireadmin/sample/fictivemeasurementproducer/
    felix/sandbox/donsez/wireadmin.sample.fictivemeasurementproducer/src/main/java/org/apache/felix/sandbox/wireadmin/sample/fictivemeasurementproducer/MeasurementProducer.java   (with props)
    felix/sandbox/donsez/wireadmin.sample.fictivemeasurementproducer/src/main/resources/
    felix/sandbox/donsez/wireadmin.sample.fictivemeasurementproducer/src/main/resources/config.properties   (with props)
    felix/sandbox/donsez/wireadmin.sample.fictivemeasurementproducer/src/site/
    felix/sandbox/donsez/wireadmin.sample.fictivemeasurementproducer/src/site/readme.html   (with props)

Added: felix/sandbox/donsez/wireadmin.sample.fictivemeasurementproducer/pom.xml
URL: http://svn.apache.org/viewvc/felix/sandbox/donsez/wireadmin.sample.fictivemeasurementproducer/pom.xml?rev=612292&view=auto
==============================================================================
--- felix/sandbox/donsez/wireadmin.sample.fictivemeasurementproducer/pom.xml (added)
+++ felix/sandbox/donsez/wireadmin.sample.fictivemeasurementproducer/pom.xml Tue Jan 15 15:05:25 2008
@@ -0,0 +1,72 @@
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements.  See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership.  The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License.  You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied.  See the License for the
+ specific language governing permissions and limitations
+ under the License.
+-->
+<project>
+	<properties>
+		<repositoryLocation>http://people.apache.org/~donsez/dev/felix/sandbox/</repositoryLocation>
+		<description>a example of a producer for the Wire Admin service.</description>
+	</properties>  
+
+  <modelVersion>4.0.0</modelVersion>
+  <packaging>bundle</packaging>
+  <name>Fictive Measurement Producer</name>
+  <description>${description}</description>
+  <groupId>org.apache.felix.sandbox</groupId>
+  <version>0.1.0-SNAPSHOT</version>
+  <artifactId>wireadmin.sample.fictivemeasurementproducer</artifactId>
+
+  <dependencies>
+
+	<dependency>
+		<groupId>org.apache.felix</groupId>
+		<artifactId>org.osgi.core</artifactId>
+  		<version>1.1.0-SNAPSHOT</version>
+	</dependency>
+	
+	<dependency>
+		<groupId>org.apache.felix</groupId>
+		<artifactId>org.osgi.compendium</artifactId>
+  		<version>0.9.0-SNAPSHOT</version>
+	</dependency>
+        
+  </dependencies>
+  
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.felix</groupId>
+        <artifactId>maven-bundle-plugin</artifactId>
+        <extensions>true</extensions>
+        <configuration>
+          <instructions>
+            <Import-Package>*</Import-Package>
+            <Private-Package>
+              ${pom.groupId}.${pom.artifactId},
+              ${pom.groupId}.util.*
+            </Private-Package>
+           	<Bundle-Activator>${pom.groupId}.${pom.artifactId}.MeasurementProducer</Bundle-Activator>
+            
+            <!-- docs in http://cwiki.apache.org/FELIX/bundle-plugin-for-maven-bnd.html and http://cwiki.apache.org/FELIX/osgi-plugin-for-maven-2.html -->
+            <Export-Service>org.osgi.service.wireadmin.Producer</Export-Service>
+                        
+          </instructions>
+        </configuration>
+      </plugin>
+    </plugins>
+  </build>
+</project>

Propchange: felix/sandbox/donsez/wireadmin.sample.fictivemeasurementproducer/pom.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Added: felix/sandbox/donsez/wireadmin.sample.fictivemeasurementproducer/src/main/java/org/apache/felix/sandbox/util/config/Configuration.java
URL: http://svn.apache.org/viewvc/felix/sandbox/donsez/wireadmin.sample.fictivemeasurementproducer/src/main/java/org/apache/felix/sandbox/util/config/Configuration.java?rev=612292&view=auto
==============================================================================
--- felix/sandbox/donsez/wireadmin.sample.fictivemeasurementproducer/src/main/java/org/apache/felix/sandbox/util/config/Configuration.java (added)
+++ felix/sandbox/donsez/wireadmin.sample.fictivemeasurementproducer/src/main/java/org/apache/felix/sandbox/util/config/Configuration.java Tue Jan 15 15:05:25 2008
@@ -0,0 +1,217 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.sandbox.util.config;
+
+import java.io.FileInputStream;
+import java.io.InputStream;
+import java.util.Hashtable;
+import java.util.Map;
+import java.util.Properties;
+import java.util.StringTokenizer;
+import java.util.Vector;
+
+/**
+ * configuration utility
+ * 
+ * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
+ */
+public class Configuration {
+	static String DEFAULT_PROPERTIES_FILE = "config.properties";
+
+	/**
+	 * loads properties from a file
+	 * 
+	 * @param filename
+	 *            the properties file name
+	 * @return the properties
+	 */
+	public static Properties loadProperties(String filename) {
+		if (filename == null) {
+			filename = System.getProperty(
+					"org.apache.felix.sandbox.util.configuration.file",
+					DEFAULT_PROPERTIES_FILE);
+		}
+		try {
+			return loadProperties(new FileInputStream(filename));
+		} catch (Exception ex) {
+			ex.printStackTrace();
+			return null;
+		}
+	}
+
+	/**
+	 * loads properties from a input stream
+	 * 
+	 * @param in
+	 *            the imput stream
+	 * @return the properties
+	 */
+	public static Properties loadProperties(InputStream in) {
+		Properties prop = new Properties();
+		try {
+			prop.load(in);
+		} catch (Exception ex) {
+			ex.printStackTrace();
+			return null;
+		}
+		return prop;
+	}
+
+	/**
+	 * builds a map from properties. the key list is in the property
+	 * keyListPropertyName <br>
+	 * Example getMap(props,"keylist") returns a hashtable with 3 key-value
+	 * entry
+	 * 
+	 * <pre>
+	 *  keylist=bar;bubba;foo
+	 *  bar=BAR
+	 *  foo=1.5;float
+	 *  bubba=100;int
+	 * </pre>
+	 * 
+	 * @param props
+	 *            the properties
+	 * @param keyListPropertyName
+	 *            the property name of the key list (separed by ;)
+	 * @return The map
+	 */
+	public static Map getMap(Properties props, String keyListPropertyName) {
+		return getHashtable(props, keyListPropertyName);
+	}
+
+	/**
+	 * builds a hashtable from properties. the key list is in the property
+	 * keyListPropertyName <br>
+	 * Example getHashtable(props,"keylist") returns a hashtable with 3
+	 * key-value entry
+	 * 
+	 * <pre>
+	 *  keylist=bar;bubba;foo
+	 *  bar=BAR
+	 *  foo=1.5;float
+	 *  bubba=100;int
+	 * </pre>
+	 * 
+	 * @param props
+	 *            the properties
+	 * @param keyListPropertyName
+	 *            the property name of the key list (separed by ;)
+	 * @return The hashtable
+	 */
+	public static Hashtable getHashtable(Properties props,
+			String keyListPropertyName) {
+
+		StringTokenizer st = new StringTokenizer(props
+				.getProperty(keyListPropertyName), ";");
+		Hashtable map = new Hashtable();
+
+		while (st.hasMoreTokens()) {
+			String key = st.nextToken();
+			StringTokenizer stvaluetype = new StringTokenizer(props
+					.getProperty(key), ";");
+			Object obj = null;
+			if (stvaluetype.hasMoreTokens()) {
+				String value = stvaluetype.nextToken();
+				if (stvaluetype.hasMoreTokens()) {
+					String type = stvaluetype.nextToken();
+					if (type.equals("int")) {
+						obj = new Integer(value);
+					} else if (type.equals("long")) {
+						obj = new Long(value);
+					} else if (type.equals("float")) {
+						obj = new Float(value);
+					} else if (type.equals("double")) {
+						obj = new Double(value);
+					} else if (type.equals("string")) {
+						obj = value;
+					} else {
+						// default : string
+						obj = value;
+					}
+				} else {
+					// no type means String
+					obj = value;
+				}
+
+			}
+			map.put(key, obj);
+		}
+		return map;
+	}
+
+	/**
+	 * builds a (ordered) vector from properties. the index list is in the
+	 * property keyListPropertyName <br>
+	 * Example getVector(props,"tab") returns a 4 elements vector (tab.5 is
+	 * ignored since tab.4 does not exist)
+	 * 
+	 * <pre>
+	 *  tab.0=bar
+	 *  tab.1=foo
+	 *  tab.2=1.5;float
+	 *  tab.3=100;int
+	 *  tab.5=10000;long
+	 * </pre>
+	 * 
+	 * @param props
+	 *            the properties
+	 * @param vectorPropertyName
+	 *            the property name of the key list (separed by ;)
+	 * @return The vector
+	 */
+	public static Vector getVector(Properties props, String vectorPropertyName) {
+
+		Vector vect = new Vector();
+
+		for (int i = 0; true; i++) {
+			String valuetype = props.getProperty(vectorPropertyName) + "." + i;
+			if (valuetype == null)
+				break;
+			StringTokenizer stvaluetype = new StringTokenizer(valuetype, ";");
+			Object obj = null;
+			if (stvaluetype.hasMoreTokens()) {
+				String value = stvaluetype.nextToken();
+				if (stvaluetype.hasMoreTokens()) {
+					String type = stvaluetype.nextToken();
+					if (type.equals("int")) {
+						obj = new Integer(value);
+					} else if (type.equals("long")) {
+						obj = new Long(value);
+					} else if (type.equals("float")) {
+						obj = new Float(value);
+					} else if (type.equals("double")) {
+						obj = new Double(value);
+					} else if (type.equals("string")) {
+						obj = value;
+					} else {
+						// default : string
+						obj = value;
+					}
+				} else {
+					// no type means String
+					obj = value;
+				}
+
+			}
+			vect.addElement(obj);
+		}
+		return vect;
+	}
+}

Propchange: felix/sandbox/donsez/wireadmin.sample.fictivemeasurementproducer/src/main/java/org/apache/felix/sandbox/util/config/Configuration.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: felix/sandbox/donsez/wireadmin.sample.fictivemeasurementproducer/src/main/java/org/apache/felix/sandbox/util/measurement/UnitUtil.java
URL: http://svn.apache.org/viewvc/felix/sandbox/donsez/wireadmin.sample.fictivemeasurementproducer/src/main/java/org/apache/felix/sandbox/util/measurement/UnitUtil.java?rev=612292&view=auto
==============================================================================
--- felix/sandbox/donsez/wireadmin.sample.fictivemeasurementproducer/src/main/java/org/apache/felix/sandbox/util/measurement/UnitUtil.java (added)
+++ felix/sandbox/donsez/wireadmin.sample.fictivemeasurementproducer/src/main/java/org/apache/felix/sandbox/util/measurement/UnitUtil.java Tue Jan 15 15:05:25 2008
@@ -0,0 +1,79 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.sandbox.util.measurement;
+
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+
+import org.osgi.util.measurement.Unit;
+
+/**
+ * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
+ */
+
+public class UnitUtil {
+
+	private static Map mapString2Unit = new HashMap();
+	static {
+		mapString2Unit.put("A", Unit.A);
+		mapString2Unit.put("C", Unit.C);
+		mapString2Unit.put("cd", Unit.cd);
+		mapString2Unit.put("F", Unit.F);
+		mapString2Unit.put("Gy", Unit.Gy);
+		mapString2Unit.put("Hz", Unit.Hz);
+		mapString2Unit.put("J", Unit.J);
+		mapString2Unit.put("K", Unit.K);
+		mapString2Unit.put("kat", Unit.kat);
+		mapString2Unit.put("kg", Unit.kg);
+		mapString2Unit.put("lx", Unit.lx);
+		mapString2Unit.put("m", Unit.m);
+		mapString2Unit.put("m2", Unit.m2);
+		mapString2Unit.put("m3", Unit.m3);
+		mapString2Unit.put("m_s", Unit.m_s);
+		mapString2Unit.put("m_s2", Unit.m_s2);
+		mapString2Unit.put("mol", Unit.mol);
+		mapString2Unit.put("N", Unit.N);
+		mapString2Unit.put("Ohm", Unit.Ohm);
+		mapString2Unit.put("Pa", Unit.Pa);
+		mapString2Unit.put("rad", Unit.rad);
+		mapString2Unit.put("S", Unit.S);
+		mapString2Unit.put("s", Unit.s);
+		mapString2Unit.put("T", Unit.T);
+		mapString2Unit.put("unity", Unit.unity);
+		mapString2Unit.put("V", Unit.V);
+		mapString2Unit.put("W", Unit.W);
+		mapString2Unit.put("Wb", Unit.Wb);
+	}
+
+	public static Unit getUnitFromString(String str){
+	    return (Unit) mapString2Unit.get(str);
+	}
+	
+	public static String getStringFromUnit(Unit unit){
+	    Iterator iter=mapString2Unit.entrySet().iterator();
+	    while(iter.hasNext()){
+	        Map.Entry mapEntry=(Map.Entry)iter.next();
+	        if(unit.equals(mapEntry.getValue()))
+	            return (String) mapEntry.getKey();
+	    }	    
+	    return null;
+	}
+	
+}

Propchange: felix/sandbox/donsez/wireadmin.sample.fictivemeasurementproducer/src/main/java/org/apache/felix/sandbox/util/measurement/UnitUtil.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: felix/sandbox/donsez/wireadmin.sample.fictivemeasurementproducer/src/main/java/org/apache/felix/sandbox/wireadmin/sample/fictivemeasurementproducer/MeasurementProducer.java
URL: http://svn.apache.org/viewvc/felix/sandbox/donsez/wireadmin.sample.fictivemeasurementproducer/src/main/java/org/apache/felix/sandbox/wireadmin/sample/fictivemeasurementproducer/MeasurementProducer.java?rev=612292&view=auto
==============================================================================
--- felix/sandbox/donsez/wireadmin.sample.fictivemeasurementproducer/src/main/java/org/apache/felix/sandbox/wireadmin/sample/fictivemeasurementproducer/MeasurementProducer.java (added)
+++ felix/sandbox/donsez/wireadmin.sample.fictivemeasurementproducer/src/main/java/org/apache/felix/sandbox/wireadmin/sample/fictivemeasurementproducer/MeasurementProducer.java Tue Jan 15 15:05:25 2008
@@ -0,0 +1,244 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.sandbox.wireadmin.sample.fictivemeasurementproducer;
+
+import java.io.InputStream;
+import java.io.PrintStream;
+import java.util.Dictionary;
+import java.util.Enumeration;
+import java.util.Hashtable;
+import java.util.Properties;
+
+import org.apache.felix.sandbox.util.config.Configuration;
+import org.apache.felix.sandbox.util.measurement.UnitUtil;
+import org.osgi.framework.BundleActivator;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceRegistration;
+import org.osgi.service.wireadmin.Producer;
+import org.osgi.service.wireadmin.Wire;
+import org.osgi.util.measurement.Measurement;
+import org.osgi.util.measurement.Unit;
+
+
+/**
+ * The class provides a producer of random measurements 
+ * It's a sample for the Wire Admin service
+ * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
+ * TODO check synchronizations on wires[]
+ * TODO takes into account wireadmin.filter http://www2.osgi.org/javadoc/r4/org/osgi/service/wireadmin/WireConstants.html#WIREADMIN_FILTER
+ * TODO add pause when no wires are created, connected or valid
+ */
+public class MeasurementProducer implements Producer, Runnable, BundleActivator {
+
+	private Wire wires[];
+	private ServiceRegistration serviceRegistration;
+	
+	private int pollDelay;
+	private double max;
+	private double min;
+	private Unit unit;
+	private double error;
+	private long period;
+	private PrintStream traceout;
+
+	private boolean quit;
+
+	private static final String CONFIGFILE = "/config.properties";
+
+	protected BundleContext bundleContext = null;
+
+	/**
+	 * Load the configuration properties and register e new service
+	 */
+	private void configure() throws Exception {
+
+		// Get the Config-Location value from the manifest
+
+		String configLocation = null;
+		Dictionary dict = bundleContext.getBundle().getHeaders();
+		Enumeration enumeration = dict.keys();
+		while (enumeration.hasMoreElements()) {
+			Object nextKey = enumeration.nextElement();
+			Object nextElem = dict.get(nextKey);
+			if (nextKey.equals("Config-Location")) {
+				configLocation = nextElem.toString();
+				break;
+			}
+		}
+		if (configLocation == null) {
+			configLocation = CONFIGFILE;
+		}
+
+		// Load properties from configLocation file
+		InputStream is = getClass().getResourceAsStream(configLocation);
+		Properties props = Configuration.loadProperties(is);
+
+		String ptraceout = props.getProperty("traceout");
+		traceout = null;
+		if (ptraceout != null) {
+			if (ptraceout.equals("System.out")) {
+				traceout = System.out;
+			} else if (ptraceout.equals("System.err")) {
+				traceout = System.err;
+			} else {
+				// TODO instanciante the class with the name	
+				System.err.println("custom trace is not implemented !");
+			}
+		} else {
+			traceout = null;
+		}
+
+		String polldelayprops = props.getProperty("poll.delay");
+		pollDelay = 1000; // default 1000 millisec
+		if (polldelayprops != null) {
+			pollDelay = Integer.parseInt(polldelayprops);
+		}
+
+		String propsmin = props.getProperty("measurement.min");
+		min = 273.0;
+		if (propsmin != null) {
+			min = Double.parseDouble(propsmin);
+		}
+
+		String propmax = props.getProperty("measurement.max");
+		max = 293.0;
+		if (propmax != null) {
+			max = Double.parseDouble(propmax);
+		}
+
+		String propserror = props.getProperty("measurement.error");
+		error = 0.5;
+		if (propsmin != null) {
+			error = Double.parseDouble(propserror);
+		}
+		String propsunit = props.getProperty("measurement.unit");
+		if(propsunit==null){
+		    unit=Unit.K;
+		} else {
+		    unit = UnitUtil.getUnitFromString(propsunit);
+		}
+		
+		String periodprops = props.getProperty("measurement.sinusperiod");
+		pollDelay = 120000; // default 1000 millisec
+		if (periodprops != null) {
+			period = Long.parseLong(periodprops);
+		}
+
+		
+	}
+
+	
+	
+	/**
+	 * @see java.lang.Runnable#run()
+	 */
+	public synchronized void run() {
+		while (!quit){
+			try {
+				Measurement measurement = getMeasurement();
+				for (int i = 0; wires != null && i < wires.length; i++) {
+					Wire wire = wires[i];
+					// check if wire is valid and connected ?
+					if (!wire.isConnected() || !wire.isValid())
+						continue;
+					Object obj=polled(wire,measurement);
+					// TODO : respect the control flow specified by the consumer
+					if(obj!=null) wire.update(obj);
+				}
+				Thread.sleep(pollDelay);
+			} catch (InterruptedException ie) {
+				/* will recheck quit */
+			}
+		}
+	}
+
+	/**
+	 * @see org.osgi.service.wireadmin.Producer#consumersConnected(org.osgi.service.wireadmin.Wire[])
+	 */
+	public synchronized void consumersConnected(Wire wires[]) {
+		this.wires = wires;
+	}
+
+	/**
+	 * @see org.osgi.service.wireadmin.Producer#polled(org.osgi.service.wireadmin.Wire)
+	 */
+	public Object polled(Wire wire) {
+		return polled(wire,getMeasurement());
+	}
+
+	private Object polled(Wire wire,Measurement measurement) {
+		Class clazzes[] = wire.getFlavors();
+		for (int i = 0; i < clazzes.length; i++) {
+			Class clazz = clazzes[i];
+			if (clazz.isAssignableFrom(Measurement.class))
+				return measurement;
+			if (clazz.isAssignableFrom(Double.class))
+				return new Double(measurement.getValue());
+			if (clazz.isAssignableFrom(String.class))
+				return measurement.toString();
+		}
+		return null;
+	}
+
+	/**
+	 * generate a random Measurement
+	 * @return
+	 */
+	private Measurement getMeasurement() {
+		long date=System.currentTimeMillis();
+		double value = min + ((max - min) * Math.sin((Math.PI*(date % period))/period));
+		return new Measurement(value, error, unit, date);
+	}
+
+	/**
+	 * @see org.osgi.framework.BundleActivator#start(org.osgi.framework.BundleContext)
+	 */
+	public void start(BundleContext bundleContext) throws Exception {
+		this.bundleContext=bundleContext;
+		
+		configure();
+		
+		Hashtable registrationProperties = new Hashtable();
+		registrationProperties.put(
+			org.osgi.service.wireadmin.WireConstants.WIREADMIN_PRODUCER_FLAVORS,
+			new Class[] { Measurement.class, Double.class, String.class });
+		registrationProperties.put(
+				org.osgi.framework.Constants.SERVICE_PID,
+				this.getClass().getPackage().getName());
+		registrationProperties.put(
+				Unit.class.getName(),
+				UnitUtil.getStringFromUnit(unit));
+		registrationProperties.put(
+				org.osgi.framework.Constants.SERVICE_DESCRIPTION,
+				"a simple Producer that poll Measurement objects");
+
+		serviceRegistration=bundleContext.registerService(Producer.class.getName(), this, registrationProperties);
+
+		quit = false;
+		new Thread(this).start();
+	}
+
+	/**
+	 * @see org.osgi.framework.BundleActivator#stop(org.osgi.framework.BundleContext)
+	 */
+	public void stop(BundleContext bundleContext) throws Exception {
+		this.quit = true;
+		serviceRegistration.unregister();
+	}
+}
\ No newline at end of file

Propchange: felix/sandbox/donsez/wireadmin.sample.fictivemeasurementproducer/src/main/java/org/apache/felix/sandbox/wireadmin/sample/fictivemeasurementproducer/MeasurementProducer.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: felix/sandbox/donsez/wireadmin.sample.fictivemeasurementproducer/src/main/resources/config.properties
URL: http://svn.apache.org/viewvc/felix/sandbox/donsez/wireadmin.sample.fictivemeasurementproducer/src/main/resources/config.properties?rev=612292&view=auto
==============================================================================
--- felix/sandbox/donsez/wireadmin.sample.fictivemeasurementproducer/src/main/resources/config.properties (added)
+++ felix/sandbox/donsez/wireadmin.sample.fictivemeasurementproducer/src/main/resources/config.properties Tue Jan 15 15:05:25 2008
@@ -0,0 +1,12 @@
+
+# poll delay
+poll.delay=5000
+
+# measurement parameter for generation
+measurement.max=283.0
+measurement.min=273.0
+measurement.error=0.25
+measurement.unit=K
+
+# period in millisec for sinusoïdal curve 
+measurement.sinusperiod=120000

Propchange: felix/sandbox/donsez/wireadmin.sample.fictivemeasurementproducer/src/main/resources/config.properties
------------------------------------------------------------------------------
    svn:eol-style = native

Added: felix/sandbox/donsez/wireadmin.sample.fictivemeasurementproducer/src/site/readme.html
URL: http://svn.apache.org/viewvc/felix/sandbox/donsez/wireadmin.sample.fictivemeasurementproducer/src/site/readme.html?rev=612292&view=auto
==============================================================================
--- felix/sandbox/donsez/wireadmin.sample.fictivemeasurementproducer/src/site/readme.html (added)
+++ felix/sandbox/donsez/wireadmin.sample.fictivemeasurementproducer/src/site/readme.html Tue Jan 15 15:05:25 2008
@@ -0,0 +1,72 @@
+<html>
+<head>
+<title>Fictive Measurement Producer</title>
+</head>
+<body>
+
+<hr width="100%" size="2">
+<h1><i><a name="org.apache.felix.sandbox.wireadmin.sample.fictivemeasurementproducer"></a><font color="#0000aa">Fictive Measurement Producer</font></i></h1>
+
+<p>
+<b>Description</b><br>
+This bundle provides a simple Producer service which poll fictive Measurement objects (according a function sine)
+</p>
+
+<p>
+<b>Contributors</b><br>
+Apache Project Team
+</p>
+
+<p>
+<b>License</b><br>
+ASL2<br>
+</p>
+
+<p>
+<b>Services</b><br>
+<code>org.osgi.service.wireadmin.Producer</code>
+</p>
+
+<p>
+<b>Properties</b><br>
+service.pid=org.apache.felix.sandbox.wireadmin.sample.fictivemeasurementproducer<br>
+wireadmin.producer.flavors=class org.osgi.util.measurement.Measurement,class java.lang.String<br>
+<br>
+</p>
+
+<p><b>Requirements</b><br>
+<ul>
+<li>org.osgi.service.wireadmin; version=1.0</li>
+<li>org.osgi.util.measurement; version=1.0</li>
+</ul>
+</p>
+
+
+<hr width="100%" size="2">
+
+
+<p>
+<b>Build</b><br>
+<ol>
+<li>setup the properties in src/main/resources/config.properties</li>
+<li>then build with Maven 2: <code>mvn clean install</code></li>
+</ol>
+</p>
+
+
+<p>
+<b>Tested gateways</b><br>
+<ul>
+<li>Objectweb Oscar (done)</li>
+<li>Apache Felix (done)</li>
+</ul>
+</p>
+
+<p>
+<b>TODO (contributions are welcome)</b><br>
+<ul>
+</ul>
+</p>
+
+</body>
+</html>

Propchange: felix/sandbox/donsez/wireadmin.sample.fictivemeasurementproducer/src/site/readme.html
------------------------------------------------------------------------------
    svn:eol-style = native