FELIX-3915 Fix timing hole between config admin and component holder creation/registration. Also java 5-ization
git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@1449277 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/scr/src/main/java/org/apache/felix/scr/impl/ComponentRegistry.java b/scr/src/main/java/org/apache/felix/scr/impl/ComponentRegistry.java
index 5e1f65b..6d10c76 100644
--- a/scr/src/main/java/org/apache/felix/scr/impl/ComponentRegistry.java
+++ b/scr/src/main/java/org/apache/felix/scr/impl/ComponentRegistry.java
@@ -21,6 +21,7 @@
import java.util.ArrayList;
import java.util.Arrays;
+import java.util.Collection;
import java.util.Dictionary;
import java.util.HashMap;
import java.util.HashSet;
@@ -380,12 +381,12 @@
* method throws a {@link ComponentException}.
*
* @param name The name to register the component under
- * @param component The component to register
+ * @param componentHolder The component to register
*
* @throws ComponentException if the name has not been reserved through
* {@link #checkComponentName(String)} yet.
*/
- final void registerComponentHolder( final ComponentRegistryKey key, ComponentHolder component )
+ final void registerComponentHolder( final ComponentRegistryKey key, ComponentHolder componentHolder )
{
synchronized ( m_componentHoldersByName )
{
@@ -393,17 +394,17 @@
if ( m_componentHoldersByName.get( key ) != null )
{
// this is not expected if all works ok
- throw new ComponentException( "The component name '" + component.getComponentMetadata().getName()
+ throw new ComponentException( "The component name '" + componentHolder.getComponentMetadata().getName()
+ "' has already been registered." );
}
- m_componentHoldersByName.put( key, component );
+ m_componentHoldersByName.put( key, componentHolder );
}
synchronized (m_componentHoldersByPid)
{
// See if the component declares a specific configuration pid (112.4.4 configuration-pid)
- String configurationPid = component.getComponentMetadata().getConfigurationPid();
+ String configurationPid = componentHolder.getComponentMetadata().getConfigurationPid();
// Since several components may refer to the same configuration pid, we have to
// store the component holder in a Set, in order to be able to lookup every
@@ -414,9 +415,15 @@
set = new HashSet<ComponentHolder>();
m_componentHoldersByPid.put(configurationPid, set);
}
- set.add(component);
+ set.add(componentHolder);
}
- }
+
+ if (configurationSupport != null)
+ {
+ configurationSupport.configureComponentHolder(componentHolder);
+ }
+
+ }
/**
* Returns the component registered under the given name or <code>null</code>
@@ -440,13 +447,12 @@
}
/**
- * Returns the list of ComponentHolder instances whose configuration pids are matching
+ * Returns the set of ComponentHolder instances whose configuration pids are matching
* the given pid.
* @param pid the pid candidate
- * @return a iterator of ComponentHolder, or an empty iterator if no ComponentHolders
- * are found
+ * @return the set of ComponentHolders matching the singleton pid supplied
*/
- public final Iterator<ComponentHolder> getComponentHoldersByPid(String pid)
+ public final Collection<ComponentHolder> getComponentHoldersByPid(String pid)
{
Set<ComponentHolder> componentHoldersUsingPid = new HashSet<ComponentHolder>();
synchronized (m_componentHoldersByPid)
@@ -458,7 +464,7 @@
componentHoldersUsingPid.addAll(set);
}
}
- return componentHoldersUsingPid.iterator();
+ return componentHoldersUsingPid;
}
/**
@@ -548,11 +554,6 @@
holder = new ImmediateComponentHolder(activator, metadata);
}
- if (configurationSupport != null)
- {
- configurationSupport.configureComponentHolder(holder);
- }
-
return holder;
}
diff --git a/scr/src/main/java/org/apache/felix/scr/impl/config/ConfigurationSupport.java b/scr/src/main/java/org/apache/felix/scr/impl/config/ConfigurationSupport.java
index 4e21c6f..ea3d43c 100644
--- a/scr/src/main/java/org/apache/felix/scr/impl/config/ConfigurationSupport.java
+++ b/scr/src/main/java/org/apache/felix/scr/impl/config/ConfigurationSupport.java
@@ -19,6 +19,7 @@
package org.apache.felix.scr.impl.config;
import java.io.IOException;
+import java.util.Collection;
import java.util.Dictionary;
import java.util.Hashtable;
import java.util.Iterator;
@@ -182,33 +183,32 @@
// iterate over all components which must be configured with this pid
// (since DS 1.2, components may specify a specific configuration PID (112.4.4 configuration-pid)
- Iterator it;
+ Collection<ComponentHolder> holders;
if (factoryPid == null)
{
- it = this.m_registry.getComponentHoldersByPid(pid);
+ holders = this.m_registry.getComponentHoldersByPid(pid);
}
else
{
- it = this.m_registry.getComponentHoldersByPid(factoryPid);
+ holders = this.m_registry.getComponentHoldersByPid(factoryPid);
}
Activator.log(LogService.LOG_DEBUG, null, "configurationEvent: Handling "
+ ((event.getType() == ConfigurationEvent.CM_DELETED) ? "DELETE" : "UPDATE")
+ " of Configuration PID=" + pid, null);
- while (it.hasNext())
+ for ( ComponentHolder componentHolder: holders )
{
- final ComponentHolder cm = (ComponentHolder) it.next();
- if (!cm.getComponentMetadata().isConfigurationIgnored())
+ if (!componentHolder.getComponentMetadata().isConfigurationIgnored())
{
switch (event.getType()) {
case ConfigurationEvent.CM_DELETED:
- cm.configurationDeleted(pid);
+ componentHolder.configurationDeleted(pid);
break;
case ConfigurationEvent.CM_UPDATED:
- final BundleComponentActivator activator = cm.getActivator();
+ final BundleComponentActivator activator = componentHolder.getActivator();
if (activator == null)
{
break;
@@ -238,13 +238,13 @@
.getBundle().getLocation() );
if ( dict != null )
{
- cm.configurationUpdated( pid, dict );
+ componentHolder.configurationUpdated( pid, dict );
}
}
else
{
Activator.log( LogService.LOG_WARNING, null, "Cannot reconfigure component "
- + cm.getComponentMetadata().getName(), null );
+ + componentHolder.getComponentMetadata().getName(), null );
Activator.log( LogService.LOG_WARNING, null,
"Component Bundle's Configuration Admin is not compatible with " +
"ours. This happens if multiple Configuration Admin API versions " +