felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fmesc...@apache.org
Subject svn commit: r663930 - /felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/AbstractComponentManager.java
Date Fri, 06 Jun 2008 13:21:35 GMT
Author: fmeschbe
Date: Fri Jun  6 06:21:34 2008
New Revision: 663930

URL: http://svn.apache.org/viewvc?rev=663930&view=rev
Log:
FELIX-599 Mutliple changes to service registration locking:
- only log once (at info level) when waiting for the lock release
- wait at most 10 * 1 seconds
- unlock only allowed for the lock owner
- prevent calling the unlock method if lock acquisition failed

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

Modified: felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/AbstractComponentManager.java
URL: http://svn.apache.org/viewvc/felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/AbstractComponentManager.java?rev=663930&r1=663929&r2=663930&view=diff
==============================================================================
--- felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/AbstractComponentManager.java
(original)
+++ felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/AbstractComponentManager.java
Fri Jun  6 06:21:34 2008
@@ -680,10 +680,11 @@
 
     protected void unregisterComponentService()
     {
+        // outside of try-finally to not trigger inadvertend unlock
+        lockServiceRegistration();
+
         try
         {
-            lockServiceRegistration();
-
             if ( m_serviceRegistration != null )
             {
                 m_serviceRegistration.unregister();
@@ -736,28 +737,33 @@
     {
         synchronized ( serviceRegistrationLock )
         {
-            int waitGuard = 10;
-            while ( serviceRegistrationLockOwner != null && waitGuard > 0 )
+            if ( serviceRegistrationLockOwner != null )
             {
-                log( LogService.LOG_DEBUG, "Service Registration already locked by " + serviceRegistrationLockOwner
-                    + ", waiting for release", m_componentMetadata, null );
+                log( LogService.LOG_INFO, "Waiting for Service Registration owned " + serviceRegistrationLockOwner,
+                    m_componentMetadata, null );
 
-                // wait at most 10 seconds
-                try
+                int waitGuard = 10;
+                while ( serviceRegistrationLockOwner != null && waitGuard > 0
)
                 {
-                    serviceRegistrationLock.wait( 10L * 1000L );
+                    // wait at most one second
+                    try
+                    {
+                        serviceRegistrationLock.wait( 1000L );
+                    }
+                    catch ( InterruptedException ie )
+                    {
+                        // don't care
+                    }
+                    waitGuard--;
                 }
-                catch ( InterruptedException ie )
+
+                // timedout waiting for the service registration lock
+                if ( waitGuard <= 0 )
                 {
-                    // don't care
+                    throw new IllegalStateException( "Cannot get Service Registration, owned
by "
+                        + serviceRegistrationLockOwner );
                 }
-                waitGuard--;
-            }
 
-            // timedout waiting for the service registration lock
-            if ( waitGuard <= 0 )
-            {
-                throw new IllegalStateException( "Cannot get the service registration lock
!!" );
             }
 
             serviceRegistrationLockOwner = Thread.currentThread();
@@ -774,13 +780,22 @@
     {
         synchronized ( serviceRegistrationLock )
         {
-            log( LogService.LOG_DEBUG, "Service Registration released by " + serviceRegistrationLockOwner,
-                m_componentMetadata, null );
+            Thread current = Thread.currentThread();
+            if ( serviceRegistrationLockOwner == current )
+            {
+                log( LogService.LOG_DEBUG, "Service Registration released by " + serviceRegistrationLockOwner,
+                    m_componentMetadata, null );
 
-            serviceRegistrationLockOwner = null;
+                serviceRegistrationLockOwner = null;
 
-            // notify threads waiting to lock service registration
-            serviceRegistrationLock.notifyAll();
+                // notify threads waiting to lock service registration
+                serviceRegistrationLock.notifyAll();
+            }
+            else
+            {
+                log( LogService.LOG_DEBUG, "Not releasing Service Registration by " + current
+ ", owner is "
+                    + serviceRegistrationLockOwner, m_componentMetadata, null );
+            }
         }
     }
 
@@ -885,10 +900,11 @@
 
     ServiceReference getServiceReference()
     {
+        // outside of try-finally to not trigger inadvertend unlock
+        lockServiceRegistration();
+
         try
         {
-            lockServiceRegistration();
-            
             return ( m_serviceRegistration != null ) ? m_serviceRegistration.getReference()
: null;
         }
         finally



Mime
View raw message