Patch to work around a JDK bug where native methods/libraries causing conflicts
which results in some sort of deadlock. (FELIX-619)
git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@775984 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/shell.tui/src/main/java/org/apache/felix/shell/tui/Activator.java b/shell.tui/src/main/java/org/apache/felix/shell/tui/Activator.java
index b964a2e..993482a 100644
--- a/shell.tui/src/main/java/org/apache/felix/shell/tui/Activator.java
+++ b/shell.tui/src/main/java/org/apache/felix/shell/tui/Activator.java
@@ -41,14 +41,8 @@
{
synchronized (Activator.this)
{
- // Ignore additional services if we already have one.
- if ((event.getType() == ServiceEvent.REGISTERED)
- && (m_shellRef != null))
- {
- return;
- }
// Initialize the service if we don't have one.
- else if ((event.getType() == ServiceEvent.REGISTERED)
+ if ((event.getType() == ServiceEvent.REGISTERED)
&& (m_shellRef == null))
{
initializeService();
@@ -92,17 +86,15 @@
private synchronized void initializeService()
{
- if (m_shell != null)
+ if (m_shell == null)
{
- return;
+ m_shellRef = m_context.getServiceReference(
+ org.apache.felix.shell.ShellService.class.getName());
+ if (m_shellRef != null)
+ {
+ m_shell = (ShellService) m_context.getService(m_shellRef);
+ }
}
- m_shellRef = m_context.getServiceReference(
- org.apache.felix.shell.ShellService.class.getName());
- if (m_shellRef == null)
- {
- return;
- }
- m_shell = (ShellService) m_context.getService(m_shellRef);
}
public void stop(BundleContext context)
@@ -127,62 +119,73 @@
String line = null;
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
- // Check to see if we have stdin.
try
{
- System.in.available();
- }
- catch (IOException ex)
- {
- m_stop = true;
- }
-
- while (!m_stop)
- {
- System.out.print("-> ");
-
- try
+ boolean needPrompt = true;
+ int available;
+ while (!m_stop)
{
+ if (needPrompt)
+ {
+ System.out.print("-> ");
+ needPrompt = false;
+ }
+
+ available = System.in.available();
+
+ if (available == 0)
+ {
+ try
+ {
+ Thread.sleep(200);
+ }
+ catch (InterruptedException ex)
+ {
+ // No one should be interrupting this thread, so
+ // ignore it.
+ }
+ continue;
+ }
+
line = in.readLine();
- }
- catch (IOException ex)
- {
- System.err.println("ShellTUI: Error reading from stdin...exiting.");
- break;
- }
-
- synchronized (Activator.this)
- {
if (line == null)
{
System.err.println("ShellTUI: No standard input...exiting.");
break;
}
-
- if (m_shell == null)
- {
- System.out.println("No impl service available.");
- continue;
- }
+ needPrompt = true;
line = line.trim();
-
if (line.length() == 0)
{
continue;
}
- try
+ synchronized (Activator.this)
{
- m_shell.executeCommand(line, System.out, System.err);
- }
- catch (Exception ex)
- {
- System.err.println("ShellTUI: " + ex);
- ex.printStackTrace();
+ if (m_shell == null)
+ {
+ System.out.println("No impl service available.");
+ continue;
+ }
+
+ try
+ {
+ m_shell.executeCommand(line, System.out, System.err);
+ }
+ catch (Exception ex)
+ {
+ System.err.println("ShellTUI: " + ex);
+ ex.printStackTrace();
+ }
}
}
}
+ catch (IOException ex)
+ {
+ // Any IO error causes the thread to exit.
+ System.err.println("ShellTUI: Unable to read from stdin...exiting.");
+ }
}
}
-}
+}
\ No newline at end of file