felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From djen...@apache.org
Subject svn commit: r1424306 - in /felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/manager: DependencyManager.java ServiceTracker.java ServiceTrackerCustomizer.java
Date Thu, 20 Dec 2012 04:52:32 GMT
Author: djencks
Date: Thu Dec 20 04:52:32 2012
New Revision: 1424306

URL: http://svn.apache.org/viewvc?rev=1424306&view=rev
Log:
FELIX-3729 Revert to only one (removed) event for service removal

Modified:
    felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/manager/DependencyManager.java
    felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/manager/ServiceTracker.java
    felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/manager/ServiceTrackerCustomizer.java

Modified: felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/manager/DependencyManager.java
URL: http://svn.apache.org/viewvc/felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/manager/DependencyManager.java?rev=1424306&r1=1424305&r2=1424306&view=diff
==============================================================================
--- felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/manager/DependencyManager.java
(original)
+++ felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/manager/DependencyManager.java
Thu Dec 20 04:52:32 2012
@@ -188,6 +188,18 @@ public class DependencyManager<S, T> imp
             }
 
         }
+
+        protected void ungetService( RefPair<T> ref )
+        {
+            synchronized ( ref )
+            {
+                if ( ref.getServiceObject() != null )
+                {
+                    ref.setServiceObject( null );
+                    m_componentManager.getActivator().getBundleContext().ungetService( ref.getRef()
);
+                }
+            }
+        }
     }
 
 
@@ -211,10 +223,6 @@ public class DependencyManager<S, T> imp
         {
         }
 
-        public void removingService( ServiceReference<T> item, RefPair<T> object,
int size )
-        {
-        }
-
         public void removedService( ServiceReference<T> serviceReference, RefPair<T>
refPair )
         {
             if ( !isOptional() )
@@ -246,6 +254,8 @@ public class DependencyManager<S, T> imp
 
     private class MultipleDynamicCustomizer extends AbstractCustomizer {
 
+        private RefPair<T> lastRefPair;
+
         public RefPair<T> addingService( ServiceReference<T> serviceReference
)
         {
             RefPair<T> refPair = getPreviousRefMap().get( serviceReference );
@@ -289,28 +299,23 @@ public class DependencyManager<S, T> imp
             }
         }
 
-        public void removingService( ServiceReference<T> item, RefPair<T> refPair,
int size )
+        public void removedService( ServiceReference<T> serviceReference, RefPair<T>
refPair )
         {
             if ( isActive() )
             {
-                boolean unbind = isOptional() || size > 0;
+                boolean unbind = isOptional() || !getTracker().isEmpty();
                 if ( unbind )
                 {
                     m_componentManager.invokeUnbindMethod( DependencyManager.this, refPair
);
                 }
                 else
                 {
+                    lastRefPair = refPair;
                     m_componentManager.deactivateInternal( ComponentConstants.DEACTIVATION_REASON_REFERENCE,
false );
+                    lastRefPair = null;
                 }
             }
-        }
-
-        public void removedService( ServiceReference<T> serviceReference, RefPair<T>
refPair )
-        {
-            if (refPair.getServiceObject() != null)
-            {
-                m_componentManager.getActivator().getBundleContext().ungetService( serviceReference
);
-            }
+            ungetService( refPair );
         }
 
         public boolean open()
@@ -338,27 +343,28 @@ public class DependencyManager<S, T> imp
         {
             for ( RefPair<T> ref : getRefs() )
             {
-                if ( ref.getServiceObject() != null )
-                {
-                    ref.setServiceObject( null );
-                    m_componentManager.getActivator().getBundleContext().ungetService( ref.getRef()
);
-                }
+                ungetService( ref );
             }
             getTracker().deactivate();
         }
 
+
         public Collection<RefPair<T>> getRefs()
         {
-            return getTracker().getTracked( true ).values();
+            if ( lastRefPair == null )
+            {
+                return getTracker().getTracked( true ).values();
+            }
+            else
+            {
+                return Collections.singletonList( lastRefPair );
+            }
         }
     }
 
     private class MultipleStaticGreedyCustomizer extends AbstractCustomizer {
 
 
-        private final AtomicInteger reactivateCount = new AtomicInteger(  );
-
-
         public RefPair<T> addingService( ServiceReference<T> serviceReference
)
         {
             RefPair<T> refPair = new RefPair<T>( serviceReference  );
@@ -374,8 +380,8 @@ public class DependencyManager<S, T> imp
             if (isActive())
             {
                 m_componentManager.log( LogService.LOG_DEBUG,
-                    "Dependency Manager: Static dependency on {0}/{1} is broken", new Object[]
-                        { m_dependencyMetadata.getName(), m_dependencyMetadata.getInterface()
}, null );
+                        "Dependency Manager: Static dependency on {0}/{1} is broken", new
Object[]
+                        {m_dependencyMetadata.getName(), m_dependencyMetadata.getInterface()},
null );
                 m_componentManager.deactivateInternal( ComponentConstants.DEACTIVATION_REASON_REFERENCE,
false );
                 m_componentManager.activateInternal();
 
@@ -394,32 +400,20 @@ public class DependencyManager<S, T> imp
             }
         }
 
