/*
 * Copyright 2012 The Netty Project
 *
 * The Netty Project licenses this file to you under the Apache License,
 * version 2.0 (the "License"); you may not use this file except in compliance
 * with the License. You may obtain a copy of the License at:
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations
 * under the License.
 */
package io.netty.logging;

import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceReference;
import org.osgi.service.log.LogService;
import org.osgi.util.tracker.ServiceTracker;

/**
 * Logger factory which creates an <a href="http://www.osgi.org/">OSGi</a>
 * {@link LogService} logger.
 */
public class OsgiLoggerFactory extends InternalLoggerFactory {

    private final ServiceTracker<LogService, LogService> logServiceTracker;
    private final InternalLoggerFactory fallback;
    volatile LogService logService;

    public OsgiLoggerFactory(BundleContext ctx) {
        this(ctx, null);
    }

    public OsgiLoggerFactory(BundleContext ctx, InternalLoggerFactory fallback) {
        if (ctx == null) {
            throw new NullPointerException("ctx");
        }
        if (fallback == null) {
            fallback = InternalLoggerFactory.getDefaultFactory();
            if (fallback instanceof OsgiLoggerFactory) {
                fallback = new JdkLoggerFactory();
            }
        }

        this.fallback = fallback;
        logServiceTracker = new ServiceTracker<LogService, LogService>(
                ctx, "org.osgi.service.log.LogService", null) {
                    @Override
                    public LogService addingService(ServiceReference<LogService> reference) {
                        LogService service = super.addingService(reference);
                        logService = service;
                        return service;
                    }

                    @Override
                    public void removedService(ServiceReference<LogService> reference, LogService service) {
                        logService = null;
                    }
        };
        logServiceTracker.open();
    }

    public InternalLoggerFactory getFallback() {
        return fallback;
    }

    public LogService getLogService() {
        return logService;
    }

    public void destroy() {
        logService = null;
        logServiceTracker.close();
    }

    @Override
    public InternalLogger newInstance(String name) {
        return new OsgiLogger(this, name, fallback.newInstance(name));
    }
}

@@ -939,16 +939,41 @@
 er.%0A */%0A
+@SuppressWarnings(%22all%22)%0A
 public c
@@ -1064,32 +1064,8 @@
 cker
-%3CLogService, LogService%3E
  log
@@ -1734,34 +1734,10 @@
 cker
-%3CLogService, LogService%3E
 (%0A
+
     
@@ -1853,26 +1853,22 @@
  public 
-LogService
+Object
  addingS
@@ -1886,36 +1886,24 @@
 iceReference
-%3CLogService%3E
  reference) 
@@ -1948,16 +1948,29 @@
 ervice =
+ (LogService)
  super.a
@@ -2200,20 +2200,8 @@
 ence
-%3CLogService%3E
  ref
@@ -2208,26 +2208,22 @@
 erence, 
-LogService
+Object
  service

Fix a compilation error (sorry!)