httplite: put 'shutdown server on last client deregistration' optimization in a thread and wait 30 seconds before checking if no clients are registered.  Fixes issue in which sole client "bounces" registration service on start and causes deadlock in server.

git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@1228773 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/httplite/minimum/src/main/java/org/apache/felix/httplite/osgi/HttpServiceFactoryImpl.java b/httplite/minimum/src/main/java/org/apache/felix/httplite/osgi/HttpServiceFactoryImpl.java
index 8d61bcc..295880c 100644
--- a/httplite/minimum/src/main/java/org/apache/felix/httplite/osgi/HttpServiceFactoryImpl.java
+++ b/httplite/minimum/src/main/java/org/apache/felix/httplite/osgi/HttpServiceFactoryImpl.java
@@ -130,17 +130,34 @@
 
         if (m_registrations.size() == 0 && m_server.getState() == Server.ACTIVE_STATE)
         {
-            try
-            {
-                m_logger.log(Logger.LOG_INFO,
-                    "Stopping http server since no clients are registered.");
-                m_server.setStopping();
-                m_server.stop();
-            }
-            catch (InterruptedException e)
-            {
-                return;
-            }
+            (new Thread(new Runnable()
+            {                
+                public void run()
+                {
+                    try
+                    {
+                        Thread.sleep( 1000 * 30 );
+                        
+                        if (m_registrations == null || m_server == null)
+                        {
+                            return;
+                        }
+                        
+                        if (m_registrations.size() == 0 && m_server.getState() == Server.ACTIVE_STATE) 
+                        {
+                            m_logger.log(Logger.LOG_INFO,
+                                "Stopping http server since no clients are registered.");
+                            m_server.setStopping();
+                            m_server.stop();
+                        }
+                    }
+                    catch (InterruptedException e)
+                    {
+                        return;
+                    }
+                    
+                }
+            })).start();            
         }
     }
 }
diff --git a/httplite/minimum/src/main/java/org/apache/felix/httplite/server/ThreadPool.java b/httplite/minimum/src/main/java/org/apache/felix/httplite/server/ThreadPool.java
index 87cadf1..0af541d 100644
--- a/httplite/minimum/src/main/java/org/apache/felix/httplite/server/ThreadPool.java
+++ b/httplite/minimum/src/main/java/org/apache/felix/httplite/server/ThreadPool.java
@@ -288,6 +288,8 @@
                         m_shutdownGate.open();
                         m_shutdownGate = null;
                         m_state = Server.INACTIVE_STATE;
+                        m_logger.log(Logger.LOG_DEBUG,
+                            "Server shutdown complete.");
                     }
                     // Return to kill the thread by exiting our run method.
                     return;