felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject svn commit: r1676459 - /felix/trunk/http/sslfilter/src/main/java/org/apache/felix/http/sslfilter/internal/LogServiceTracker.java
Date Tue, 28 Apr 2015 09:44:43 GMT
Author: cziegeler
Date: Tue Apr 28 09:44:43 2015
New Revision: 1676459

URL: http://svn.apache.org/r1676459
Log:
FELIX-4870 : sslfilter implementation assumes there is only one log service

Modified:
    felix/trunk/http/sslfilter/src/main/java/org/apache/felix/http/sslfilter/internal/LogServiceTracker.java

Modified: felix/trunk/http/sslfilter/src/main/java/org/apache/felix/http/sslfilter/internal/LogServiceTracker.java
URL: http://svn.apache.org/viewvc/felix/trunk/http/sslfilter/src/main/java/org/apache/felix/http/sslfilter/internal/LogServiceTracker.java?rev=1676459&r1=1676458&r2=1676459&view=diff
==============================================================================
--- felix/trunk/http/sslfilter/src/main/java/org/apache/felix/http/sslfilter/internal/LogServiceTracker.java
(original)
+++ felix/trunk/http/sslfilter/src/main/java/org/apache/felix/http/sslfilter/internal/LogServiceTracker.java
Tue Apr 28 09:44:43 2015
@@ -18,35 +18,55 @@
  */
 package org.apache.felix.http.sslfilter.internal;
 
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Map;
+import java.util.TreeMap;
+
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.ServiceReference;
 import org.osgi.service.log.LogService;
 import org.osgi.util.tracker.ServiceTracker;
 
 /**
- * TODO - this implementation assumes that there is exactly one LogService
+ *
  *
  * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
  */
 public class LogServiceTracker extends ServiceTracker
 {
+    private final Map<ServiceReference, LogService> logServices = new TreeMap<ServiceReference,
LogService>(Collections.reverseOrder());
+
     public LogServiceTracker(BundleContext context)
     {
         super(context, LogService.class.getName(), null);
     }
 
     @Override
-    public Object addingService(ServiceReference reference)
+    public Object addingService(final ServiceReference reference)
     {
-        LogService result = (LogService) super.addingService(reference);
-        SystemLogger.setLogService(result);
+        final LogService result = (LogService) super.addingService(reference);
+        if ( result != null ) {
+            synchronized ( logServices ) {
+                logServices.put(reference, result);
+                SystemLogger.setLogService(logServices.values().iterator().next());
+            }
+        }
         return result;
     }
 
     @Override
-    public void removedService(ServiceReference reference, Object service)
+    public void removedService(final ServiceReference reference, final Object service)
     {
-        SystemLogger.setLogService(null);
+        synchronized ( logServices ) {
+            logServices.remove(reference);
+            final Collection<LogService> services = logServices.values();
+            if ( services.isEmpty() ) {
+                SystemLogger.setLogService(null);
+            } else {
+                SystemLogger.setLogService(services.iterator().next());
+            }
+        }
         super.removedService(reference, service);
     }
 }



Mime
View raw message