View Javadoc

1   /*******************************************************************************
2    * Copyright (c) 2011 Michael Mimo Moratti.
3    *
4    * Michael Mimo Moratti licenses this file to you under the Apache License, version 2.0
5    * (the "License"); you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at:
7    *     http://www.apache.org/licenses/LICENSE-2.0
8    * Unless required by applicable law or agreed to in writing, software
9    * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
10   * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
11   * License for the specific language governing permissions and limitations
12   * under the License.
13   *******************************************************************************/
14  package ch.mimo.netty.icap.container.osgi;
15  
16  import org.jboss.netty.logging.InternalLoggerFactory;
17  import org.jboss.netty.logging.OsgiLoggerFactory;
18  import org.osgi.framework.BundleActivator;
19  import org.osgi.framework.BundleContext;
20  
21  /**
22   * OSGI bundle activator. It will set the osgi logging factory.
23   * 
24   * @author Michael Mimo Moratti (mimo@mimo.ch)
25   *
26   */
27  public class NettyIcapBundleActivator implements BundleActivator {
28  
29      private OsgiLoggerFactory loggerFactory;
30  
31      @Override
32      public void start(BundleContext ctx) throws Exception {
33          // Switch the internal logger to the OSGi LogService.
34          loggerFactory = new OsgiLoggerFactory(ctx);
35          InternalLoggerFactory.setDefaultFactory(loggerFactory);
36      }
37  
38      @Override
39      public void stop(BundleContext ctx) throws Exception {
40          if (loggerFactory != null) {
41              InternalLoggerFactory.setDefaultFactory(loggerFactory.getFallback());
42              loggerFactory.destroy();
43              loggerFactory = null;
44          }
45      }
46  }