-        public void removingService( ServiceReference<T> item, RefPair<T> object,
int size )
+        public void removedService( ServiceReference<T> serviceReference, RefPair<T>
refPair )
         {
             if ( isActive() )
             {
                 //deactivate while ref is still tracked
-                    m_componentManager.log( LogService.LOG_DEBUG,
-                            "Dependency Manager: Static dependency on {0}/{1} is broken",
new Object[]
-                            {m_dependencyMetadata.getName(), m_dependencyMetadata.getInterface()},
null );
-                    m_componentManager.deactivateInternal( ComponentConstants.DEACTIVATION_REASON_REFERENCE,
false );
-                    reactivateCount.incrementAndGet();
-            }
-        }
-
-        public void removedService( ServiceReference<T> serviceReference, RefPair<T>
refPair )
-        {
-            if ( reactivateCount.getAndDecrement() > 0 )
-            {
+                m_componentManager.log( LogService.LOG_DEBUG,
+                        "Dependency Manager: Static dependency on {0}/{1} is broken", new
Object[]
+                        {m_dependencyMetadata.getName(), m_dependencyMetadata.getInterface()},
null );
+                m_componentManager.deactivateInternal( ComponentConstants.DEACTIVATION_REASON_REFERENCE,
false );
                 //try to reactivate after ref is no longer tracked.
                 m_componentManager.activateInternal();
-
             }
             //This is unlikely
-            if (refPair.getServiceObject() != null)
-            {
-                m_componentManager.getActivator().getBundleContext().ungetService( serviceReference
);
-            }
+            ungetService( refPair );
         }
 
         public boolean open()
@@ -440,11 +434,7 @@ public class DependencyManager<S, T> imp
         {
             for ( RefPair<T> ref: getRefs())
             {
-                if ( ref.getServiceObject() != null)
-                {
-                    ref.setServiceObject( null );
-                    m_componentManager.getActivator().getBundleContext().ungetService( ref.getRef()
);
-                }
+                ungetService( ref );
             }
             getTracker().deactivate();
         }
@@ -481,10 +471,6 @@ public class DependencyManager<S, T> imp
             }
         }
 
-        public void removingService( ServiceReference<T> item, RefPair<T> object,
int size )
-        {
-        }
-
         public void removedService( ServiceReference<T> serviceReference, RefPair<T>
refPair )
         {
             if ( isActive() )
@@ -502,10 +488,7 @@ public class DependencyManager<S, T> imp
 
                 }
             }
-            if (refPair.getServiceObject() != null)
-            {
-                m_componentManager.getActivator().getBundleContext().ungetService( serviceReference
);
-            }
+            ungetService( refPair );
         }
 
         public boolean open()
@@ -527,11 +510,7 @@ public class DependencyManager<S, T> imp
         {
             for ( RefPair<T> ref: getRefs())
             {
-                if ( ref.getServiceObject() != null)
-                {
-                    ref.setServiceObject( null );
-                    m_componentManager.getActivator().getBundleContext().ungetService( ref.getRef()
);
-                }
+                ungetService( ref );
             }
             refs.clear();
             getTracker().deactivate();
@@ -593,10 +572,6 @@ public class DependencyManager<S, T> imp
             }
         }
 
