You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@felix.apache.org by ri...@apache.org on 2009/05/18 17:22:38 UTC
svn commit: r775984 -
/felix/trunk/shell.tui/src/main/java/org/apache/felix/shell/tui/Activator.java
Author: rickhall
Date: Mon May 18 15:22:37 2009
New Revision: 775984
URL: http://svn.apache.org/viewvc?rev=775984&view=rev
Log:
Patch to work around a JDK bug where native methods/libraries causing conflicts
which results in some sort of deadlock. (FELIX-619)
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=775984&r1=775983&r2=775984&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 Mon May 18 15:22:37 2009
@@ -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)
- {
- return;
- }
- m_shellRef = m_context.getServiceReference(
- org.apache.felix.shell.ShellService.class.getName());
- if (m_shellRef == 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_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;
- }
+ boolean needPrompt = true;
+ int available;
+ while (!m_stop)
+ {
+ if (needPrompt)
+ {
+ System.out.print("-> ");
+ needPrompt = false;
+ }
- while (!m_stop)
- {
- System.out.print("-> ");
+ available = System.in.available();
- try
- {
- line = in.readLine();
- }
- catch (IOException ex)
- {
- System.err.println("ShellTUI: Error reading from stdin...exiting.");
- break;
- }
+ if (available == 0)
+ {
+ try
+ {
+ Thread.sleep(200);
+ }
+ catch (InterruptedException ex)
+ {
+ // No one should be interrupting this thread, so
+ // ignore it.
+ }
+ continue;
+ }
- synchronized (Activator.this)
- {
+ line = in.readLine();
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