felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From djen...@apache.org
Subject svn commit: r1470396 - /felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/manager/ImmediateComponentManager.java
Date Mon, 22 Apr 2013 06:44:31 GMT
Author: djencks
Date: Mon Apr 22 06:44:30 2013
New Revision: 1470396

URL: http://svn.apache.org/r1470396
Log:
FELIX-4020 fix the circular reference tests by detecting circular reference earlier and returning
null immediately

Modified:
    felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/manager/ImmediateComponentManager.java

Modified: felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/manager/ImmediateComponentManager.java
URL: http://svn.apache.org/viewvc/felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/manager/ImmediateComponentManager.java?rev=1470396&r1=1470395&r2=1470396&view=diff
==============================================================================
--- felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/manager/ImmediateComponentManager.java
(original)
+++ felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/manager/ImmediateComponentManager.java
Mon Apr 22 06:44:30 2013
@@ -72,7 +72,9 @@ public class ImmediateComponentManager<S
     
     private volatile long m_changeCount = -1;
 
-    /**
+    private final ThreadLocal<Boolean> m_circularReferences = new ThreadLocal<Boolean>();
+    
+   /**
      * The constructor receives both the activator and the metadata
      *
      * @param activator
@@ -710,58 +712,71 @@ public class ImmediateComponentManager<S
         }
     }
 
+    
     @Override
     boolean getServiceInternal()
     {
-        boolean success = true;
-        if ( m_componentContext == null )
+        if (m_circularReferences.get() != null)
         {
-            try
+            return false;             
+        }
+        m_circularReferences.set( Boolean.TRUE );
+        try
+        {
+            boolean success = true;
+            if ( m_componentContext == null )
             {
-                if ( !collectDependencies() )
+                try
                 {
-                    log(
-                            LogService.LOG_DEBUG,
-                            "getService did not win collecting dependencies, try creating
object anyway.",
-                            null );
+                    if ( !collectDependencies() )
+                    {
+                        log(
+                                LogService.LOG_DEBUG,
+                                "getService did not win collecting dependencies, try creating
object anyway.",
+                                null );
 
+                    }
+                    else
+                    {
+                        log(
+                                LogService.LOG_DEBUG,
+                                "getService won collecting dependencies, proceed to creating
object.",
+                                null );
+
+                    }
                 }
-                else
+                catch ( IllegalStateException e )
                 {
                     log(
-                            LogService.LOG_DEBUG,
-                            "getService won collecting dependencies, proceed to creating
object.",
+                            LogService.LOG_INFO,
+                            "Could not obtain all required dependencies, getService returning
null",
                             null );
-
+                    success = false;
                 }
-            }
-            catch ( IllegalStateException e )
-            {
-                log(
-                        LogService.LOG_INFO,
-                        "Could not obtain all required dependencies, getService returning
null",
-                        null );
-                success = false;
-            }
-            obtainWriteLock( "ImmediateComponentManager.getService.1" );
-            try
-            {
-                if ( m_componentContext == null )
+                obtainWriteLock( "ImmediateComponentManager.getService.1" );
+                try
                 {
-                    //state should be "Registered"
-                    S result = (S) state().getService( this );
-                    if ( result == null )
+                    if ( m_componentContext == null )
                     {
-                        success = false;;
+                        //state should be "Registered"
+                        S result = (S) state().getService( this );
+                        if ( result == null )
+                        {
+                            success = false;;
+                        }
                     }
                 }
+                finally
+                {
+                    releaseWriteLock( "ImmediateComponentManager.getService.1" );
+                }
             }
-            finally
-            {
-                releaseWriteLock( "ImmediateComponentManager.getService.1" );
-            }
+            return success;
+        }
+        finally
+        {
+            m_circularReferences.remove();
         }
-        return success;
     }
 
     public void ungetService( Bundle bundle, ServiceRegistration<S> serviceRegistration,
S o )



Mime
View raw message