You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@felix.apache.org by dj...@apache.org on 2016/08/03 05:39:00 UTC
svn commit: r1755019 - in
/felix/trunk/scr/src/main/java/org/apache/felix/scr/impl: Activator.java
BundleComponentActivator.java
Author: djencks
Date: Wed Aug 3 05:39:00 2016
New Revision: 1755019
URL: http://svn.apache.org/viewvc?rev=1755019&view=rev
Log:
FELIX-5318 Use lock rather than countdown latch to protect bundle start/destroy actions
Modified:
felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/Activator.java
felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/BundleComponentActivator.java
Modified: felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/Activator.java
URL: http://svn.apache.org/viewvc/felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/Activator.java?rev=1755019&r1=1755018&r2=1755019&view=diff
==============================================================================
--- felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/Activator.java (original)
+++ felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/Activator.java Wed Aug 3 05:39:00 2016
@@ -23,8 +23,9 @@ 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.helper.SimpleLogger;
@@ -250,39 +251,67 @@ public class Activator extends AbstractE
{
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
{
+ 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 );
}
}
@@ -408,7 +437,7 @@ public class Activator extends AbstractE
*/
private void disposeComponents(Bundle bundle)
{
- final Object ga;
+ final BundleComponentActivator ga;
synchronized ( m_componentBundles )
{
ga = m_componentBundles.remove( bundle.getBundleId() );
@@ -420,7 +449,7 @@ public class Activator extends AbstractE
{
int reason = isStopping()? ComponentConstants.DEACTIVATION_REASON_DISPOSED
: ComponentConstants.DEACTIVATION_REASON_BUNDLE_STOPPED;
- ( (BundleComponentActivator) ga ).dispose( reason );
+ ga.dispose( reason );
}
catch ( Exception e )
{
Modified: felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/BundleComponentActivator.java
URL: http://svn.apache.org/viewvc/felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/BundleComponentActivator.java?rev=1755019&r1=1755018&r2=1755019&view=diff
==============================================================================
--- felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/BundleComponentActivator.java (original)
+++ felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/BundleComponentActivator.java Wed Aug 3 05:39:00 2016
@@ -553,6 +553,7 @@ public class BundleComponentActivator im
catch ( InterruptedException e )
{
//ignore interruption during concurrent shutdown.
+ Thread.currentThread().interrupt();
}
}