felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From db...@apache.org
Subject svn commit: r986322 - in /felix/trunk/gogo: runtime/src/main/java/org/apache/felix/gogo/runtime/ runtime/src/main/java/org/apache/felix/gogo/runtime/activator/ shell/src/main/java/org/apache/felix/gogo/shell/
Date Tue, 17 Aug 2010 14:21:17 GMT
Author: dbaum
Date: Tue Aug 17 14:21:16 2010
New Revision: 986322

URL: http://svn.apache.org/viewvc?rev=986322&view=rev
Log:
close all sessions when runtime is stopped (FELIX-2545).
quit console if session is closed.

Modified:
    felix/trunk/gogo/runtime/src/main/java/org/apache/felix/gogo/runtime/CommandProcessorImpl.java
    felix/trunk/gogo/runtime/src/main/java/org/apache/felix/gogo/runtime/CommandSessionImpl.java
    felix/trunk/gogo/runtime/src/main/java/org/apache/felix/gogo/runtime/activator/Activator.java
    felix/trunk/gogo/shell/src/main/java/org/apache/felix/gogo/shell/Console.java

Modified: felix/trunk/gogo/runtime/src/main/java/org/apache/felix/gogo/runtime/CommandProcessorImpl.java
URL: http://svn.apache.org/viewvc/felix/trunk/gogo/runtime/src/main/java/org/apache/felix/gogo/runtime/CommandProcessorImpl.java?rev=986322&r1=986321&r2=986322&view=diff
==============================================================================
--- felix/trunk/gogo/runtime/src/main/java/org/apache/felix/gogo/runtime/CommandProcessorImpl.java
(original)
+++ felix/trunk/gogo/runtime/src/main/java/org/apache/felix/gogo/runtime/CommandProcessorImpl.java
Tue Aug 17 14:21:16 2010
@@ -27,6 +27,7 @@ import java.util.LinkedHashMap;
 import java.util.Map;
 import java.util.Set;
 import java.util.TreeSet;
+import java.util.WeakHashMap;
 import java.util.Map.Entry;
 
 import org.osgi.framework.BundleContext;
@@ -42,6 +43,7 @@ public class CommandProcessorImpl implem
     protected final Map<String, Object> commands = new LinkedHashMap<String, Object>();
     protected final BundleContext context;
     protected final ThreadIO threadIO;
