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/03/23 08:53:25 UTC

svn commit: r640172 - /felix/sandbox/donsez/wireadmin.sample.fictivemeasurementproducer/src/main/java/org/apache/felix/sandbox/wireadmin/sample/fictivemeasurementproducer/MeasurementProducer.java

Author: donsez
Date: Sun Mar 23 00:53:24 2008
New Revision: 640172

URL: http://svn.apache.org/viewvc?rev=640172&view=rev
Log:
fix bug on synchronization

Modified:
    felix/sandbox/donsez/wireadmin.sample.fictivemeasurementproducer/src/main/java/org/apache/felix/sandbox/wireadmin/sample/fictivemeasurementproducer/MeasurementProducer.java

Modified: 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=640172&r1=640171&r2=640172&view=diff
==============================================================================
--- felix/sandbox/donsez/wireadmin.sample.fictivemeasurementproducer/src/main/java/org/apache/felix/sandbox/wireadmin/sample/fictivemeasurementproducer/MeasurementProducer.java (original)
+++ felix/sandbox/donsez/wireadmin.sample.fictivemeasurementproducer/src/main/java/org/apache/felix/sandbox/wireadmin/sample/fictivemeasurementproducer/MeasurementProducer.java Sun Mar 23 00:53:24 2008
@@ -40,9 +40,10 @@
  * 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
+ * TODO add ManagedService for CM
+ * TODO refactor to have a factory MeasurementProducerFactory with several configuration files
  */
 public class MeasurementProducer implements Producer, Runnable, BundleActivator {
 
@@ -139,8 +140,6 @@
 		if (periodprops != null) {
 			period = Long.parseLong(periodprops);
 		}
-
-		
 	}
 
 	
@@ -148,18 +147,20 @@
 	/**
 	 * @see java.lang.Runnable#run()
 	 */
-	public synchronized void run() {
+	public 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);
+				synchronized (this) {	
+					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) {
@@ -231,7 +232,9 @@
 		serviceRegistration=bundleContext.registerService(Producer.class.getName(), this, registrationProperties);
 
 		quit = false;
-		new Thread(this).start();
+		Thread thread=new Thread(this);
+		thread.setName(getClass().getPackage().getName());
+		thread.start();
 	}
 
 	/**