FELIX-3888 Make the lock timeout a configuration property, and expose it in the config command

git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@1444491 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/scr/src/main/java/org/apache/felix/scr/impl/ScrCommand.java b/scr/src/main/java/org/apache/felix/scr/impl/ScrCommand.java
index bcc9cf8..9823ad2 100644
--- a/scr/src/main/java/org/apache/felix/scr/impl/ScrCommand.java
+++ b/scr/src/main/java/org/apache/felix/scr/impl/ScrCommand.java
@@ -457,6 +457,8 @@
         out.println(scrConfiguration.isFactoryEnabled() ? "Supported" : "Unsupported");
         out.print("Keep instances with no references: ");
         out.println(scrConfiguration.keepInstances() ? "Supported" : "Unsupported");
+        out.print("Lock timeount milliseconds: ");
+        out.println(scrConfiguration.lockTimeout());
         out.print("Info Service registered: ");
         out.println(scrConfiguration.infoAsService() ? "Supported" : "Unsupported");
     }
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 e8526ab..c1adcee 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
@@ -64,6 +64,8 @@
 
     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_LOGLEVEL = "ds.loglevel";
 
     private static final String LOG_LEVEL_DEBUG = "debug";
@@ -85,6 +87,8 @@
     private boolean keepInstances;
     
     private boolean infoAsService;
+    
+    private long lockTimeout = 5000;//milliseconds
 
     private BundleContext bundleContext;
 
@@ -139,6 +143,7 @@
                 factoryEnabled = false;
                 keepInstances = false;
                 infoAsService = false;
+                lockTimeout = 5000;
             }
             else
             {
@@ -146,6 +151,7 @@
                 factoryEnabled = getDefaultFactoryEnabled();
                 keepInstances = getDefaultKeepInstances();
                 infoAsService = getDefaultInfoAsService();
+                lockTimeout = getDefaultLockTimeout();
             }
         }
         else
@@ -154,6 +160,8 @@
             factoryEnabled = VALUE_TRUE.equalsIgnoreCase( String.valueOf( config.get( PROP_FACTORY_ENABLED ) ) );
             keepInstances = VALUE_TRUE.equalsIgnoreCase( String.valueOf( config.get( PROP_DELAYED_KEEP_INSTANCES ) ) );
             infoAsService = VALUE_TRUE.equalsIgnoreCase( String.valueOf( config.get( PROP_INFO_SERVICE) ) );
+            Long timeout = ( Long ) config.get( PROP_LOCK_TIMEOUT );
+            lockTimeout = timeout == null? 5000: timeout;
         }
         if ( scrCommand != null )
         {
@@ -187,6 +195,10 @@
         return infoAsService;
     }
 
+    public long lockTimeout()
+    {
+        return lockTimeout;
+    }
 
     private boolean getDefaultFactoryEnabled()
     {
@@ -210,6 +222,16 @@
         return VALUE_TRUE.equalsIgnoreCase( bundleContext.getProperty( PROP_INFO_SERVICE) );
     }
 
+    private long getDefaultLockTimeout()
+    {
+        String val = bundleContext.getProperty( PROP_LOCK_TIMEOUT);
+        if ( val == null)
+        {
+            return 5000;
+        }
+        return Long.parseLong( val );
+    }
+
 
     private int getLogLevel( final Object levelObject )
     {
diff --git a/scr/src/main/java/org/apache/felix/scr/impl/config/ScrManagedServiceMetaTypeProvider.java b/scr/src/main/java/org/apache/felix/scr/impl/config/ScrManagedServiceMetaTypeProvider.java
index 5e638cb..ac9e27a 100644
--- a/scr/src/main/java/org/apache/felix/scr/impl/config/ScrManagedServiceMetaTypeProvider.java
+++ b/scr/src/main/java/org/apache/felix/scr/impl/config/ScrManagedServiceMetaTypeProvider.java
@@ -105,9 +105,17 @@
         adList.add( new AttributeDefinitionImpl(
                 ScrConfiguration.PROP_INFO_SERVICE,
                 "Bind Info Service",
-                "Whether to bind a service backing the console commands providing info on components ", 
+                "Whether to bind a service backing the console commands providing info on components.", 
                 this.getScrConfiguration().infoAsService() ) );
 
+        adList.add( new AttributeDefinitionImpl(
+                ScrConfiguration.PROP_LOCK_TIMEOUT,
+                "Lock timeout milliseconds",
+                "How long a lock is held before releasing due to suspected deadlock", 
+                AttributeDefinition.LONG,
+                new String[] { String.valueOf(this.getScrConfiguration().lockTimeout())}, 
+                0, null, null) );
+
         return new ObjectClassDefinition()
         {
 
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 4c10674..408a1b7 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
@@ -105,8 +105,6 @@
 
     private final ReentrantLock m_stateLock;
 
-    private long m_timeout = 5000;
-
     protected volatile boolean enabled;
     protected volatile CountDownLatch enabledLatch;
     private final Object enabledLatchLock = new Object();
@@ -180,7 +178,7 @@
     {
         try
         {
-            if (!m_stateLock.tryLock( m_timeout, TimeUnit.MILLISECONDS ) )
+            if (!m_stateLock.tryLock( getActivator().getConfiguration().lockTimeout(), TimeUnit.MILLISECONDS ) )
             {
             	dumpThreads();
                 throw new IllegalStateException( "Could not obtain lock" );