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:56:03 UTC

svn commit: r640173 - in /felix/sandbox/donsez/wireadmin.sample.freevmmemproducer/src/main/java/org/apache/felix/sandbox: util/Configuration.java util/config/ util/config/Configuration.java wireadmin/sample/vmfreememproducer/VMFreeMemoryProducer.java

Author: donsez
Date: Sun Mar 23 00:56:02 2008
New Revision: 640173

URL: http://svn.apache.org/viewvc?rev=640173&view=rev
Log:
fix bug on synchronization and refactor util in util.config

Added:
    felix/sandbox/donsez/wireadmin.sample.freevmmemproducer/src/main/java/org/apache/felix/sandbox/util/config/
    felix/sandbox/donsez/wireadmin.sample.freevmmemproducer/src/main/java/org/apache/felix/sandbox/util/config/Configuration.java
      - copied, changed from r612122, felix/sandbox/donsez/wireadmin.sample.freevmmemproducer/src/main/java/org/apache/felix/sandbox/util/Configuration.java
Removed:
    felix/sandbox/donsez/wireadmin.sample.freevmmemproducer/src/main/java/org/apache/felix/sandbox/util/Configuration.java
Modified:
    felix/sandbox/donsez/wireadmin.sample.freevmmemproducer/src/main/java/org/apache/felix/sandbox/wireadmin/sample/vmfreememproducer/VMFreeMemoryProducer.java

Copied: felix/sandbox/donsez/wireadmin.sample.freevmmemproducer/src/main/java/org/apache/felix/sandbox/util/config/Configuration.java (from r612122, felix/sandbox/donsez/wireadmin.sample.freevmmemproducer/src/main/java/org/apache/felix/sandbox/util/Configuration.java)
URL: http://svn.apache.org/viewvc/felix/sandbox/donsez/wireadmin.sample.freevmmemproducer/src/main/java/org/apache/felix/sandbox/util/config/Configuration.java?p2=felix/sandbox/donsez/wireadmin.sample.freevmmemproducer/src/main/java/org/apache/felix/sandbox/util/config/Configuration.java&p1=felix/sandbox/donsez/wireadmin.sample.freevmmemproducer/src/main/java/org/apache/felix/sandbox/util/Configuration.java&r1=612122&r2=640173&rev=640173&view=diff
==============================================================================
--- felix/sandbox/donsez/wireadmin.sample.freevmmemproducer/src/main/java/org/apache/felix/sandbox/util/Configuration.java (original)
+++ felix/sandbox/donsez/wireadmin.sample.freevmmemproducer/src/main/java/org/apache/felix/sandbox/util/config/Configuration.java Sun Mar 23 00:56:02 2008
@@ -16,7 +16,7 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-package org.apache.felix.sandbox.util;
+package org.apache.felix.sandbox.util.config;
 
 import java.io.FileInputStream;
 import java.io.InputStream;

Modified: felix/sandbox/donsez/wireadmin.sample.freevmmemproducer/src/main/java/org/apache/felix/sandbox/wireadmin/sample/vmfreememproducer/VMFreeMemoryProducer.java
URL: http://svn.apache.org/viewvc/felix/sandbox/donsez/wireadmin.sample.freevmmemproducer/src/main/java/org/apache/felix/sandbox/wireadmin/sample/vmfreememproducer/VMFreeMemoryProducer.java?rev=640173&r1=640172&r2=640173&view=diff
==============================================================================
--- felix/sandbox/donsez/wireadmin.sample.freevmmemproducer/src/main/java/org/apache/felix/sandbox/wireadmin/sample/vmfreememproducer/VMFreeMemoryProducer.java (original)
+++ felix/sandbox/donsez/wireadmin.sample.freevmmemproducer/src/main/java/org/apache/felix/sandbox/wireadmin/sample/vmfreememproducer/VMFreeMemoryProducer.java Sun Mar 23 00:56:02 2008
@@ -25,7 +25,7 @@
 import java.util.Hashtable;
 import java.util.Properties;
 
-import org.apache.felix.sandbox.util.Configuration;
+import org.apache.felix.sandbox.util.config.Configuration;
 import org.osgi.framework.BundleActivator;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.ServiceRegistration;
@@ -47,7 +47,7 @@
 public class VMFreeMemoryProducer implements Producer, Runnable, BundleActivator, ManagedService {
 
 	private static final String CONFIGFILE = "/config.properties";
-	private static final String PRODUCER_PID = "org.apache.felix.sandbox.wireadmin.sample.vmfreememory";
+	private static final String PRODUCER_PID = VMFreeMemoryProducer.class.getPackage().getName();
 	
 	private BundleContext bundleContext;
 	private Wire wires[];
@@ -58,7 +58,6 @@
 	private boolean quit=false;
 	private boolean pause=true;
 
-
 	/**
 	 * set the new set of Wires connected to this producers. This method is invoked by the WireAdmin service each time a wire is created or removed
 	 * @see org.osgi.service.wireadmin.Producer#consumersConnected(org.osgi.service.wireadmin.Wire[])
@@ -73,6 +72,7 @@
 	}
 
 	/**
+	 * invoke by the WireAdmin when the consumer polls an Object or when the WireAdmin polls an object according to wireadmin.filter property of the Wire
 	 * @param wire
 	 * @return
 	 * @see org.osgi.service.wireadmin.Producer#polled(org.osgi.service.wireadmin.Wire)
@@ -83,7 +83,7 @@
 	}
 
 	/**
-	 * Method producing a Object according to the consumer flavor priority
+	 * produce an Object according to the consumer flavor priority
 	 * @param wire
 	 * @param freemem
 	 * @param currentTimeMillis
@@ -131,7 +131,7 @@
 
 	
 	/**
-	 * Called upon starting of the bundle. This method invokes configure() which
+	 * called upon starting of the bundle. This method invokes configure() which
 	 * load the configuration file, registers the services
 	 *
 	 * @param   	bundleContext  The bundle bundleContext passed by the framework
@@ -158,7 +158,9 @@
 		
 		// start the thread
 		quit = false;
-		new Thread(this).start();
+		Thread thread=new Thread(this);
+		thread.setName(getClass().getPackage().getName());
+		thread.start();
 	}
 
 	/**
@@ -199,17 +201,23 @@
 	 * @see java.lang.Runnable#run()
 	 * TODO the thread could be "paused" until wires.lenght > 0
 	 */
-	public synchronized void run() {
+	public void run() {
 		while (!quit)
 			try {
-				long freemem = Runtime.getRuntime().freeMemory(); // consumers will received the same value for free memory
-				long currentTimeMillis = System.currentTimeMillis(); // and the same timestamp
-				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;
-					wire.update(polled(wire,freemem,currentTimeMillis));
+				if(!pause) {
+					long freemem = Runtime.getRuntime().freeMemory(); // consumers will received the same value for free memory
+					long currentTimeMillis = System.currentTimeMillis(); // and the same timestamp
+					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;
+							wire.update(polled(wire,freemem,currentTimeMillis));
+						}
+					};
+
 				}
 				Thread.sleep(pollDelay);
 			} catch (InterruptedException ie) {