servicemix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gno...@apache.org
Subject svn commit: r1133885 - /servicemix/smx4/specs/trunk/locator/src/main/java/org/apache/servicemix/specs/locator/OsgiLocator.java
Date Thu, 09 Jun 2011 14:22:05 GMT
Author: gnodet
Date: Thu Jun  9 14:22:04 2011
New Revision: 1133885

URL: http://svn.apache.org/viewvc?rev=1133885&view=rev
Log:
[SMX4-860] ServiceMix specs should wait for an implementation for a certain amount of time
when in OSGi

Modified:
    servicemix/smx4/specs/trunk/locator/src/main/java/org/apache/servicemix/specs/locator/OsgiLocator.java

Modified: servicemix/smx4/specs/trunk/locator/src/main/java/org/apache/servicemix/specs/locator/OsgiLocator.java
URL: http://svn.apache.org/viewvc/servicemix/smx4/specs/trunk/locator/src/main/java/org/apache/servicemix/specs/locator/OsgiLocator.java?rev=1133885&r1=1133884&r2=1133885&view=diff
==============================================================================
--- servicemix/smx4/specs/trunk/locator/src/main/java/org/apache/servicemix/specs/locator/OsgiLocator.java
(original)
+++ servicemix/smx4/specs/trunk/locator/src/main/java/org/apache/servicemix/specs/locator/OsgiLocator.java
Thu Jun  9 14:22:04 2011
@@ -59,6 +59,9 @@ public class OsgiLocator {
                 factories.put(id, l);
             }
             l.add(0, factory);
+            synchronized (lock) {
+                lock.notifyAll();
+            }
         } finally {
             lock.writeLock().unlock();
         }
@@ -70,6 +73,30 @@ public class OsgiLocator {
     }
 
     public static <T> Class<? extends T> locate(Class<T> factoryClass,
String factoryId) {
+        long timeout = 5000;
+        long t0 = -1;
+        long t1 = t0;
+        while (t1 - t0 < timeout) {
+            Class<? extends T> impl = doLocate(factoryClass, factoryId);
+            if (impl != null) {
+                return impl;
+            }
+            if (t0 == -1) {
+                t0 = t1 = System.currentTimeMillis();
+            }
+            synchronized (lock) {
+                try {
+                    lock.wait(timeout - (t1 - t0));
+                } catch (InterruptedException e) {
+                    return null;
+                }
+            }
+            t1 = System.currentTimeMillis();
+        }
+        return null;
+    }
+
+    private static <T> Class<? extends T> doLocate(Class<T> factoryClass,
String factoryId) {
         lock.readLock().lock();
         try {
             if (factories != null) {



Mime
View raw message