FELIX-4011 getService can wait if another thread is creating the impl object
git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@1467353 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/scr/src/main/java/org/apache/felix/scr/impl/manager/AbstractComponentManager.java b/scr/src/main/java/org/apache/felix/scr/impl/manager/AbstractComponentManager.java
index 519023f..84d04d2 100644
--- a/scr/src/main/java/org/apache/felix/scr/impl/manager/AbstractComponentManager.java
+++ b/scr/src/main/java/org/apache/felix/scr/impl/manager/AbstractComponentManager.java
@@ -191,7 +191,7 @@
}
}
- private long getLockTimeout()
+ long getLockTimeout()
{
BundleComponentActivator activator = getActivator();
if ( activator != null )
diff --git a/scr/src/main/java/org/apache/felix/scr/impl/manager/ComponentContextImpl.java b/scr/src/main/java/org/apache/felix/scr/impl/manager/ComponentContextImpl.java
index 58dd806..dd89fd8 100644
--- a/scr/src/main/java/org/apache/felix/scr/impl/manager/ComponentContextImpl.java
+++ b/scr/src/main/java/org/apache/felix/scr/impl/manager/ComponentContextImpl.java
@@ -21,6 +21,8 @@
import java.util.Arrays;
import java.util.Dictionary;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
import org.apache.felix.scr.component.ExtComponentContext;
import org.apache.felix.scr.impl.BundleComponentActivator;
@@ -48,6 +50,8 @@
private final S m_implementationObject;
private volatile boolean m_implementationAccessible;
+
+ private final CountDownLatch accessibleLatch = new CountDownLatch(1);
ComponentContextImpl( AbstractComponentManager<S> componentManager, Bundle usingBundle, S implementationObject )
{
@@ -60,6 +64,10 @@
void setImplementationAccessible(boolean implementationAccessible)
{
this.m_implementationAccessible = implementationAccessible;
+ if (implementationAccessible)
+ {
+ accessibleLatch.countDown();
+ }
}
EdgeInfo getEdgeInfo(DependencyManager<S, ?> dm)
@@ -170,6 +178,17 @@
{
return m_implementationObject;
}
+ try
+ {
+ if (accessibleLatch.await( m_componentManager.getLockTimeout(), TimeUnit.MILLISECONDS ) && m_implementationAccessible)
+ {
+ return m_implementationObject;
+ }
+ }
+ catch ( InterruptedException e )
+ {
+ return null;
+ }
return null;
}
diff --git a/scr/src/main/java/org/apache/felix/scr/impl/manager/ImmediateComponentManager.java b/scr/src/main/java/org/apache/felix/scr/impl/manager/ImmediateComponentManager.java
index 0c17fd5..711632a 100644
--- a/scr/src/main/java/org/apache/felix/scr/impl/manager/ImmediateComponentManager.java
+++ b/scr/src/main/java/org/apache/felix/scr/impl/manager/ImmediateComponentManager.java
@@ -700,8 +700,7 @@
public S getService( Bundle bundle, ServiceRegistration<S> serviceRegistration )
{
- ComponentContextImpl<S> componentContext = m_componentContext;
- if ( componentContext == null )
+ if ( m_componentContext == null )
{
try
{