felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject svn commit: r1755041 - in /felix/sandbox/scr-r7: ./ src/main/java/org/apache/felix/scr/impl/ src/main/java/org/apache/felix/scr/impl/helper/ src/main/java/org/apache/felix/scr/impl/manager/
Date Wed, 03 Aug 2016 08:17:08 GMT
Author: cziegeler
Date: Wed Aug  3 08:17:08 2016
New Revision: 1755041

URL: http://svn.apache.org/viewvc?rev=1755041&view=rev
Log:
Merge in changes from master

Modified:
    felix/sandbox/scr-r7/changelog.txt
    felix/sandbox/scr-r7/src/main/java/org/apache/felix/scr/impl/Activator.java
    felix/sandbox/scr-r7/src/main/java/org/apache/felix/scr/impl/BundleComponentActivator.java
    felix/sandbox/scr-r7/src/main/java/org/apache/felix/scr/impl/helper/ConfigAdminTracker.java
    felix/sandbox/scr-r7/src/main/java/org/apache/felix/scr/impl/manager/RegionConfigurationSupport.java

Modified: felix/sandbox/scr-r7/changelog.txt
URL: http://svn.apache.org/viewvc/felix/sandbox/scr-r7/changelog.txt?rev=1755041&r1=1755040&r2=1755041&view=diff
==============================================================================
--- felix/sandbox/scr-r7/changelog.txt (original)
+++ felix/sandbox/scr-r7/changelog.txt Wed Aug  3 08:17:08 2016
@@ -1,3 +1,11 @@
+Changes from 2.0.4 to 2.0.6
+---------------------------
+** Bug
+    * [FELIX-5315] Unexpected release of ConfigurationAdmin service in RegionConfigurationSupport
+    * [FELIX-5316] Updating from SCR 2.0.2 to SCR 2.0.4 leads to null pointers
+    * [FELIX-5318] SCR causes startup to wait when bundle uninstall itself in activator
+
+
 Changes from 2.0.2 to 2.0.4
 ---------------------------
 ** Improvement

Modified: felix/sandbox/scr-r7/src/main/java/org/apache/felix/scr/impl/Activator.java
URL: http://svn.apache.org/viewvc/felix/sandbox/scr-r7/src/main/java/org/apache/felix/scr/impl/Activator.java?rev=1755041&r1=1755040&r2=1755041&view=diff
==============================================================================
--- felix/sandbox/scr-r7/src/main/java/org/apache/felix/scr/impl/Activator.java (original)
+++ felix/sandbox/scr-r7/src/main/java/org/apache/felix/scr/impl/Activator.java Wed Aug  3 08:17:08 2016
@@ -23,12 +23,13 @@ import java.text.MessageFormat;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
-import java.util.concurrent.CountDownLatch;
 import java.util.concurrent.TimeUnit;
+import java.util.concurrent.locks.Lock;
+import java.util.concurrent.locks.ReentrantLock;
 
 import org.apache.felix.scr.impl.config.ScrConfigurationImpl;
-import org.apache.felix.scr.impl.inject.ClassUtils;
 import org.apache.felix.scr.impl.helper.SimpleLogger;
+import org.apache.felix.scr.impl.inject.ClassUtils;
 import org.apache.felix.scr.impl.runtime.ServiceComponentRuntimeImpl;
 import org.apache.felix.utils.extender.AbstractExtender;
 import org.apache.felix.utils.extender.Extension;
