incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From my...@apache.org
Subject svn commit: r1404723 - in /sling/trunk: bundles/commons/osgi/src/main/java/org/apache/sling/commons/osgi/SortingServiceTracker.java installer/core/pom.xml installer/core/src/main/java/org/apache/sling/installer/core/impl/SortingServiceTracker.java
Date Thu, 01 Nov 2012 18:53:12 GMT
Author: mykee
Date: Thu Nov  1 18:53:12 2012
New Revision: 1404723

URL: http://svn.apache.org/viewvc?rev=1404723&view=rev
Log:
SLING-2645 Move SortingServiceTracker from org.apache.sling.installer.core.impl to org.apache.sling.commons.osgi


Added:
    sling/trunk/bundles/commons/osgi/src/main/java/org/apache/sling/commons/osgi/SortingServiceTracker.java
      - copied, changed from r1402821, sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/SortingServiceTracker.java
Modified:
    sling/trunk/installer/core/pom.xml
    sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/SortingServiceTracker.java

Copied: sling/trunk/bundles/commons/osgi/src/main/java/org/apache/sling/commons/osgi/SortingServiceTracker.java
(from r1402821, sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/SortingServiceTracker.java)
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/commons/osgi/src/main/java/org/apache/sling/commons/osgi/SortingServiceTracker.java?p2=sling/trunk/bundles/commons/osgi/src/main/java/org/apache/sling/commons/osgi/SortingServiceTracker.java&p1=sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/SortingServiceTracker.java&r1=1402821&r2=1404723&rev=1404723&view=diff
==============================================================================
--- sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/SortingServiceTracker.java
(original)
+++ sling/trunk/bundles/commons/osgi/src/main/java/org/apache/sling/commons/osgi/SortingServiceTracker.java
Thu Nov  1 18:53:12 2012
@@ -16,14 +16,13 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-package org.apache.sling.installer.core.impl;
+package org.apache.sling.commons.osgi;
 
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collections;
 import java.util.List;
 
-import org.apache.sling.installer.api.tasks.RetryHandler;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.ServiceReference;
 import org.osgi.util.tracker.ServiceTracker;
