FELIX-3826 fix race enabling components. Also a little more generics
git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@1424318 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/scr/src/main/java/org/apache/felix/scr/impl/config/ImmediateComponentHolder.java b/scr/src/main/java/org/apache/felix/scr/impl/config/ImmediateComponentHolder.java
index c46c9a1..be5d1ed 100644
--- a/scr/src/main/java/org/apache/felix/scr/impl/config/ImmediateComponentHolder.java
+++ b/scr/src/main/java/org/apache/felix/scr/impl/config/ImmediateComponentHolder.java
@@ -76,7 +76,7 @@
* The values are the {@link ImmediateComponentManager component instances}
* created on behalf of the configurations.
*/
- private final Map m_components;
+ private final Map<String, ImmediateComponentManager> m_components;
/**
* The special component used if there is no configuration or a singleton
@@ -103,7 +103,7 @@
* {@link #configurationUpdated(String, Dictionary)} method are also
* enabled. Otherwise they are not enabled immediately.
*/
- private boolean m_enabled;
+ private volatile boolean m_enabled;
private final ComponentMethods m_componentMethods;
@@ -111,7 +111,7 @@
{
this.m_activator = activator;
this.m_componentMetadata = metadata;
- this.m_components = new HashMap();
+ this.m_components = new HashMap<String, ImmediateComponentManager>();
this.m_componentMethods = new ComponentMethods();
this.m_singleComponent = createComponentManager();
this.m_enabled = false;
@@ -220,7 +220,7 @@
// replace the single component field with another
// entry from the map
- m_singleComponent = ( ImmediateComponentManager ) m_components.values().iterator().next();
+ m_singleComponent = m_components.values().iterator().next();
}
}
@@ -336,6 +336,7 @@
public void enableComponents( final boolean async )
{
+ m_enabled = true;
final ImmediateComponentManager[] cms = getComponentManagers( false );
if ( cms == null )
{
@@ -343,13 +344,12 @@
}
else
{
- for ( int i = 0; i < cms.length; i++ )
+ for ( ImmediateComponentManager cm : cms )
{
- cms[i].enable( async );
+ cm.enable( async );
}
}
- m_enabled = true;
}
@@ -364,9 +364,9 @@
}
else
{
- for ( int i = 0; i < cms.length; i++ )
+ for ( ImmediateComponentManager cm : cms )
{
- cms[i].disable( async );
+ cm.disable( async );
}
}
}
@@ -386,9 +386,9 @@
}
else
{
- for ( int i = 0; i < cms.length; i++ )
+ for ( ImmediateComponentManager cm : cms )
{
- cms[i].dispose( reason );
+ cm.dispose( reason );
}
}
}
@@ -426,7 +426,7 @@
}
else
{
- m_singleComponent = ( ImmediateComponentManager ) m_components.values().iterator().next();
+ m_singleComponent = m_components.values().iterator().next();
}
}
}
@@ -472,7 +472,7 @@
{
synchronized ( m_components )
{
- return ( ImmediateComponentManager ) m_components.get( pid );
+ return m_components.get( pid );
}
}
@@ -481,7 +481,7 @@
{
synchronized ( m_components )
{
- return ( ImmediateComponentManager ) m_components.remove( pid );
+ return m_components.remove( pid );
}
}