@@ -85,7 +86,7 @@ public class Activator extends AbstractE
     public Activator()
     {
         m_configuration = new ScrConfigurationImpl( this );
-        setSynchronous(true);
+        setSynchronous( true );
     }
 
     /**
@@ -101,53 +102,48 @@ public class Activator extends AbstractE
         m_context = context;
         m_bundle = context.getBundle();
         // require the log service
-        m_logService = new ServiceTracker<LogService, LogService>(m_context,
-            LOGSERVICE_CLASS, null);
+        m_logService = new ServiceTracker<LogService, LogService>( m_context, LOGSERVICE_CLASS, null );
         m_logService.open();
-        // get the configuration
-        m_configuration.start(m_context); //this will call restart, which calls super.start.
         // set bundle context for PackageAdmin tracker
         ClassUtils.setBundleContext( context );
+        // get the configuration
+        m_configuration.start( m_context ); //this will call restart, which calls super.start.
     }
 
     public void restart(boolean globalExtender)
     {
         BundleContext context = m_globalContext;
-        if (globalExtender)
+        if ( globalExtender )
         {
-            m_globalContext = m_context.getBundle(
-                Constants.SYSTEM_BUNDLE_LOCATION).getBundleContext();
+            m_globalContext = m_context.getBundle( Constants.SYSTEM_BUNDLE_LOCATION ).getBundleContext();
         }
         else
         {
             m_globalContext = m_context;
         }
-        if (ClassUtils.m_packageAdmin != null)
+        if ( ClassUtils.m_packageAdmin != null )
         {
-            log(LogService.LOG_INFO, m_bundle,
-                "Stopping to restart with new globalExtender setting: " + globalExtender,
-                null);
+            log( LogService.LOG_INFO, m_bundle,
+                "Stopping to restart with new globalExtender setting: " + globalExtender, null );
             //this really is a restart, not the initial start
             // the initial start where m_globalContext is null should skip this as m_packageAdmin should not yet be set.
             try
             {
-                super.stop(context);
+                super.stop( context );
             }
-            catch (Exception e)
+            catch ( Exception e )
             {
-                log(LogService.LOG_ERROR, m_bundle, "Exception stopping during restart",
-                    e);
+                log( LogService.LOG_ERROR, m_bundle, "Exception stopping during restart", e );
             }
         }
         try
         {
-            log(LogService.LOG_INFO, m_bundle,
-                "Starting with globalExtender setting: " + globalExtender, null);
-            super.start(m_globalContext);
+            log( LogService.LOG_INFO, m_bundle, "Starting with globalExtender setting: " + globalExtender, null );
+            super.start( m_globalContext );
         }
-        catch (Exception e)
+        catch ( Exception e )
         {
-            log(LogService.LOG_ERROR, m_bundle, "Exception starting during restart", e);
+            log( LogService.LOG_ERROR, m_bundle, "Exception starting during restart", e );
         }
 
     }
@@ -160,31 +156,29 @@ public class Activator extends AbstractE
         m_componentBundles = new HashMap<Long, BundleComponentActivator>();
         m_componentRegistry = new ComponentRegistry( this );
 
-        final ServiceComponentRuntime runtime = new ServiceComponentRuntimeImpl(
-            m_globalContext, m_componentRegistry);
-        m_runtime_reg = m_context.registerService(ServiceComponentRuntime.class, runtime,
-            null);
+        final ServiceComponentRuntime runtime = new ServiceComponentRuntimeImpl( m_globalContext, m_componentRegistry );
+        m_runtime_reg = m_context.registerService( ServiceComponentRuntime.class, runtime, null );
 
         // log SCR startup
-        log(LogService.LOG_INFO, m_bundle, " Version = {0}",
-            new Object[] { m_bundle.getHeaders().get(Constants.BUNDLE_VERSION) }, null);
+        log( LogService.LOG_INFO, m_bundle, " Version = {0}",
+            new Object[] { m_bundle.getHeaders().get( Constants.BUNDLE_VERSION ) }, null );
 
         // create and start the component actor
         m_componentActor = new ComponentActorThread( this );
-        Thread t = new Thread(m_componentActor, "SCR Component Actor");
-        t.setDaemon(true);
+        Thread t = new Thread( m_componentActor, "SCR Component Actor" );
+        t.setDaemon( true );
         t.start();
 
         super.doStart();
 
-        m_scrCommand = ScrCommand.register(m_context, runtime, m_configuration);
-        m_configuration.setScrCommand(m_scrCommand);
+        m_scrCommand = ScrCommand.register( m_context, runtime, m_configuration );
+        m_configuration.setScrCommand( m_scrCommand );
     }
 
     @Override
     public void stop(BundleContext context) throws Exception
     {
-        super.stop(context);
+        super.stop( context );
         m_configuration.stop();
         m_configuration = null;
     }
@@ -200,31 +194,31 @@ public class Activator extends AbstractE
         // stop tracking
         super.doStop();
 
-        if (m_scrCommand != null)
+        if ( m_scrCommand != null )
         {
             m_scrCommand.unregister();
             m_scrCommand = null;
         }
-        if (m_runtime_reg != null)
+        if ( m_runtime_reg != null )
         {
             m_runtime_reg.unregister();
             m_runtime_reg = null;
         }
         // dispose component registry
-        if (m_componentRegistry != null)
+        if ( m_componentRegistry != null )
         {
             m_componentRegistry = null;
         }
 
         // terminate the actor thread
-        if (m_componentActor != null)
+        if ( m_componentActor != null )
         {
             m_componentActor.terminate();
             m_componentActor = null;
         }
 
         // close the LogService tracker now
-        if (m_logService != null)
+        if ( m_logService != null )
         {
             m_logService.close();
             m_logService = null;
@@ -239,57 +233,85 @@ public class Activator extends AbstractE
     @Override
     protected Extension doCreateExtension(final Bundle bundle) throws Exception
     {
-        if (gogoMissing)
+        if ( gogoMissing )
         {
             try
             {
-                bundle.loadClass("org.apache.felix.service.command.Descriptor");
+                bundle.loadClass( "org.apache.felix.service.command.Descriptor" );
                 gogoMissing = false;
             }
-            catch (Throwable e)
+            catch ( Throwable e )
             {
             }
         }
-        return new ScrExtension(bundle);
+        return new ScrExtension( bundle );
     }
 
     protected class ScrExtension implements Extension
     {
 
         private final Bundle bundle;
-        private final CountDownLatch started;
+        private final Lock stateLock = new ReentrantLock();
 
         public ScrExtension(Bundle bundle)
         {
             this.bundle = bundle;
-            this.started = new CountDownLatch(1);
         }
 
         public void start()
         {
+            boolean acquired = false;
             try
             {
-                loadComponents(ScrExtension.this.bundle);
+                try
+                {
+                    acquired = stateLock.tryLock( m_configuration.stopTimeout(), TimeUnit.MILLISECONDS );
+
+                }
+                catch ( InterruptedException e )
+                {
+                    Thread.currentThread().interrupt();
+                    log( LogService.LOG_WARNING, m_bundle,
+                        "The wait for bundle {0}/{1} being destroyed before starting has been interrupted.",
+                        new Object[] { bundle.getSymbolicName(), bundle.getBundleId() }, e );
+                }
+                loadComponents( ScrExtension.this.bundle );
             }
             finally
             {
-                started.countDown();
+                if ( acquired )
+                {
+                    stateLock.unlock();
+                }
             }
         }
 
         public void destroy()
         {
+            boolean acquired = false;
             try
             {
-                this.started.await(m_configuration.stopTimeout(), TimeUnit.MILLISECONDS);
+                try
+                {
+                    acquired = stateLock.tryLock( m_configuration.stopTimeout(), TimeUnit.MILLISECONDS );
+
+                }
+                catch ( InterruptedException e )
+                {
+                    Thread.currentThread().interrupt();
+                    log( LogService.LOG_WARNING, m_bundle,
+                        "The wait for bundle {0}/{1} being started before destruction has been interrupted.",
+                        new Object[] { bundle.getSymbolicName(), bundle.getBundleId() }, e );
+                }
+                disposeComponents( bundle );
             }
-            catch (InterruptedException e)
+            finally
             {
-                log(LogService.LOG_WARNING, m_bundle,
-                    "The wait for bundle {0}/{1} being started before destruction has been interrupted.",
-                    new Object[] { bundle.getSymbolicName(), bundle.getBundleId() }, e);
+                if ( acquired )
+                {
+                    stateLock.unlock();
+                }
             }
-            disposeComponents(this.bundle);
         }
     }
 
@@ -304,7 +326,7 @@ public class Activator extends AbstractE
      */
     private void loadComponents(Bundle bundle)
     {
-        if (bundle.getHeaders().get(ComponentConstants.SERVICE_COMPONENT) == null)
+        if ( bundle.getHeaders().get( ComponentConstants.SERVICE_COMPONENT ) == null )
         {
             // no components in the bundle, abandon
             return;
@@ -312,43 +334,38 @@ public class Activator extends AbstractE
 
         // there should be components, load them with a bundle context
         BundleContext context = bundle.getBundleContext();
-        if (context == null)
+        if ( context == null )
         {
-            log(LogService.LOG_DEBUG, m_bundle,
-                "Cannot get BundleContext of bundle {0}/{1}",
-                new Object[] { bundle.getSymbolicName(), bundle.getBundleId() }, null);
+            log( LogService.LOG_DEBUG, m_bundle, "Cannot get BundleContext of bundle {0}/{1}",
+                new Object[] { bundle.getSymbolicName(), bundle.getBundleId() }, null );
             return;
         }
 
         //Examine bundle for extender requirement; if present check if bundle is wired to us.
-        BundleWiring wiring = bundle.adapt(BundleWiring.class);
-        List<BundleWire> extenderWires = wiring.getRequiredWires(
-            ExtenderNamespace.EXTENDER_NAMESPACE);
+        BundleWiring wiring = bundle.adapt( BundleWiring.class );
+        List<BundleWire> extenderWires = wiring.getRequiredWires( ExtenderNamespace.EXTENDER_NAMESPACE );
         try
         {
-            for (BundleWire wire : extenderWires)
+            for ( BundleWire wire : extenderWires )
             {
-                if (ComponentConstants.COMPONENT_CAPABILITY_NAME.equals(
-                    wire.getCapability().getAttributes().get(
-                        ExtenderNamespace.EXTENDER_NAMESPACE)))
+                if ( ComponentConstants.COMPONENT_CAPABILITY_NAME.equals(
+                    wire.getCapability().getAttributes().get( ExtenderNamespace.EXTENDER_NAMESPACE ) ) )
                 {
-                    if (!m_bundle.adapt(BundleRevision.class).equals(wire.getProvider()))
+                    if ( !m_bundle.adapt( BundleRevision.class ).equals( wire.getProvider() ) )
                     {
-                        log(LogService.LOG_DEBUG, m_bundle,
-                            "Bundle {0}/{1} wired to a different extender: {2}",
+                        log( LogService.LOG_DEBUG, m_bundle, "Bundle {0}/{1} wired to a different extender: {2}",
                             new Object[] { bundle.getSymbolicName(), bundle.getBundleId(),
                                     wire.getProvider().getSymbolicName() },
-                            null);
+                            null );
                         return;
                     }
                     break;
                 }
             }
         }
-        catch (NoSuchMethodError e)
+        catch ( NoSuchMethodError e )
         {
-            log(LogService.LOG_DEBUG, m_bundle,
-                "Cannot determine bundle wiring on pre R6 framework", null, null);
+            log( LogService.LOG_DEBUG, m_bundle, "Cannot determine bundle wiring on pre R6 framework", null, null );
         }
 
         // FELIX-1666 method is called for the LAZY_ACTIVATION event and
@@ -358,60 +375,58 @@ public class Activator extends AbstractE
         // if LAZY_ACTIVATION and STARTED event are fired at the same time
         final boolean loaded;
         final Long bundleId = bundle.getBundleId();
-        synchronized (m_componentBundles)
+        synchronized ( m_componentBundles )
         {
-            if (m_componentBundles.containsKey(bundleId))
+            if ( m_componentBundles.containsKey( bundleId ) )
             {
                 loaded = true;
             }
             else
             {
-                m_componentBundles.put(bundleId, null);
+                m_componentBundles.put( bundleId, null );
                 loaded = false;
             }
         }
 
         // terminate if already loaded (or currently being loaded)
-        if (loaded)
+        if ( loaded )
         {
-            log(LogService.LOG_DEBUG, m_bundle,
-                "Components for bundle {0}/{1} already loaded. Nothing to do.",
-                new Object[] { bundle.getSymbolicName(), bundle.getBundleId() }, null);
+            log( LogService.LOG_DEBUG, m_bundle, "Components for bundle {0}/{1} already loaded. Nothing to do.",
+                new Object[] { bundle.getSymbolicName(), bundle.getBundleId() }, null );
             return;
         }
 
         try
         {
-            BundleComponentActivator ga = new BundleComponentActivator( this,
-                m_componentRegistry, m_componentActor, context, m_configuration);
+            BundleComponentActivator ga = new BundleComponentActivator( this, m_componentRegistry, m_componentActor,
+                context, m_configuration );
             ga.initialEnable();
 
             // replace bundle activator in the map
-            synchronized (m_componentBundles)
+            synchronized ( m_componentBundles )
             {
-                m_componentBundles.put(bundleId, ga);
+                m_componentBundles.put( bundleId, ga );
             }
         }
-        catch (Exception e)
+        catch ( Exception e )
         {
             // remove the bundle id from the bundles map to ensure it is
             // not marked as being loaded
-            synchronized (m_componentBundles)
+            synchronized ( m_componentBundles )
             {
-                m_componentBundles.remove(bundleId);
+                m_componentBundles.remove( bundleId );
             }
 
-            if (e instanceof IllegalStateException && bundle.getState() != Bundle.ACTIVE)
+            if ( e instanceof IllegalStateException && bundle.getState() != Bundle.ACTIVE )
             {
-                log(LogService.LOG_DEBUG, m_bundle,
+                log( LogService.LOG_DEBUG, m_bundle,
                     "Bundle {0}/{1} has been stopped while trying to activate its components. Trying again when the bundles gets started again.",
-                    new Object[] { bundle.getSymbolicName(), bundle.getBundleId() }, e);
+                    new Object[] { bundle.getSymbolicName(), bundle.getBundleId() }, e );
             }
             else
             {
-                log(LogService.LOG_ERROR, m_bundle,
-                    "Error while loading components of bundle {0}/{1}",
-                    new Object[] { bundle.getSymbolicName(), bundle.getBundleId() }, e);
+                log( LogService.LOG_ERROR, m_bundle, "Error while loading components of bundle {0}/{1}",
+                    new Object[] { bundle.getSymbolicName(), bundle.getBundleId() }, e );
             }
         }
     }
@@ -422,26 +437,24 @@ public class Activator extends AbstractE
      */
     private void disposeComponents(Bundle bundle)
     {
-        final Object ga;
-        synchronized (m_componentBundles)
+        final BundleComponentActivator ga;
+        synchronized ( m_componentBundles )
         {
-            ga = m_componentBundles.remove(bundle.getBundleId());
+            ga = m_componentBundles.remove( bundle.getBundleId() );
         }
 
-        if (ga != null)
+        if ( ga != null )
         {
             try
             {
-                int reason = isStopping()
-                    ? ComponentConstants.DEACTIVATION_REASON_DISPOSED
+                int reason = isStopping()? ComponentConstants.DEACTIVATION_REASON_DISPOSED
                     : ComponentConstants.DEACTIVATION_REASON_BUNDLE_STOPPED;
-                ((BundleComponentActivator) ga).dispose(reason);
+                ga.dispose( reason );
             }
-            catch (Exception e)
+            catch ( Exception e )
             {
-                log(LogService.LOG_ERROR, m_bundle,
-                    "Error while disposing components of bundle {0}/{1}",
-                    new Object[] { bundle.getSymbolicName(), bundle.getBundleId() }, e);
+                log( LogService.LOG_ERROR, m_bundle, "Error while disposing components of bundle {0}/{1}",
+                    new Object[] { bundle.getSymbolicName(), bundle.getBundleId() }, e );
             }
         }
     }
@@ -449,48 +462,47 @@ public class Activator extends AbstractE
     @Override
     protected void debug(Bundle bundle, String msg)
     {
-        final String message = MessageFormat.format(msg + " bundle: {0}/{1}",
-            bundle.getSymbolicName(), bundle.getBundleId());
-        log(LogService.LOG_DEBUG, bundle, message, null);
+        final String message = MessageFormat.format( msg + " bundle: {0}/{1}", bundle.getSymbolicName(),
+            bundle.getBundleId() );
+        log( LogService.LOG_DEBUG, bundle, message, null );
     }
 
     @Override
     protected void warn(Bundle bundle, String msg, Throwable t)
     {
-        final String message = MessageFormat.format(msg + " bundle: {0}/{1}",
-            bundle.getSymbolicName(), bundle.getBundleId());
-        log(LogService.LOG_WARNING, bundle, message, t);
+        final String message = MessageFormat.format( msg + " bundle: {0}/{1}", bundle.getSymbolicName(),
+            bundle.getBundleId() );
+        log( LogService.LOG_WARNING, bundle, message, t );
     }
 
     @Override
     protected void error(String msg, Throwable t)
     {
-        log(LogService.LOG_DEBUG, m_bundle, msg, t);
+        log( LogService.LOG_DEBUG, m_bundle, msg, t );
     }
 
-//    @Override
+    //    @Override
     public void log(int level, String message, Throwable ex)
     {
-        log(level, null, message, ex);
+        log( level, null, message, ex );
     }
 
-//    @Override
+    //    @Override
     public void log(int level, String pattern, Object[] arguments, Throwable ex)
     {
-        if (isLogEnabled(level))
+        if ( isLogEnabled( level ) )
         {
-            final String message = MessageFormat.format(pattern, arguments);
-            log(level, null, message, ex);
+            final String message = MessageFormat.format( pattern, arguments );
+            log( level, null, message, ex );
         }
     }
 
-    public void log(int level, Bundle bundle, String pattern, Object[] arguments,
-                    Throwable ex)
+    public void log(int level, Bundle bundle, String pattern, Object[] arguments, Throwable ex)
     {
-        if (isLogEnabled(level))
+        if ( isLogEnabled( level ) )
         {
-            final String message = MessageFormat.format(pattern, arguments);
-            log(level, bundle, message, ex);
+            final String message = MessageFormat.format( pattern, arguments );
+            log( level, bundle, message, ex );
         }
     }
 
@@ -514,62 +526,61 @@ public class Activator extends AbstractE
      */
     public void log(int level, Bundle bundle, String message, Throwable ex)
     {
-        if (isLogEnabled(level))
+        if ( isLogEnabled( level ) )
         {
             ServiceTracker<LogService, LogService> t = m_logService;
-            LogService logger = (t != null) ? t.getService() : null;
-            if (logger == null)
+            LogService logger = ( t != null )? t.getService(): null;
+            if ( logger == null )
             {
                 // output depending on level
-                PrintStream out = (level == LogService.LOG_ERROR) ? System.err
-                    : System.out;
+                PrintStream out = ( level == LogService.LOG_ERROR )? System.err: System.out;
 
                 // level as a string
                 StringBuffer buf = new StringBuffer();
                 switch (level)
                 {
-                    case (LogService.LOG_DEBUG):
-                        buf.append("DEBUG: ");
+                    case ( LogService.LOG_DEBUG ):
+                        buf.append( "DEBUG: " );
                         break;
-                    case (LogService.LOG_INFO):
-                        buf.append("INFO : ");
+                    case ( LogService.LOG_INFO ):
+                        buf.append( "INFO : " );
                         break;
-                    case (LogService.LOG_WARNING):
-                        buf.append("WARN : ");
+                    case ( LogService.LOG_WARNING ):
+                        buf.append( "WARN : " );
                         break;
-                    case (LogService.LOG_ERROR):
-                        buf.append("ERROR: ");
+                    case ( LogService.LOG_ERROR ):
+                        buf.append( "ERROR: " );
                         break;
                     default:
-                        buf.append("UNK  : ");
+                        buf.append( "UNK  : " );
                         break;
                 }
 
                 // bundle information
-                if (bundle != null)
+                if ( bundle != null )
                 {
-                    buf.append(bundle.getSymbolicName());
-                    buf.append(" (");
-                    buf.append(bundle.getBundleId());
-                    buf.append("): ");
+                    buf.append( bundle.getSymbolicName() );
+                    buf.append( " (" );
+                    buf.append( bundle.getBundleId() );
+                    buf.append( "): " );
                 }
 
                 // the message
-                buf.append(message);
+                buf.append( message );
 
                 // keep the message and the stacktrace together
-                synchronized (out)
+                synchronized ( out )
                 {
-                    out.println(buf);
-                    if (ex != null)
+                    out.println( buf );
+                    if ( ex != null )
                     {
-                        ex.printStackTrace(out);
+                        ex.printStackTrace( out );
                     }
                 }
             }
             else
             {
-                logger.log(level, message, ex);
+                logger.log( level, message, ex );
             }
         }
     }

Modified: felix/sandbox/scr-r7/src/main/java/org/apache/felix/scr/impl/BundleComponentActivator.java
URL: http://svn.apache.org/viewvc/felix/sandbox/scr-r7/src/main/java/org/apache/felix/scr/impl/BundleComponentActivator.java?rev=1755041&r1=1755040&r2=1755041&view=diff
==============================================================================
--- felix/sandbox/scr-r7/src/main/java/org/apache/felix/scr/impl/BundleComponentActivator.java (original)
+++ felix/sandbox/scr-r7/src/main/java/org/apache/felix/scr/impl/BundleComponentActivator.java Wed Aug  3 08:17:08 2016
@@ -36,15 +36,15 @@ import java.util.concurrent.TimeUnit;
 import java.util.concurrent.atomic.AtomicBoolean;
 
 import org.apache.felix.scr.impl.helper.ConfigAdminTracker;
-import org.apache.felix.scr.impl.manager.ComponentActivator;
-import org.apache.felix.scr.impl.manager.ComponentHolder;
-import org.apache.felix.scr.impl.manager.RegionConfigurationSupport;
-import org.apache.felix.scr.impl.manager.ScrConfiguration;
 import org.apache.felix.scr.impl.helper.SimpleLogger;
 import org.apache.felix.scr.impl.manager.AbstractComponentManager;
+import org.apache.felix.scr.impl.manager.ComponentActivator;
+import org.apache.felix.scr.impl.manager.ComponentHolder;
 import org.apache.felix.scr.impl.manager.DependencyManager;
 import org.apache.felix.scr.impl.manager.ExtendedServiceEvent;
 import org.apache.felix.scr.impl.manager.ExtendedServiceListener;
+import org.apache.felix.scr.impl.manager.RegionConfigurationSupport;
+import org.apache.felix.scr.impl.manager.ScrConfiguration;
 import org.apache.felix.scr.impl.metadata.ComponentMetadata;
 import org.apache.felix.scr.impl.parser.KXml2SAXParser;
 import org.apache.felix.scr.impl.xml.XmlHandler;
@@ -67,7 +67,7 @@ import org.osgi.util.tracker.ServiceTrac
  */
 public class BundleComponentActivator implements ComponentActivator
 {
-	
+
     // global component registration
     private final ComponentRegistry m_componentRegistry;
 
@@ -87,12 +87,12 @@ public class BundleComponentActivator im
     private final ComponentActorThread m_componentActor;
 
     // true as long as the dispose method is not called
-    private final AtomicBoolean m_active = new AtomicBoolean(true);
-    private final CountDownLatch m_closeLatch = new CountDownLatch(1);
+    private final AtomicBoolean m_active = new AtomicBoolean( true );
+    private final CountDownLatch m_closeLatch = new CountDownLatch( 1 );
 
     // the configuration
     private final ScrConfiguration m_configuration;
-    
+
     private final ConfigAdminTracker configAdminTracker;
 
     private final Map<String, ListenerInfo> listenerMap = new HashMap<String, ListenerInfo>();
@@ -109,84 +109,77 @@ public class BundleComponentActivator im
             ExtendedServiceEvent extEvent = null;
             ExtendedServiceEvent endMatchEvent = null;
             Map<Filter, List<ExtendedServiceListener<ExtendedServiceEvent>>> filterMap;
-            synchronized (this)
+            synchronized ( this )
             {
                 filterMap = this.filterMap;
             }
-            for (Map.Entry<Filter, List<ExtendedServiceListener<ExtendedServiceEvent>>> entry : filterMap.entrySet())
+            for ( Map.Entry<Filter, List<ExtendedServiceListener<ExtendedServiceEvent>>> entry : filterMap.entrySet() )
             {
                 Filter filter = entry.getKey();
-                if (filter == null || filter.match(ref))
+                if ( filter == null || filter.match( ref ) )
                 {
-                    if (extEvent == null)
+                    if ( extEvent == null )
                     {
-                        extEvent = new ExtendedServiceEvent(event);
+                        extEvent = new ExtendedServiceEvent( event );
                     }
-                    for (ExtendedServiceListener<ExtendedServiceEvent> forwardTo : entry.getValue())
+                    for ( ExtendedServiceListener<ExtendedServiceEvent> forwardTo : entry.getValue() )
                     {
-                        forwardTo.serviceChanged(extEvent);
+                        forwardTo.serviceChanged( extEvent );
                     }
                 }
-                else if (event.getType() == ServiceEvent.MODIFIED)
+                else if ( event.getType() == ServiceEvent.MODIFIED )
                 {
-                    if (endMatchEvent == null)
+                    if ( endMatchEvent == null )
                     {
-                        endMatchEvent = new ExtendedServiceEvent(
-                            ServiceEvent.MODIFIED_ENDMATCH, ref);
+                        endMatchEvent = new ExtendedServiceEvent( ServiceEvent.MODIFIED_ENDMATCH, ref );
                     }
-                    for (ExtendedServiceListener<ExtendedServiceEvent> forwardTo : entry.getValue())
+                    for ( ExtendedServiceListener<ExtendedServiceEvent> forwardTo : entry.getValue() )
                     {
-                        forwardTo.serviceChanged(endMatchEvent);
+                        forwardTo.serviceChanged( endMatchEvent );
                     }
                 }
             }
-            if (extEvent != null)
+            if ( extEvent != null )
             {
                 extEvent.activateManagers();
             }
-            if (endMatchEvent != null)
+            if ( endMatchEvent != null )
             {
                 endMatchEvent.activateManagers();
             }
         }
 
-        public synchronized void add(Filter filter,
-            ExtendedServiceListener<ExtendedServiceEvent> listener)
+        public synchronized void add(Filter filter, ExtendedServiceListener<ExtendedServiceEvent> listener)
         {
-            filterMap = new HashMap<Filter, List<ExtendedServiceListener<ExtendedServiceEvent>>>(
-                filterMap);
-            List<ExtendedServiceListener<ExtendedServiceEvent>> listeners = filterMap.get(filter);
-            if (listeners == null)
+            filterMap = new HashMap<Filter, List<ExtendedServiceListener<ExtendedServiceEvent>>>( filterMap );
+            List<ExtendedServiceListener<ExtendedServiceEvent>> listeners = filterMap.get( filter );
+            if ( listeners == null )
             {
-                listeners = Collections.<ExtendedServiceListener<ExtendedServiceEvent>> singletonList(listener);
+                listeners = Collections.<ExtendedServiceListener<ExtendedServiceEvent>> singletonList( listener );
             }
             else
             {
-                listeners = new ArrayList<ExtendedServiceListener<ExtendedServiceEvent>>(
-                    listeners);
-                listeners.add(listener);
+                listeners = new ArrayList<ExtendedServiceListener<ExtendedServiceEvent>>( listeners );
+                listeners.add( listener );
             }
-            filterMap.put(filter, listeners);
+            filterMap.put( filter, listeners );
         }
 
-        public synchronized boolean remove(Filter filter,
-            ExtendedServiceListener<ExtendedServiceEvent> listener)
+        public synchronized boolean remove(Filter filter, ExtendedServiceListener<ExtendedServiceEvent> listener)
         {
-            List<ExtendedServiceListener<ExtendedServiceEvent>> listeners = filterMap.get(filter);
-            if (listeners != null)
+            List<ExtendedServiceListener<ExtendedServiceEvent>> listeners = filterMap.get( filter );
+            if ( listeners != null )
             {
-                filterMap = new HashMap<Filter, List<ExtendedServiceListener<ExtendedServiceEvent>>>(
-                    filterMap);
-                listeners = new ArrayList<ExtendedServiceListener<ExtendedServiceEvent>>(
-                    listeners);
-                listeners.remove(listener);
-                if (listeners.isEmpty())
+                filterMap = new HashMap<Filter, List<ExtendedServiceListener<ExtendedServiceEvent>>>( filterMap );
+                listeners = new ArrayList<ExtendedServiceListener<ExtendedServiceEvent>>( listeners );
+                listeners.remove( listener );
+                if ( listeners.isEmpty() )
                 {
-                    filterMap.remove(filter);
+                    filterMap.remove( filter );
                 }
                 else
                 {
-                    filterMap.put(filter, listeners);
+                    filterMap.put( filter, listeners );
                 }
             }
             return filterMap.isEmpty();
@@ -197,41 +190,41 @@ public class BundleComponentActivator im
         ExtendedServiceListener<ExtendedServiceEvent> listener)
     {
         ListenerInfo listenerInfo;
-        synchronized (listenerMap)
+        synchronized ( listenerMap )
         {
-            log(LogService.LOG_DEBUG, "classNameFilter: " + classNameFilter
-                + " event filter: " + eventFilter, null, null, null);
-            listenerInfo = listenerMap.get(classNameFilter);
-            if (listenerInfo == null)
+            log( LogService.LOG_DEBUG, "classNameFilter: " + classNameFilter + " event filter: " + eventFilter, null,
+                null, null );
+            listenerInfo = listenerMap.get( classNameFilter );
+            if ( listenerInfo == null )
             {
                 listenerInfo = new ListenerInfo();
-                listenerMap.put(classNameFilter, listenerInfo);
+                listenerMap.put( classNameFilter, listenerInfo );
                 try
                 {
-                    m_context.addServiceListener(listenerInfo, classNameFilter);
+                    m_context.addServiceListener( listenerInfo, classNameFilter );
                 }
-                catch (InvalidSyntaxException e)
+                catch ( InvalidSyntaxException e )
                 {
                     throw (IllegalArgumentException) new IllegalArgumentException(
-                        "invalid class name filter").initCause(e);
+                        "invalid class name filter" ).initCause( e );
                 }
             }
         }
-        listenerInfo.add(eventFilter, listener);
+        listenerInfo.add( eventFilter, listener );
     }
 
     public void removeServiceListener(String className, Filter filter,
         ExtendedServiceListener<ExtendedServiceEvent> listener)
     {
-        synchronized (listenerMap)
+        synchronized ( listenerMap )
         {
-            ListenerInfo listenerInfo = listenerMap.get(className);
-            if (listenerInfo != null)
+            ListenerInfo listenerInfo = listenerMap.get( className );
+            if ( listenerInfo != null )
             {
-                if (listenerInfo.remove(filter, listener))
+                if ( listenerInfo.remove( filter, listener ) )
                 {
-                    listenerMap.remove(className);
-                    m_context.removeServiceListener(listenerInfo);
+                    listenerMap.remove( className );
+                    m_context.removeServiceListener( listenerInfo );
                 }
             }
         }
@@ -258,32 +251,29 @@ public class BundleComponentActivator im
         m_bundle = context.getBundle();
 
         // have the LogService handy (if available)
-        m_logService = new ServiceTracker<LogService, LogService>(context,
-            Activator.LOGSERVICE_CLASS, null);
+        m_logService = new ServiceTracker<LogService, LogService>( context, Activator.LOGSERVICE_CLASS, null );
         m_logService.open();
         m_configuration = configuration;
 
-        log(LogService.LOG_DEBUG, "BundleComponentActivator : Bundle [{0}] active",
-            new Object[] { m_bundle.getBundleId() }, null, null, null);
+        log( LogService.LOG_DEBUG, "BundleComponentActivator : Bundle [{0}] active",
+            new Object[] { m_bundle.getBundleId() }, null, null, null );
 
         // Get the Metadata-Location value from the manifest
-        String descriptorLocations = (String) m_bundle.getHeaders().get(
-            "Service-Component");
-        if (descriptorLocations == null)
+        String descriptorLocations = (String) m_bundle.getHeaders().get( "Service-Component" );
+        if ( descriptorLocations == null )
         {
-            throw new ComponentException(
-                "Service-Component entry not found in the manifest");
+            throw new ComponentException( "Service-Component entry not found in the manifest" );
         }
 
-        initialize(descriptorLocations);
+        initialize( descriptorLocations );
         ConfigAdminTracker tracker = null;
-        for (ComponentHolder<?> holder: m_holders) 
+        for ( ComponentHolder<?> holder : m_holders )
         {
-        	if (!holder.getComponentMetadata().isConfigurationIgnored())
-        	{
-        		tracker = new ConfigAdminTracker(this);
-        		break;
-        	}
+            if ( !holder.getComponentMetadata().isConfigurationIgnored() )
+            {
+                tracker = new ConfigAdminTracker( this );
+                break;
+            }
         }
         configAdminTracker = tracker;
     }