-        public void removingService( ServiceReference<T> item, RefPair<T> object,
int size )
-        {
-        }
-
         public void removedService( ServiceReference<T> serviceReference, RefPair<T>
refPair )
         {
             if (refPair == this.refPair)
@@ -666,10 +641,9 @@ public class DependencyManager<S, T> imp
 
         private void closeRefPair()
         {
-            if ( refPair != null && refPair.getServiceObject() != null )
+            if ( refPair != null )
             {
-                refPair.setServiceObject( null );
-                m_componentManager.getActivator().getBundleContext().ungetService( refPair.getRef()
);
+                ungetService( refPair );
             }
             refPair = null;
         }
@@ -715,10 +689,6 @@ public class DependencyManager<S, T> imp
             }
         }
 
-        public void removingService( ServiceReference<T> item, RefPair<T> object,
int size )
-        {
-        }
-
         public void removedService( ServiceReference<T> serviceReference, RefPair<T>
refPair )
         {
             if ( isActive() && refPair == this.refPair )
@@ -749,10 +719,9 @@ public class DependencyManager<S, T> imp
 
         public void close()
         {
-            if ( refPair != null && refPair.getServiceObject() != null )
+            if ( refPair != null )
             {
-                refPair.setServiceObject( null );
-                m_componentManager.getActivator().getBundleContext().ungetService( refPair.getRef()
);
+                ungetService( refPair );
             }
             refPair = null;
             getTracker().deactivate();

Modified: felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/manager/ServiceTracker.java
URL: http://svn.apache.org/viewvc/felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/manager/ServiceTracker.java?rev=1424306&r1=1424305&r2=1424306&view=diff
==============================================================================
--- felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/manager/ServiceTracker.java (original)
+++ felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/manager/ServiceTracker.java Thu
Dec 20 04:52:32 2012
@@ -1001,11 +1001,6 @@ public class ServiceTracker<S, T> {
         private final LinkedList<S> initial;
 
         /**
-         * counter to show size after removed during remmoving event.
-         */
-        private int pendingRemovals;
-
-        /**
          * AbstractTracked constructor.
          */
         AbstractTracked() {
@@ -1234,21 +1229,7 @@ public class ServiceTracker<S, T> {
                              * adding
                              */
                 }
-                object = tracked.get( item );
-                if (object == null) {
-                    //this can happen if a service is removed concurrently with tracker.close().
-                    return;
-                }
-                pendingRemovals++;
-                size = tracked.size() - pendingRemovals;
-            }
-            /* Call customizer outside of synchronized region */
-            customizerRemoving(item, related, object, size );
-            synchronized (this) {
-                pendingRemovals--;
-
-                tracked.remove(item); /*
-                                                 * must remove from tracker before
+                object = tracked.remove(item); /*                                       
         * must remove from tracker before
                                                  * calling customizer callback
                                                  */
                 modified(); /* increment modification count */
@@ -1375,8 +1356,6 @@ public class ServiceTracker<S, T> {
          */
         abstract void customizerModified(final S item, final R related, final T object);
 
-        abstract void customizerRemoving( final S item, final R related, final T object,
int size );
-
         /**
          * Call the specific customizer removed method. This method must not be
          * called while synchronized on this object.
@@ -1482,12 +1461,6 @@ public class ServiceTracker<S, T> {
 			customizer.modifiedService(item, object);
 		}
 
-        @Override
-        void customizerRemoving( ServiceReference<S> item, ServiceEvent related, T
object, int size )
-        {
-            customizer.removingService( item, object, size );
-        }
-
         /**
 		 * Call the specific customizer removed method. This method must not be
 		 * called while synchronized on this object.

Modified: felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/manager/ServiceTrackerCustomizer.java
URL: http://svn.apache.org/viewvc/felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/manager/ServiceTrackerCustomizer.java?rev=1424306&r1=1424305&r2=1424306&view=diff
==============================================================================
--- felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/manager/ServiceTrackerCustomizer.java
(original)
+++ felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/manager/ServiceTrackerCustomizer.java
Thu Dec 20 04:52:32 2012
@@ -81,8 +81,6 @@ public interface ServiceTrackerCustomize
 	 */
 	public void modifiedService(ServiceReference<S> reference, T service);
 
-    void removingService( ServiceReference<S> item, T object, int size );
-
 	/**
 	 * A service tracked by the {@code ServiceTracker} has been removed.
 	 * 



Mime
View raw message