[FELIX-4309] Make timeout configurable

git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@1543739 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/scr/src/main/java/org/apache/felix/scr/impl/Activator.java b/scr/src/main/java/org/apache/felix/scr/impl/Activator.java
index f3cf693..9ea1d8a 100644
--- a/scr/src/main/java/org/apache/felix/scr/impl/Activator.java
+++ b/scr/src/main/java/org/apache/felix/scr/impl/Activator.java
@@ -24,7 +24,6 @@
 import java.util.HashMap;
 import java.util.Map;
 import java.util.concurrent.CountDownLatch;
-import java.util.concurrent.FutureTask;
 import java.util.concurrent.TimeUnit;
 
 import org.apache.felix.scr.impl.config.ScrConfiguration;
@@ -187,7 +186,7 @@
 
         public void destroy() {
             try {
-                this.started.await(60, TimeUnit.SECONDS);
+                this.started.await(m_configuration.stopTimeout(), TimeUnit.MILLISECONDS);
             } catch (InterruptedException e) {
                 log( LogService.LOG_WARNING, m_context.getBundle(), "The wait for bundle {0}/{1} being started before destruction has been interrupted.",
                         new Object[] {bundle.getSymbolicName(), bundle.getBundleId()}, e );
diff --git a/scr/src/main/java/org/apache/felix/scr/impl/config/ScrConfiguration.java b/scr/src/main/java/org/apache/felix/scr/impl/config/ScrConfiguration.java
index 46a1f51..1f96d31 100644
--- a/scr/src/main/java/org/apache/felix/scr/impl/config/ScrConfiguration.java
+++ b/scr/src/main/java/org/apache/felix/scr/impl/config/ScrConfiguration.java
@@ -63,10 +63,14 @@
     public static final String PROP_DELAYED_KEEP_INSTANCES = "ds.delayed.keepInstances";
 
     public static final String PROP_INFO_SERVICE = "ds.info.service";
-    
+
     public static final String PROP_LOCK_TIMEOUT = "ds.lock.timeout.milliseconds";
-    
+
+    public static final String PROP_STOP_TIMEOUT = "ds.stop.timeout.milliseconds";
+
     public static final long DEFAULT_LOCK_TIMEOUT_MILLISECONDS = 5000;
+
+    public static final long DEFAULT_STOP_TIMEOUT_MILLISECONDS = 60000;
     
     public static final String PROP_LOGLEVEL = "ds.loglevel";
 
@@ -92,6 +96,8 @@
     
     private long lockTimeout = DEFAULT_LOCK_TIMEOUT_MILLISECONDS;
 
+    private long stopTimeout = DEFAULT_STOP_TIMEOUT_MILLISECONDS;
+
     private BundleContext bundleContext;
 
     private ServiceRegistration managedService;
@@ -146,6 +152,7 @@
                 keepInstances = false;
                 infoAsService = false;
                 lockTimeout = DEFAULT_LOCK_TIMEOUT_MILLISECONDS;
+                stopTimeout = DEFAULT_STOP_TIMEOUT_MILLISECONDS;
             }
             else
             {
@@ -154,6 +161,7 @@
                 keepInstances = getDefaultKeepInstances();
                 infoAsService = getDefaultInfoAsService();
                 lockTimeout = getDefaultLockTimeout();
+                stopTimeout = getDefaultStopTimeout();
             }
         }
         else
@@ -164,6 +172,8 @@
             infoAsService = VALUE_TRUE.equalsIgnoreCase( String.valueOf( config.get( PROP_INFO_SERVICE) ) );
             Long timeout = ( Long ) config.get( PROP_LOCK_TIMEOUT );
             lockTimeout = timeout == null? DEFAULT_LOCK_TIMEOUT_MILLISECONDS: timeout;
+            timeout = ( Long ) config.get( PROP_STOP_TIMEOUT );
+            stopTimeout = timeout == null? DEFAULT_STOP_TIMEOUT_MILLISECONDS: timeout;
         }
         if ( scrCommand != null )
         {
@@ -202,6 +212,11 @@
         return lockTimeout;
     }
 
+    public long stopTimeout()
+    {
+        return stopTimeout;
+    }
+
     private boolean getDefaultFactoryEnabled()
     {
         return VALUE_TRUE.equals( bundleContext.getProperty( PROP_FACTORY_ENABLED ) );
@@ -234,6 +249,16 @@
         return Long.parseLong( val );
     }
 
+    private long getDefaultStopTimeout()
+    {
+        String val = bundleContext.getProperty( PROP_STOP_TIMEOUT);
+        if ( val == null)
+        {
+            return DEFAULT_STOP_TIMEOUT_MILLISECONDS;
+        }
+        return Long.parseLong( val );
+    }
+
 
     private int getLogLevel( final Object levelObject )
     {