Author: slaws
Date: Mon Jan 21 08:45:36 2008
New Revision: 613927

URL: http://svn.apache.org/viewvc?rev=613927&view=rev
Log:
TUSCANY-1987
A work around to some synchronization issues in Felix. 

Modified:
    
incubator/tuscany/java/sca/itest/osgi-implementation/src/main/java/conversation/client/ConversationalClientActivator.java
    
incubator/tuscany/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/invocation/OSGiImplementationProvider.java
    
incubator/tuscany/java/sca/modules/osgi-runtime/src/main/java/org/apache/tuscany/sca/osgi/runtime/FelixRuntime.java

Modified: 
incubator/tuscany/java/sca/itest/osgi-implementation/src/main/java/conversation/client/ConversationalClientActivator.java
URL: 
http://svn.apache.org/viewvc/incubator/tuscany/java/sca/itest/osgi-implementation/src/main/java/conversation/client/ConversationalClientActivator.java?rev=613927&r1=613926&r2=613927&view=diff
==============================================================================
--- 
incubator/tuscany/java/sca/itest/osgi-implementation/src/main/java/conversation/client/ConversationalClientActivator.java
 (original)
+++ 
incubator/tuscany/java/sca/itest/osgi-implementation/src/main/java/conversation/client/ConversationalClientActivator.java
 Mon Jan 21 08:45:36 2008
@@ -55,7 +55,7 @@
         Hashtable<String, Object> serviceProps;
         
         serviceProps = new Hashtable<String, Object>();
-        
+         
         serviceProps.put("component.name", 
"ConversationalStatelessClientStatelessService");
         Object statelessClientFactory1 = 
             new 
ConversationalClientServiceFactory(ConversationalClientStatelessImpl.class, 
bundleContext, 1);
@@ -74,6 +74,7 @@
                 serviceProps);
         
             
+        serviceProps = new Hashtable<String, Object>();
         serviceProps.put("component.name", 
"ConversationalStatefulClientStatelessService");
         Object statefulClientFactory1 = 
             new 
ConversationalClientServiceFactory(ConversationalClientStatefulImpl.class, 
bundleContext, 3);
@@ -91,21 +92,6 @@
                 statefulClientFactory2, 
                 serviceProps);
       
-        serviceProps.put("component.name", "ConversationalReferenceClient");
-        ConversationalReferenceClientImpl refClient = new 
ConversationalReferenceClientImpl();
-        
bundleContext.registerService(ConversationalReferenceClient.class.getName(), 
refClient, serviceProps);
-        
-        serviceProps = new Hashtable<String, Object>();
-        serviceProps.put("component.name", "ConversationalServiceStateful");
-        Object statefulService = 
-            new 
ConversationalClientServiceFactory(ConversationalServiceStatefulImpl.class, 
bundleContext, 5);
-        bundleContext.registerService(ConversationalService.class.getName(), 
statefulService, serviceProps);
-        
-        serviceProps = new Hashtable<String, Object>();
-        serviceProps.put("component.name", "ConversationalServiceStateless");
-        ConversationalServiceStatelessImpl statelessService = new 
ConversationalServiceStatelessImpl();
-        bundleContext.registerService(ConversationalService.class.getName(), 
statelessService, serviceProps);
-        
         
     }
     

Modified: 
incubator/tuscany/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/invocation/OSGiImplementationProvider.java
URL: 
http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/invocation/OSGiImplementationProvider.java?rev=613927&r1=613926&r2=613927&view=diff
==============================================================================
--- 
incubator/tuscany/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/invocation/OSGiImplementationProvider.java
 (original)
+++ 
incubator/tuscany/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/invocation/OSGiImplementationProvider.java
 Mon Jan 21 08:45:36 2008
@@ -173,6 +173,7 @@
             
bundleContext.getServiceReference("org.osgi.service.packageadmin.PackageAdmin");
         if (packageAdminReference != null) {
             packageAdmin = (PackageAdmin) 
bundleContext.getService(packageAdminReference);
+            bundleContext.addFrameworkListener(this);
         }
         
         
@@ -333,7 +334,7 @@
                 
                 resolveBundle();
                 
-                processAnnotations();
+                processAnnotations(true);
                 
                 
                 for (Bundle bundle : dependentBundles) {
@@ -547,20 +548,7 @@
         bundle.start();
         
         if (existingBundle != null && packageAdmin != null) {
-            
-
-            bundleContext.addFrameworkListener(this);
-                      
-            packagesRefreshed = false;
-            packageAdmin.refreshPackages(null);
-                        
-            synchronized (this) {
-                if (!packagesRefreshed) {
-                    this.wait(2000);
-                }
-            }            
-            packagesRefreshed = false;
-            bundleContext.removeFrameworkListener(this);
+            refreshPackages();
             
         }
 
@@ -826,6 +814,25 @@
         
     }
     
+    private void refreshPackages() {
+    
+        if (packageAdmin != null) {
+            synchronized (this) {
+                packagesRefreshed = false;
+                packageAdmin.refreshPackages(null);
+                        
+                if (!packagesRefreshed) {
+                       try {
+                        this.wait(2000);
+                       } catch (InterruptedException e) {
+                               // ignore
+                       }
+                }
+                packagesRefreshed = false;
+            }                       
+        }
+    }
+    
     
     private void resolveBundle() throws ObjectCreationException {
         
@@ -893,6 +900,8 @@
                     }
                     index++;
                 }