@@ -299,32 +289,30 @@ public class BundleComponentActivator im
      */
     protected void initialize(String descriptorLocations)
     {
-        log(LogService.LOG_DEBUG,
-            "BundleComponentActivator : Bundle [{0}] descriptor locations {1}",
-            new Object[] { m_bundle.getBundleId(), descriptorLocations }, null, null,
-            null);
+        log( LogService.LOG_DEBUG, "BundleComponentActivator : Bundle [{0}] descriptor locations {1}",
+            new Object[] { m_bundle.getBundleId(), descriptorLocations }, null, null, null );
 
         // 112.4.1: The value of the the header is a comma separated list of XML entries within the Bundle
-        StringTokenizer st = new StringTokenizer(descriptorLocations, ", ");
+        StringTokenizer st = new StringTokenizer( descriptorLocations, ", " );
 
-        while (st.hasMoreTokens())
+        while ( st.hasMoreTokens() )
         {
             String descriptorLocation = st.nextToken();
 
-            URL[] descriptorURLs = findDescriptors(m_bundle, descriptorLocation);
-            if (descriptorURLs.length == 0)
+            URL[] descriptorURLs = findDescriptors( m_bundle, descriptorLocation );
+            if ( descriptorURLs.length == 0 )
             {
                 // 112.4.1 If an XML document specified by the header cannot be located in the bundle and its attached
                 // fragments, SCR must log an error message with the Log Service, if present, and continue.
-                log(LogService.LOG_ERROR, "Component descriptor entry ''{0}'' not found",
-                    new Object[] { descriptorLocation }, null, null, null);
+                log( LogService.LOG_ERROR, "Component descriptor entry ''{0}'' not found",
+                    new Object[] { descriptorLocation }, null, null, null );
                 continue;
             }
 
             // load from the descriptors
-            for (URL descriptorURL : descriptorURLs)
+            for ( URL descriptorURL : descriptorURLs )
             {
-                loadDescriptor(descriptorURL);
+                loadDescriptor( descriptorURL );
             }
         }
     }