+    protected final WeakHashMap<CommandSession, Object> sessions = new WeakHashMap<CommandSession,
Object>();
 
     public CommandProcessorImpl(ThreadIO tio, BundleContext context)
     {
@@ -54,9 +56,19 @@ public class CommandProcessorImpl implem
 
     public CommandSession createSession(InputStream in, PrintStream out, PrintStream err)
     {
-        return new CommandSessionImpl(this, in, out, err);
+        CommandSessionImpl session = new CommandSessionImpl(this, in, out, err);
+        sessions.put(session, null);
+        return session;
     }
 
+    public void stop()
+    {
+        for (CommandSession session : sessions.keySet())
+        {
+            session.close();
+        }
+    }
+    
     public void addConverter(Converter c)
     {
         converters.add(c);

Modified: felix/trunk/gogo/runtime/src/main/java/org/apache/felix/gogo/runtime/CommandSessionImpl.java
URL: http://svn.apache.org/viewvc/felix/trunk/gogo/runtime/src/main/java/org/apache/felix/gogo/runtime/CommandSessionImpl.java?rev=986322&r1=986321&r2=986322&view=diff
==============================================================================
--- felix/trunk/gogo/runtime/src/main/java/org/apache/felix/gogo/runtime/CommandSessionImpl.java
(original)
+++ felix/trunk/gogo/runtime/src/main/java/org/apache/felix/gogo/runtime/CommandSessionImpl.java
Tue Aug 17 14:21:16 2010
@@ -33,6 +33,7 @@ import java.util.*;
 
 public class CommandSessionImpl implements CommandSession, Converter
 {
+    public static final String SESSION_CLOSED = "session is closed";
     public static final String VARIABLES = ".variables";
     public static final String COMMANDS = ".commands";
     public static final String CONTEXT = ".context";
@@ -71,7 +72,7 @@ public class CommandSessionImpl implemen
 
         if (closed)
         {
-            throw new IllegalStateException("session is closed");
+            throw new IllegalStateException(SESSION_CLOSED);
         }
 
         Closure impl = new Closure(this, null, commandline);

Modified: felix/trunk/gogo/runtime/src/main/java/org/apache/felix/gogo/runtime/activator/Activator.java
URL: http://svn.apache.org/viewvc/felix/trunk/gogo/runtime/src/main/java/org/apache/felix/gogo/runtime/activator/Activator.java?rev=986322&r1=986321&r2=986322&view=diff
==============================================================================
--- felix/trunk/gogo/runtime/src/main/java/org/apache/felix/gogo/runtime/activator/Activator.java
(original)
+++ felix/trunk/gogo/runtime/src/main/java/org/apache/felix/gogo/runtime/activator/Activator.java
Tue Aug 17 14:21:16 2010
@@ -90,6 +90,7 @@ public class Activator implements Bundle
         commandTracker.close();
         converterTracker.close();
         threadio.stop();
+        processor.stop();
     }
 
     private ServiceTracker trackOSGiCommands(final BundleContext context)

Modified: felix/trunk/gogo/shell/src/main/java/org/apache/felix/gogo/shell/Console.java
URL: http://svn.apache.org/viewvc/felix/trunk/gogo/shell/src/main/java/org/apache/felix/gogo/shell/Console.java?rev=986322&r1=986321&r2=986322&view=diff
==============================================================================
--- felix/trunk/gogo/shell/src/main/java/org/apache/felix/gogo/shell/Console.java (original)
+++ felix/trunk/gogo/shell/src/main/java/org/apache/felix/gogo/shell/Console.java Tue Aug
17 14:21:16 2010
@@ -44,31 +44,43 @@ public class Console implements Runnable
         {
             while (!quit)
             {
-                try
+                Object prompt = session.get("prompt");
+                if (prompt == null)
                 {
-                    Object prompt = session.get("prompt");
-                    if (prompt == null)
-                    {
-                        prompt = "g! ";
-                    }
+                    prompt = "g! ";
+                }
 
-                    CharSequence line = getLine(prompt.toString());
+                CharSequence line = getLine(prompt.toString());
 
-                    if (line == null)
-                    {
-                        break;
-                    }
+                if (line == null)
+                {
+                    break;
+                }
 
+                try
+                {
                     Object result = session.execute(line);
-                    session.put("_", result);    // set $_ to last result
+                    session.put("_", result); // set $_ to last result
 
-                    if (result != null && !Boolean.FALSE.equals(session.get(".Gogo.format")))
+                    if (result != null
+                        && !Boolean.FALSE.equals(session.get(".Gogo.format")))
                     {
                         out.println(session.format(result, Converter.INSPECT));
                     }
                 }
                 catch (Throwable e)
                 {
+                    final String SESSION_CLOSED = "session is closed";
+                    if ((e instanceof IllegalStateException) && SESSION_CLOSED.equals(e.getMessage()))
+                    {
+                        // FIXME: we assume IllegalStateException is because the session
is closed;
+                        // but it may be for another reason, so we also check the message
(yuk).
+                        // It would be better if the RFC-147 API threw a unique exception,
such as
+                        // org.osgi.service.command.SessionClosedException
+                        out.println("gosh: " + e);
+                        quit = true;
+                    }
+                    
                     if (!quit)
                     {
                         session.put("exception", e);
@@ -79,7 +91,8 @@ public class Console implements Runnable
                             loc = "gogo";
                         }
 
-                        out.println(loc + ": " + e.getClass().getSimpleName() + ": " + e.getMessage());
+                        out.println(loc + ": " + e.getClass().getSimpleName() + ": "
+                            + e.getMessage());
                     }
                 }
             }
@@ -106,7 +119,7 @@ public class Console implements Runnable
             switch (c)
             {
                 case -1:
-                case 4:    // EOT, ^D from telnet
+                case 4: // EOT, ^D from telnet
                     quit = true;
                     break;
 
@@ -138,9 +151,4 @@ public class Console implements Runnable
         return null;
     }
 
-    public void close()
-    {
-        quit = true;
-    }
-
 }



Mime
View raw message