+
+                refreshPackages();
                 
                 
                 index = 0;
@@ -1085,57 +1094,55 @@
         setReferencesAndProperties();
     }
         
-    public void processAnnotations() throws IntrospectionException {
+    public void processAnnotations(boolean doWait) throws 
IntrospectionException {
         
-        synchronized (this) {       
-            if (processedResolvedBundle || processingResolvedBundle)
+        synchronized (this) {   
+            if (processedResolvedBundle)
                 return;
+            else if (processingResolvedBundle) {               
+                if (doWait) {
+                    while (processingResolvedBundle) {
+                        try {
+                            wait(5000);
+                        } catch (InterruptedException e) {
+                        }
+                    }
+                }
+                return;
+            }
             processingResolvedBundle = true;
         }
         
-        osgiAnnotations.processAnnotations();
+        try {
+            osgiAnnotations.processAnnotations();
         
-        Scope scope = osgiAnnotations.getScope();
-        if (scope.equals(Scope.SYSTEM) || scope.equals(Scope.COMPOSITE)) {
-            // Nothing
-        } else {
+            Scope scope = osgiAnnotations.getScope();
+            if (scope.equals(Scope.SYSTEM) || scope.equals(Scope.COMPOSITE)) {
+                // Nothing
+            } else {
 
-            if (runtimeComponent instanceof ScopedRuntimeComponent) {
+                if (runtimeComponent instanceof ScopedRuntimeComponent) {
 
-                ScopedRuntimeComponent component = (ScopedRuntimeComponent) 
runtimeComponent;
+                    ScopedRuntimeComponent component = 
(ScopedRuntimeComponent) runtimeComponent;
 
-                ScopeContainer oldScopeContainer = 
component.getScopeContainer();
-                component.setScopeContainer(null);
-                ScopeContainer scopeContainer = 
scopeRegistry.getScopeContainer(runtimeComponent);
-
-                if (oldScopeContainer != null && 
oldScopeContainer.getLifecycleState() == ScopeContainer.RUNNING) {
-                    scopeContainer.start();
-                }
-                
-                component.setScopeContainer(scopeContainer);
-            }
-
-            // Check for conversational contract if conversational scope
-//            if (scope.equals(Scope.CONVERSATION)) {
-//                boolean hasConversationalContract = false;
-//                for (Service serviceDef : implementation.getServices()) {
-//                    if (serviceDef.getInterfaceContract().getInterface()
-//                            .isConversational()) {
-//                        hasConversationalContract = true;
-//                        break;
-//                    }
-//                }
-//                if (!hasConversationalContract) {
-//                    Exception e = new NoConversationalContractException(
-//                            runtimeComponent.getName() + ":" + osgiBundle);
-//                    throw new RuntimeException(e);
-//                }
-//            }
-        }
-            
-        synchronized (this) {                
-            processedResolvedBundle = true;
-            this.notifyAll();
+                    ScopeContainer oldScopeContainer = 
component.getScopeContainer();
+                    component.setScopeContainer(null);
+                    ScopeContainer scopeContainer = 
scopeRegistry.getScopeContainer(runtimeComponent);
+
+                    if (oldScopeContainer != null && 
oldScopeContainer.getLifecycleState() == ScopeContainer.RUNNING) {
+                        scopeContainer.start();
+                    }
+                
+                    component.setScopeContainer(scopeContainer);
+                }
+
+            }
+        } finally {
+            synchronized (this) {                
+                processingResolvedBundle = false;
+                processedResolvedBundle = true;
+                this.notifyAll();
+            }
         }  
     }
     
@@ -1160,7 +1167,7 @@
     public void bundleChanged(BundleEvent event) {
         if (event.getType() == BundleEvent.RESOLVED && event.getBundle() == 
osgiBundle) {
             try {
-                processAnnotations();
+                processAnnotations(false);
             } catch (Throwable e) {
                 e.printStackTrace();
             }             

Modified: 
incubator/tuscany/java/sca/modules/osgi-runtime/src/main/java/org/apache/tuscany/sca/osgi/runtime/FelixRuntime.java
URL: 
http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/osgi-runtime/src/main/java/org/apache/tuscany/sca/osgi/runtime/FelixRuntime.java?rev=613927&r1=613926&r2=613927&view=diff
==============================================================================
--- 
incubator/tuscany/java/sca/modules/osgi-runtime/src/main/java/org/apache/tuscany/sca/osgi/runtime/FelixRuntime.java
 (original)
+++ 
incubator/tuscany/java/sca/modules/osgi-runtime/src/main/java/org/apache/tuscany/sca/osgi/runtime/FelixRuntime.java
 Mon Jan 21 08:45:36 2008
@@ -171,8 +171,17 @@
         bundleContext = null;
         instance = null;
         
+        // We could potentially use Felix.stopAndWait, but use timed wait for 
now because
+        // stopAndWait hangs with Felix 1.0.0
         if (felix instanceof Bundle) {
-            ((Bundle)felix).stop();
+            Bundle felixBundle = (Bundle)felix;
+            felixBundle.stop();
+            int retries = 50;
+            synchronized (felix) {
+                while (retries-- > 0 && felixBundle.getState() != 
Bundle.UNINSTALLED) {
+                    felix.wait(100);
+                }
+            }
         }
         else if (felix != null) {
             Method shutdownMethod = felixClass.getMethod("shutdown");



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to