@@ -336,27 +324,23 @@ public class BundleComponentActivator im
     void initialEnable()
     {
         //enable all the enabled components
-        for (ComponentHolder<?> componentHolder : m_holders)
+        for ( ComponentHolder<?> componentHolder : m_holders )
         {
-            log(LogService.LOG_DEBUG,
-                "BundleComponentActivator : Bundle [{0}] May enable component holder {1}",
-                new Object[] { m_bundle.getBundleId(),
-                        componentHolder.getComponentMetadata().getName() }, null, null,
-                null);
-
-            if (componentHolder.getComponentMetadata().isEnabled())
-            {
-                log(LogService.LOG_DEBUG,
-                    "BundleComponentActivator : Bundle [{0}] Enabling component holder {1}",
-                    new Object[] { m_bundle.getBundleId(),
-                            componentHolder.getComponentMetadata().getName() }, null,
-                    null, null);
+            log( LogService.LOG_DEBUG, "BundleComponentActivator : Bundle [{0}] May enable component holder {1}",
+                new Object[] { m_bundle.getBundleId(), componentHolder.getComponentMetadata().getName() }, null, null,
+                null );
+
+            if ( componentHolder.getComponentMetadata().isEnabled() )
+            {
+                log( LogService.LOG_DEBUG, "BundleComponentActivator : Bundle [{0}] Enabling component holder {1}",
+                    new Object[] { m_bundle.getBundleId(), componentHolder.getComponentMetadata().getName() }, null,
+                    null, null );
 
                 try
                 {
-                    componentHolder.enableComponents(false);
+                    componentHolder.enableComponents( false );
                 }
-                catch (Throwable t)
+                catch ( Throwable t )
                 {
                     // caught on unhandled RuntimeException or Error
                     // (e.g. ClassDefNotFoundError)
@@ -364,26 +348,24 @@ public class BundleComponentActivator im
                     // make sure the component is properly disabled, just in case
                     try
                     {
-                        componentHolder.disableComponents(false);
+                        componentHolder.disableComponents( false );
                     }
-                    catch (Throwable ignore)
+                    catch ( Throwable ignore )
                     {
                     }
 
-                    log(LogService.LOG_ERROR,
+                    log( LogService.LOG_ERROR,
                         "BundleComponentActivator : Bundle [{0}] Unexpected failure enabling component holder {1}",
-                        new Object[] { m_bundle.getBundleId(),
-                                componentHolder.getComponentMetadata().getName() }, null,
-                        null, t);
+                        new Object[] { m_bundle.getBundleId(), componentHolder.getComponentMetadata().getName() }, null,
+                        null, t );
                 }
             }
             else
             {
-                log(LogService.LOG_DEBUG,
+                log( LogService.LOG_DEBUG,
                     "BundleComponentActivator : Bundle [{0}] Will not enable component holder {1}",
-                    new Object[] { m_bundle.getBundleId(),
-                            componentHolder.getComponentMetadata().getName() }, null,
-                    null, null);
+                    new Object[] { m_bundle.getBundleId(), componentHolder.getComponentMetadata().getName() }, null,
+                    null, null );
             }
         }
     }
@@ -397,20 +379,19 @@ public class BundleComponentActivator im
      */
     static URL[] findDescriptors(final Bundle bundle, final String descriptorLocation)
     {
-        if (bundle == null || descriptorLocation == null
-            || descriptorLocation.trim().length() == 0)
+        if ( bundle == null || descriptorLocation == null || descriptorLocation.trim().length() == 0 )
         {
             return new URL[0];
         }
 
         // split pattern and path
-        final int lios = descriptorLocation.lastIndexOf("/");
+        final int lios = descriptorLocation.lastIndexOf( "/" );
         final String path;
         final String filePattern;
-        if (lios > 0)
+        if ( lios > 0 )
         {
-            path = descriptorLocation.substring(0, lios);
-            filePattern = descriptorLocation.substring(lios + 1);
+            path = descriptorLocation.substring( 0, lios );
+            filePattern = descriptorLocation.substring( lios + 1 );
         }
         else
         {
@@ -419,19 +400,19 @@ public class BundleComponentActivator im
         }
 
         // find the entries
-        final Enumeration<URL> entries = bundle.findEntries(path, filePattern, false);
-        if (entries == null || !entries.hasMoreElements())
+        final Enumeration<URL> entries = bundle.findEntries( path, filePattern, false );
+        if ( entries == null || !entries.hasMoreElements() )
         {
             return new URL[0];
         }
 
         // create the result list
         List<URL> urls = new ArrayList<URL>();
-        while (entries.hasMoreElements())
+        while ( entries.hasMoreElements() )
         {
-            urls.add(entries.nextElement());
+            urls.add( entries.nextElement() );
         }
-        return urls.toArray(new URL[urls.size()]);
+        return urls.toArray( new URL[urls.size()] );
     }
 
     private void loadDescriptor(final URL descriptorURL)
@@ -444,129 +425,121 @@ public class BundleComponentActivator im
         {
             stream = descriptorURL.openStream();
 
-            BufferedReader in = new BufferedReader(new InputStreamReader(stream, "UTF-8"));
-            XmlHandler handler = new XmlHandler(m_bundle, this,
-                getConfiguration().isFactoryEnabled(), getConfiguration().keepInstances());
+            BufferedReader in = new BufferedReader( new InputStreamReader( stream, "UTF-8" ) );
+            XmlHandler handler = new XmlHandler( m_bundle, this, getConfiguration().isFactoryEnabled(),
+                getConfiguration().keepInstances() );
             KXml2SAXParser parser;
 
-            parser = new KXml2SAXParser(in);
+            parser = new KXml2SAXParser( in );
 
-            parser.parseXML(handler);
+            parser.parseXML( handler );
 
             // 112.4.2 Component descriptors may contain a single, root component element
             // or one or more component elements embedded in a larger document
-            for (Object o : handler.getComponentMetadataList())
+            for ( Object o : handler.getComponentMetadataList() )
             {
                 ComponentMetadata metadata = (ComponentMetadata) o;
                 ComponentRegistryKey key = null;
                 try
                 {
                     // check and reserve the component name (if not null)
-                    if (metadata.getName() != null)
+                    if ( metadata.getName() != null )
                     {
-                        key = m_componentRegistry.checkComponentName(m_bundle,
-                            metadata.getName());
+                        key = m_componentRegistry.checkComponentName( m_bundle, metadata.getName() );
                     }
 
                     // validate the component metadata
-                    metadata.validate(this);
+                    metadata.validate( this );
 
                     // Request creation of the component manager
-                    ComponentHolder<?> holder = m_componentRegistry.createComponentHolder(
-                        this, metadata);
+                    ComponentHolder<?> holder = m_componentRegistry.createComponentHolder( this, metadata );
 
                     // register the component after validation
-                    m_componentRegistry.registerComponentHolder(key, holder);
-                    m_holders.add(holder);
+                    m_componentRegistry.registerComponentHolder( key, holder );
+                    m_holders.add( holder );
 
-                    log(LogService.LOG_DEBUG,
+                    log( LogService.LOG_DEBUG,
                         "BundleComponentActivator : Bundle [{0}] ComponentHolder created for {1}",
-                        new Object[] { m_bundle.getBundleId(), metadata.getName() },
-                        null, null, null);
+                        new Object[] { m_bundle.getBundleId(), metadata.getName() }, null, null, null );
 
                 }
-                catch (Throwable t)
+                catch ( Throwable t )
                 {
                     // There is a problem with this particular component, we'll log the error
                     // and proceed to the next one
-                    log(LogService.LOG_ERROR, "Cannot register Component", metadata,
-                        null, t);
+                    log( LogService.LOG_ERROR, "Cannot register Component", metadata, null, t );
 
                     // make sure the name is not reserved any more
-                    if (key != null)
+                    if ( key != null )
                     {
-                        m_componentRegistry.unregisterComponentHolder(key);
+                        m_componentRegistry.unregisterComponentHolder( key );
                     }
                 }
             }
         }
-        catch (IOException ex)
+        catch ( IOException ex )
         {
             // 112.4.1 If an XML document specified by the header cannot be located in the bundle and its attached
             // fragments, SCR must log an error message with the Log Service, if present, and continue.
 
-            log(LogService.LOG_ERROR, "Problem reading descriptor entry ''{0}''",
-                new Object[] { descriptorLocation }, null, null, ex);
+            log( LogService.LOG_ERROR, "Problem reading descriptor entry ''{0}''", new Object[] { descriptorLocation },
+                null, null, ex );
         }
-        catch (Exception ex)
+        catch ( Exception ex )
         {
-            log(LogService.LOG_ERROR, "General problem with descriptor entry ''{0}''",
-                new Object[] { descriptorLocation }, null, null, ex);
+            log( LogService.LOG_ERROR, "General problem with descriptor entry ''{0}''",
+                new Object[] { descriptorLocation }, null, null, ex );
         }
         finally
         {
-            if (stream != null)
+            if ( stream != null )
             {
                 try
                 {
                     stream.close();
                 }
-                catch (IOException ignore)
+                catch ( IOException ignore )
                 {
                 }
             }
         }
     }
