felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pa...@apache.org
Subject svn commit: r642238 - /felix/trunk/shell.tui/src/main/java/org/apache/felix/shell/tui/Activator.java
Date Fri, 28 Mar 2008 14:12:58 GMT
Author: pauls
Date: Fri Mar 28 07:12:54 2008
New Revision: 642238

URL: http://svn.apache.org/viewvc?rev=642238&view=rev
Log:
The shell has a problem when being stopped using the BundleActivator.stop() method but not
getting any input because it is blocked on System.in. This patch fixes the issue by using
the ready() method to wait until input is available. There still is a race condition in case
more then one Thread is listening on System.in but we can ignore this for now because in case
the race condition happens we default to the old behaviour.

Modified:
    felix/trunk/shell.tui/src/main/java/org/apache/felix/shell/tui/Activator.java

Modified: felix/trunk/shell.tui/src/main/java/org/apache/felix/shell/tui/Activator.java
URL: http://svn.apache.org/viewvc/felix/trunk/shell.tui/src/main/java/org/apache/felix/shell/tui/Activator.java?rev=642238&r1=642237&r2=642238&view=diff
==============================================================================
--- felix/trunk/shell.tui/src/main/java/org/apache/felix/shell/tui/Activator.java (original)
+++ felix/trunk/shell.tui/src/main/java/org/apache/felix/shell/tui/Activator.java Fri Mar
28 07:12:54 2008
@@ -83,10 +83,13 @@
         // since one might already be available.
         initializeService();
 
-        // Start impl thread.
-        m_thread = new Thread(
-            m_runnable = new ShellTuiRunnable(),
-            "Felix Shell TUI");
+        synchronized (this)
+        {
+            // Start impl thread.
+            m_thread = new Thread(
+                m_runnable = new ShellTuiRunnable(),
+                "Felix Shell TUI");
+        }
         m_thread.start();
     }
 
@@ -107,16 +110,19 @@
 
     public void stop(BundleContext context)
     {
-        if (m_runnable != null)
+        synchronized (this)
         {
-            m_runnable.stop();
-            m_thread.interrupt();
+            if (m_runnable != null)
+            {
+                m_runnable.stop();
+                m_thread.interrupt();
+            }
         }
     }
 
     private class ShellTuiRunnable implements Runnable
     {
-        private boolean stop = false;
+        private volatile boolean stop = false;
 
         public void stop()
         {
@@ -127,15 +133,22 @@
         {
             String line = null;
             BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
-
             while (!stop)
             {
                 System.out.print("-> ");
 
                 try
                 {
+                    while (!in.ready())
+                    {
+                        Thread.sleep(20);
+                    }
                     line = in.readLine();
                 }
+                catch (InterruptedException ex)
+                {
+                    continue;
+                }
                 catch (IOException ex)
                 {
                     System.err.println("Could not read input, please try again.");
@@ -175,4 +188,4 @@
             }
         }
     }
-}
\ No newline at end of file
+}



Mime
View raw message