@@ -35,8 +34,6 @@ import org.osgi.util.tracker.ServiceTrac
 public class SortingServiceTracker<T>
     extends ServiceTracker  {
 
-    private final RetryHandler listener;
-
     private int lastCount = -1;
 
     private int lastRefCount = -1;
@@ -49,10 +46,8 @@ public class SortingServiceTracker<T>
      * Constructor
      */
     public SortingServiceTracker(final BundleContext context,
-            final String clazz,
-            final RetryHandler listener) {
+            final String clazz) {
         super(context, clazz, null);
-        this.listener = listener;
     }
 
     /**
@@ -81,10 +76,6 @@ public class SortingServiceTracker<T>
     public Object addingService(ServiceReference reference) {
         this.sortedServiceCache = null;
         this.sortedReferences = null;
-        if ( listener != null ) {
-            // new factory or resource transformer has been added, wake up main thread
-            this.listener.scheduleRetry();
-        }
         return context.getService(reference);
     }
 

Modified: sling/trunk/installer/core/pom.xml
URL: http://svn.apache.org/viewvc/sling/trunk/installer/core/pom.xml?rev=1404723&r1=1404722&r2=1404723&view=diff
==============================================================================
--- sling/trunk/installer/core/pom.xml (original)
+++ sling/trunk/installer/core/pom.xml Thu Nov  1 18:53:12 2012
@@ -140,7 +140,7 @@
         <dependency>
             <groupId>org.apache.sling</groupId>
             <artifactId>org.apache.sling.commons.osgi</artifactId>
-            <version>2.1.0</version>
+            <version>2.1.1-SNAPSHOT</version>
             <scope>provided</scope>
         </dependency>
       <!-- We use a class from the config admin implementation to read config files -->

Modified: sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/SortingServiceTracker.java
URL: http://svn.apache.org/viewvc/sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/SortingServiceTracker.java?rev=1404723&r1=1404722&r2=1404723&view=diff
==============================================================================
--- sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/SortingServiceTracker.java
(original)
+++ sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/SortingServiceTracker.java
Thu Nov  1 18:53:12 2012
@@ -18,121 +18,37 @@
  */
 package org.apache.sling.installer.core.impl;
 
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.List;
-
 import org.apache.sling.installer.api.tasks.RetryHandler;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.ServiceReference;
-import org.osgi.util.tracker.ServiceTracker;
 
-/**
- * Implementation providing a sorted list of services
- * by service ranking.
- */
-public class SortingServiceTracker<T>
-    extends ServiceTracker  {
+public class SortingServiceTracker<T> extends
+        org.apache.sling.commons.osgi.SortingServiceTracker<T> {
 
     private final RetryHandler listener;
 
-    private int lastCount = -1;
-
-    private int lastRefCount = -1;
-
-    private List<T> sortedServiceCache;
-
-    private List<ServiceReference> sortedReferences;
-
     /**
      * Constructor
      */
     public SortingServiceTracker(final BundleContext context,
             final String clazz,
             final RetryHandler listener) {
-        super(context, clazz, null);
+        super(context, null);
         this.listener = listener;
     }
-
-    /**
-     * @see org.osgi.util.tracker.ServiceTracker#removedService(org.osgi.framework.ServiceReference,
java.lang.Object)
-     */
-    @Override
-    public void removedService(ServiceReference reference, Object service) {
-        this.sortedServiceCache = null;
-        this.sortedReferences = null;
-        this.context.ungetService(reference);
-    }
-
-    /**
-     * @see org.osgi.util.tracker.ServiceTrackerCustomizer#modifiedService(org.osgi.framework.ServiceReference,
java.lang.Object)
-     */
-    @Override
-    public void modifiedService(ServiceReference reference, Object service) {
-        this.sortedServiceCache = null;
-        this.sortedReferences = null;
-    }
-
+    
     /**
      * @see org.osgi.util.tracker.ServiceTrackerCustomizer#addingService(org.osgi.framework.ServiceReference)
      */
     @Override
     public Object addingService(ServiceReference reference) {
-        this.sortedServiceCache = null;
-        this.sortedReferences = null;
+        Object returnValue = super.addingService(reference);
         if ( listener != null ) {
             // new factory or resource transformer has been added, wake up main thread
             this.listener.scheduleRetry();
         }
-        return context.getService(reference);
+        return returnValue;
     }
 
-    /**
-     * Return a sorted list of the services.
-     */
-    public List<T> getSortedServices() {
-        List<T> result = this.sortedServiceCache;
-        if ( result == null || this.lastCount < this.getTrackingCount() ) {
-            this.lastCount = this.getTrackingCount();
-            final ServiceReference[] references = this.getServiceReferences();
-            if ( references == null || references.length == 0 ) {
-                result = Collections.emptyList();
-            } else {
-                Arrays.sort(references);
-                result = new ArrayList<T>();
-                for(int i=0;i<references.length;i++) {
-                    @SuppressWarnings("unchecked")
-                    final T service = (T)this.getService(references[references.length - 1
- i]);
-                    if ( service != null ) {
-                        result.add(service);
-                    }
-                }
-            }
-            this.sortedServiceCache = result;
-        }
-        return result;
-    }
-
-    /**
-     * Return a sorted list of the services references.
-     */
-    public List<ServiceReference> getSortedServiceReferences() {
-        List<ServiceReference> result = this.sortedReferences;
-        if ( result == null || this.lastRefCount < this.getTrackingCount() ) {
-            this.lastRefCount = this.getTrackingCount();
-            final ServiceReference[] references = this.getServiceReferences();
-            if ( references == null || references.length == 0 ) {
-                result = Collections.emptyList();
-            } else {
-                Arrays.sort(references);
-                result = new ArrayList<ServiceReference>();
-                for(int i=0;i<references.length;i++) {
-                    result.add(references[references.length - 1 - i]);
-                }
-            }
-            this.sortedReferences = result;
-        }
-        return result;
-    }
+    
 }



Mime
View raw message