-    
+
     /**
     * Dispose of this component activator instance and all the component
     * managers.
     */
     void dispose(int reason)
     {
-        if (m_active.compareAndSet(true, false))
+        if ( m_active.compareAndSet( true, false ) )
         {
-            log(LogService.LOG_DEBUG,
-                "BundleComponentActivator : Bundle [{0}] will destroy {1} instances",
-                new Object[] { m_bundle.getBundleId(), m_holders.size() }, null, null,
-                null);
+            log( LogService.LOG_DEBUG, "BundleComponentActivator : Bundle [{0}] will destroy {1} instances",
+                new Object[] { m_bundle.getBundleId(), m_holders.size() }, null, null, null );
 
-            for (ComponentHolder<?> holder : m_holders)
+            for ( ComponentHolder<?> holder : m_holders )
             {
                 try
                 {
-                    holder.disposeComponents(reason);
+                    holder.disposeComponents( reason );
                 }
-                catch (Exception e)
+                catch ( Exception e )
                 {
-                    log(LogService.LOG_ERROR,
-                        "BundleComponentActivator : Exception invalidating",
-                        holder.getComponentMetadata(), null, e);
+                    log( LogService.LOG_ERROR, "BundleComponentActivator : Exception invalidating",
+                        holder.getComponentMetadata(), null, e );
                 }
                 finally
                 {
-                    m_componentRegistry.unregisterComponentHolder(m_bundle,
-                        holder.getComponentMetadata().getName());
+                    m_componentRegistry.unregisterComponentHolder( m_bundle, holder.getComponentMetadata().getName() );
                 }
 
             }
-            if (configAdminTracker != null)
+            if ( configAdminTracker != null )
             {
-            	configAdminTracker.dispose();
+                configAdminTracker.dispose();
             }
-            
-            log(LogService.LOG_DEBUG, "BundleComponentActivator : Bundle [{0}] STOPPED",
-                new Object[] { m_bundle.getBundleId() }, null, null, null);
+
+            log( LogService.LOG_DEBUG, "BundleComponentActivator : Bundle [{0}] STOPPED",
+                new Object[] { m_bundle.getBundleId() }, null, null, null );
 
             m_logService.close();
             m_closeLatch.countDown();
@@ -575,11 +548,12 @@ public class BundleComponentActivator im
         {
             try
             {
-                m_closeLatch.await(m_configuration.lockTimeout(), TimeUnit.MILLISECONDS);
+                m_closeLatch.await( m_configuration.lockTimeout(), TimeUnit.MILLISECONDS );
             }
-            catch (InterruptedException e)
+            catch ( InterruptedException e )
             {
                 //ignore interruption during concurrent shutdown.
+                Thread.currentThread().interrupt();
             }
         }
 
@@ -623,19 +597,17 @@ public class BundleComponentActivator im
      */
     public void enableComponent(final String name)
     {
-        final List<ComponentHolder<?>> holder = getSelectedComponents(name);
-        for (ComponentHolder<?> aHolder : holder)
+        final List<ComponentHolder<?>> holder = getSelectedComponents( name );
+        for ( ComponentHolder<?> aHolder : holder )
         {
             try
             {
-                log(LogService.LOG_DEBUG, "Enabling Component",
-                    aHolder.getComponentMetadata(), null, null);
-                aHolder.enableComponents(true);
+                log( LogService.LOG_DEBUG, "Enabling Component", aHolder.getComponentMetadata(), null, null );
+                aHolder.enableComponents( true );
             }
-            catch (Throwable t)
+            catch ( Throwable t )
             {
-                log(LogService.LOG_ERROR, "Cannot enable component",
-                    aHolder.getComponentMetadata(), null, t);
+                log( LogService.LOG_ERROR, "Cannot enable component", aHolder.getComponentMetadata(), null, t );
             }
         }
     }
@@ -651,19 +623,17 @@ public class BundleComponentActivator im
      */
     public void disableComponent(final String name)
     {
-        final List<ComponentHolder<?>> holder = getSelectedComponents(name);
-        for (ComponentHolder<?> aHolder : holder)
+        final List<ComponentHolder<?>> holder = getSelectedComponents( name );
+        for ( ComponentHolder<?> aHolder : holder )
         {
             try
             {
-                log(LogService.LOG_DEBUG, "Disabling Component",
-                    aHolder.getComponentMetadata(), null, null);
-                aHolder.disableComponents(true);
+                log( LogService.LOG_DEBUG, "Disabling Component", aHolder.getComponentMetadata(), null, null );
+                aHolder.disableComponents( true );
             }
-            catch (Throwable t)
+            catch ( Throwable t )
             {
-                log(LogService.LOG_ERROR, "Cannot disable component",
-                    aHolder.getComponentMetadata(), null, t);
+                log( LogService.LOG_ERROR, "Cannot disable component", aHolder.getComponentMetadata(), null, t );
             }
         }
     }
@@ -686,16 +656,15 @@ public class BundleComponentActivator im
     private List<ComponentHolder<?>> getSelectedComponents(String name)
     {
         // if all components are selected
-        if (name == null)
+        if ( name == null )
         {
             return m_holders;
         }
 
-        ComponentHolder<?> componentHolder = m_componentRegistry.getComponentHolder(
-            m_bundle, name);
-        if (componentHolder != null)
+        ComponentHolder<?> componentHolder = m_componentRegistry.getComponentHolder( m_bundle, name );
+        if ( componentHolder != null )
         {
-            return Collections.<ComponentHolder<?>> singletonList(componentHolder);
+            return Collections.<ComponentHolder<?>> singletonList( componentHolder );
         }
 
         // if the component is not known
@@ -706,12 +675,12 @@ public class BundleComponentActivator im
 
     public long registerComponentId(AbstractComponentManager<?> componentManager)
     {
-        return m_componentRegistry.registerComponentId(componentManager);
+        return m_componentRegistry.registerComponentId( componentManager );
     }
 
     public void unregisterComponentId(AbstractComponentManager<?> componentManager)
     {
-        m_componentRegistry.unregisterComponentId(componentManager.getId());
+        m_componentRegistry.unregisterComponentId( componentManager.getId() );
     }
 
     //---------- Asynchronous Component Handling ------------------------------
@@ -725,37 +694,34 @@ public class BundleComponentActivator im
      */
     public void schedule(Runnable task)
     {
-        if (isActive())
+        if ( isActive() )
         {
             ComponentActorThread cat = m_componentActor;
-            if (cat != null)
+            if ( cat != null )
             {
-                cat.schedule(task);
+                cat.schedule( task );
             }
             else
             {
-                log(LogService.LOG_DEBUG,
-                    "Component Actor Thread not running, calling synchronously", null,
-                    null, null);
+                log( LogService.LOG_DEBUG, "Component Actor Thread not running, calling synchronously", null, null,
+                    null );
                 try
                 {
-                    synchronized (this)
+                    synchronized ( this )
                     {
                         task.run();
                     }
                 }
-                catch (Throwable t)
+                catch ( Throwable t )
                 {
-                    log(LogService.LOG_WARNING, "Unexpected problem executing task",
-                        null, null, t);
+                    log( LogService.LOG_WARNING, "Unexpected problem executing task", null, null, t );
                 }
             }
         }
         else
         {
-            log(LogService.LOG_WARNING,
-                "BundleComponentActivator is not active; not scheduling {0}",
-                new Object[] { task }, null, null, null);
+            log( LogService.LOG_WARNING, "BundleComponentActivator is not active; not scheduling {0}",
+                new Object[] { task }, null, null, null );
         }
     }
 
@@ -780,13 +746,13 @@ public class BundleComponentActivator im
      * @param componentId
      * @param ex An optional <code>Throwable</code> whose stack trace is written,
      */
-    public void log(int level, String pattern, Object[] arguments,
-        ComponentMetadata metadata, Long componentId, Throwable ex)
+    public void log(int level, String pattern, Object[] arguments, ComponentMetadata metadata, Long componentId,
+        Throwable ex)
     {
-        if (isLogEnabled(level))
+        if ( isLogEnabled( level ) )
         {
-            final String message = MessageFormat.format(pattern, arguments);
-            log(level, message, metadata, componentId, ex);
+            final String message = MessageFormat.format( pattern, arguments );
+            log( level, message, metadata, componentId, ex );
         }
     }
 
@@ -800,18 +766,16 @@ public class BundleComponentActivator im
      * @param componentId
      * @param ex An optional <code>Throwable</code> whose stack trace is written,
      */
-    public void log(int level, String message, ComponentMetadata metadata,
-        Long componentId, Throwable ex)
+    public void log(int level, String message, ComponentMetadata metadata, Long componentId, Throwable ex)
     {
-        if (isLogEnabled(level))
+        if ( isLogEnabled( level ) )
         {
             // prepend the metadata name to the message
-            if (metadata != null)
+            if ( metadata != null )
             {
-                if (componentId != null)
+                if ( componentId != null )
                 {
-                    message = "[" + metadata.getName() + "(" + componentId + ")] "
-                        + message;
+                    message = "[" + metadata.getName() + "(" + componentId + ")] " + message;
                 }
                 else
                 {
@@ -820,59 +784,60 @@ public class BundleComponentActivator im
             }
 
             ServiceTracker<LogService, LogService> logService = m_logService;
-            if (logService != null)
+            if ( logService != null )
             {
                 LogService logger = logService.getService();
-                if (logger == null)
+                if ( logger == null )
                 {
-                    m_logger.log(level, message, ex);
+                    m_logger.log( level, message, ex );
                 }
                 else
                 {
-                    logger.log(level, message, ex);
+                    logger.log( level, message, ex );
                 }
             }
             else
             {
                 // BCA has been disposed off, bundle context is probably invalid. Try to log something.
-                m_logger.log(level, message, ex);
+                m_logger.log( level, message, ex );
             }
         }
     }
-    
+
     public <T> boolean enterCreate(ServiceReference<T> serviceReference)
     {
-        return m_componentRegistry.enterCreate(serviceReference);
+        return m_componentRegistry.enterCreate( serviceReference );
     }
-    
+
     public <T> void leaveCreate(ServiceReference<T> serviceReference)
     {
-        m_componentRegistry.leaveCreate(serviceReference);
+        m_componentRegistry.leaveCreate( serviceReference );
     }
 
     public <T> void missingServicePresent(ServiceReference<T> serviceReference)
     {
-        m_componentRegistry.missingServicePresent(serviceReference, m_componentActor);
+        m_componentRegistry.missingServicePresent( serviceReference, m_componentActor );
     }
 
     public <S, T> void registerMissingDependency(DependencyManager<S, T> dependencyManager,
         ServiceReference<T> serviceReference, int trackingCount)
     {
-        m_componentRegistry.registerMissingDependency(dependencyManager,
-            serviceReference, trackingCount);
+        m_componentRegistry.registerMissingDependency( dependencyManager, serviceReference, trackingCount );
     }
 
-    public RegionConfigurationSupport setRegionConfigurationSupport(ServiceReference<ConfigurationAdmin> reference) {
-        RegionConfigurationSupport rcs = m_componentRegistry.registerRegionConfigurationSupport(reference);
-        for (ComponentHolder<?> holder: m_holders)
+    public RegionConfigurationSupport setRegionConfigurationSupport(ServiceReference<ConfigurationAdmin> reference)
+    {
+        RegionConfigurationSupport rcs = m_componentRegistry.registerRegionConfigurationSupport( reference );
+        for ( ComponentHolder<?> holder : m_holders )
         {
-            rcs.configureComponentHolder(holder);
+            rcs.configureComponentHolder( holder );
         }
         return rcs;
     }
 
-    public void unsetRegionConfigurationSupport(RegionConfigurationSupport rcs) {
-        m_componentRegistry.unregisterRegionConfigurationSupport(rcs);
-		// TODO anything needed?
-	}
+    public void unsetRegionConfigurationSupport(RegionConfigurationSupport rcs)
+    {
+        m_componentRegistry.unregisterRegionConfigurationSupport( rcs );
+        // TODO anything needed?
+    }
 }

Modified: felix/sandbox/scr-r7/src/main/java/org/apache/felix/scr/impl/helper/ConfigAdminTracker.java
URL: http://svn.apache.org/viewvc/felix/sandbox/scr-r7/src/main/java/org/apache/felix/scr/impl/helper/ConfigAdminTracker.java?rev=1755041&r1=1755040&r2=1755041&view=diff
==============================================================================
--- felix/sandbox/scr-r7/src/main/java/org/apache/felix/scr/impl/helper/ConfigAdminTracker.java (original)
+++ felix/sandbox/scr-r7/src/main/java/org/apache/felix/scr/impl/helper/ConfigAdminTracker.java Wed Aug  3 08:17:08 2016
@@ -20,7 +20,6 @@ package org.apache.felix.scr.impl.helper
 
 import org.apache.felix.scr.impl.manager.ComponentActivator;
 import org.apache.felix.scr.impl.manager.RegionConfigurationSupport;
-import org.osgi.framework.Bundle;
 import org.osgi.framework.ServiceReference;
 import org.osgi.service.cm.ConfigurationAdmin;
 import org.osgi.util.tracker.ServiceTracker;
@@ -28,76 +27,43 @@ import org.osgi.util.tracker.ServiceTrac
 
 public class ConfigAdminTracker
 {
-	public static final String CONFIGURATION_ADMIN = "org.osgi.service.cm.ConfigurationAdmin";
-	
-	private final ServiceTracker<ConfigurationAdmin, RegionConfigurationSupport> configAdminTracker;
-
-	static ConfigAdminTracker getRegionConfigurationSupport(final ComponentActivator componentActivator, final Bundle dsBundle)
-	{
-		Class<?> ourCA;
-		Class<?> theirCA;
-		try
-		{
-			ourCA = dsBundle.loadClass(CONFIGURATION_ADMIN);
-		}
-		catch (ClassNotFoundException e)
-		{
-			return null;
-		}
-		try
-		{
-			Bundle bundle = componentActivator.getBundleContext().getBundle();
-			if ( bundle == null )
-			{
-				return null;
-			}
-			theirCA = dsBundle.loadClass(CONFIGURATION_ADMIN);
-		}
-		catch (ClassNotFoundException e)
-		{
-			return null;
-		}
-		if ( ourCA != theirCA )
-		{
-			return null;
-		}
-		ConfigAdminTracker tracker = new ConfigAdminTracker(componentActivator);
-		return tracker;
-	}
-
-	public ConfigAdminTracker(final ComponentActivator componentActivator)
-	{
-		
-		//TODO this assumes that there is 0 or 1 ca service visible to the bundle being extended.
-		//Is this sure to be true?
-		configAdminTracker = new ServiceTracker<ConfigurationAdmin, RegionConfigurationSupport>(componentActivator.getBundleContext(),
-				CONFIGURATION_ADMIN, 
-				new ServiceTrackerCustomizer<ConfigurationAdmin, RegionConfigurationSupport>() 
-				{
-
-			public RegionConfigurationSupport addingService(
-					ServiceReference<ConfigurationAdmin> reference) {
-				return componentActivator.setRegionConfigurationSupport(reference);
-			}
-
-			public void modifiedService(
-					ServiceReference<ConfigurationAdmin> reference,
-					RegionConfigurationSupport service) {
-			}
-
-			public void removedService(
-					ServiceReference<ConfigurationAdmin> reference,
-					RegionConfigurationSupport rcs) {
-				componentActivator.unsetRegionConfigurationSupport(rcs);
-			}
-				});
-
-		configAdminTracker.open();
-	}
-
-	public void dispose()
-	{
-		configAdminTracker.close();
-	}
-	
+    public static final String CONFIGURATION_ADMIN = "org.osgi.service.cm.ConfigurationAdmin";
+
+    private final ServiceTracker<ConfigurationAdmin, RegionConfigurationSupport> configAdminTracker;
+
+    public ConfigAdminTracker(final ComponentActivator componentActivator)
+    {
+
+        //TODO this assumes that there is 0 or 1 ca service visible to the bundle being extended.
+        //Is this sure to be true?
+        configAdminTracker = new ServiceTracker<ConfigurationAdmin, RegionConfigurationSupport>(
+            componentActivator.getBundleContext(), CONFIGURATION_ADMIN,
+            new ServiceTrackerCustomizer<ConfigurationAdmin, RegionConfigurationSupport>()
+            {
+
+                public RegionConfigurationSupport addingService(ServiceReference<ConfigurationAdmin> reference)
+                {
+                    return componentActivator.setRegionConfigurationSupport( reference );
+                }
+
+                public void modifiedService(ServiceReference<ConfigurationAdmin> reference,
+                    RegionConfigurationSupport service)
+                {
+                }
+
+                public void removedService(ServiceReference<ConfigurationAdmin> reference,
+                    RegionConfigurationSupport rcs)
+                {
+                    componentActivator.unsetRegionConfigurationSupport( rcs );
+                }
+            } );
+
+        configAdminTracker.open();
+    }
+
+    public void dispose()
+    {
+        configAdminTracker.close();
+    }
+
 }

Modified: felix/sandbox/scr-r7/src/main/java/org/apache/felix/scr/impl/manager/RegionConfigurationSupport.java
URL: http://svn.apache.org/viewvc/felix/sandbox/scr-r7/src/main/java/org/apache/felix/scr/impl/manager/RegionConfigurationSupport.java?rev=1755041&r1=1755040&r2=1755041&view=diff
==============================================================================
--- felix/sandbox/scr-r7/src/main/java/org/apache/felix/scr/impl/manager/RegionConfigurationSupport.java (original)
+++ felix/sandbox/scr-r7/src/main/java/org/apache/felix/scr/impl/manager/RegionConfigurationSupport.java Wed Aug  3 08:17:08 2016
@@ -58,7 +58,7 @@ public abstract class RegionConfiguratio
     private ServiceRegistration<ConfigurationListener> m_registration;
 
     /**
-     *
+     * 
      * @param bundleContext of the ConfigurationAdmin we are tracking
      * @param registry
      */
@@ -124,7 +124,7 @@ public abstract class RegionConfiguratio
             }
             final List<String> confPids = holder.getComponentMetadata().getConfigurationPid();
 
-            final ConfigurationAdmin ca = getConfigAdmin();
+            final ConfigurationAdmin ca = getConfigAdmin( bundleContext );
             try
             {
                 for ( final String confPid : confPids )
@@ -441,7 +441,7 @@ public abstract class RegionConfiguratio
     {
         try
         {
-            final ConfigurationAdmin ca = getConfigAdmin();
+            final ConfigurationAdmin ca = getConfigAdmin( bundleContext );
             try
             {
                 Configuration[] configs = ca.listConfigurations( filter( pid.getRawPid() ) );
@@ -631,9 +631,9 @@ public abstract class RegionConfiguratio
         return value.replaceAll( "([\\\\\\*\\(\\)])", "\\\\$1" );
     }
 
-    private ConfigurationAdmin getConfigAdmin()
+    private ConfigurationAdmin getConfigAdmin(BundleContext bundleContext)
     {
-        return caBundleContext.getService( caReference );
+        return bundleContext.getService( caReference );
     }
 
 }



Mime
View raw message