geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jdil...@apache.org
Subject svn commit: r697721 - in /geronimo/gshell/trunk/gshell-remote/gshell-remote-server/src/main/java/org/apache/geronimo/gshell/remote/server: ./ auth/ handler/ timeout/
Date Mon, 22 Sep 2008 09:13:57 GMT
Author: jdillon
Date: Mon Sep 22 02:13:56 2008
New Revision: 697721

URL: http://svn.apache.org/viewvc?rev=697721&view=rev
Log:
Added RemoteShellContextHolder to handle thread-based access to the RemoteShell's ShellContext,
Dropped related hacks
Added some more logging to a few places

Added:
    geronimo/gshell/trunk/gshell-remote/gshell-remote-server/src/main/java/org/apache/geronimo/gshell/remote/server/RemoteShellContextHolder.java
  (with props)
Modified:
    geronimo/gshell/trunk/gshell-remote/gshell-remote-server/src/main/java/org/apache/geronimo/gshell/remote/server/RemoteShellImpl.java
    geronimo/gshell/trunk/gshell-remote/gshell-remote-server/src/main/java/org/apache/geronimo/gshell/remote/server/RshServer.java
    geronimo/gshell/trunk/gshell-remote/gshell-remote-server/src/main/java/org/apache/geronimo/gshell/remote/server/RshServerCommand.java
    geronimo/gshell/trunk/gshell-remote/gshell-remote-server/src/main/java/org/apache/geronimo/gshell/remote/server/auth/BogusLoginModule.java
    geronimo/gshell/trunk/gshell-remote/gshell-remote-server/src/main/java/org/apache/geronimo/gshell/remote/server/handler/CloseShellHandler.java
    geronimo/gshell/trunk/gshell-remote/gshell-remote-server/src/main/java/org/apache/geronimo/gshell/remote/server/handler/ExecuteHandler.java
    geronimo/gshell/trunk/gshell-remote/gshell-remote-server/src/main/java/org/apache/geronimo/gshell/remote/server/handler/OpenShellHandler.java
    geronimo/gshell/trunk/gshell-remote/gshell-remote-server/src/main/java/org/apache/geronimo/gshell/remote/server/handler/ServerSessionContext.java
    geronimo/gshell/trunk/gshell-remote/gshell-remote-server/src/main/java/org/apache/geronimo/gshell/remote/server/timeout/TimeoutManagerImpl.java

Added: geronimo/gshell/trunk/gshell-remote/gshell-remote-server/src/main/java/org/apache/geronimo/gshell/remote/server/RemoteShellContextHolder.java
URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-remote/gshell-remote-server/src/main/java/org/apache/geronimo/gshell/remote/server/RemoteShellContextHolder.java?rev=697721&view=auto
==============================================================================
--- geronimo/gshell/trunk/gshell-remote/gshell-remote-server/src/main/java/org/apache/geronimo/gshell/remote/server/RemoteShellContextHolder.java
(added)
+++ geronimo/gshell/trunk/gshell-remote/gshell-remote-server/src/main/java/org/apache/geronimo/gshell/remote/server/RemoteShellContextHolder.java
Mon Sep 22 02:13:56 2008
@@ -0,0 +1,46 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.geronimo.gshell.remote.server;
+
+import org.apache.geronimo.gshell.shell.ShellContext;
+
+/**
+ * Remote {@link ShellContext} holder.
+ *
+ * @version $Rev$ $Date$
+ */
+public class RemoteShellContextHolder
+{
+    private static final InheritableThreadLocal<ShellContext> holder = new InheritableThreadLocal<ShellContext>();
+
+    public static void clearContext() {
+        holder.set(null);
+    }
+
+    public static void setContext(final ShellContext context) {
+        assert context != null;
+
+        holder.set(context);
+    }
+
+    public static ShellContext getContext() {
+        return holder.get();
+    }
+}

Propchange: geronimo/gshell/trunk/gshell-remote/gshell-remote-server/src/main/java/org/apache/geronimo/gshell/remote/server/RemoteShellContextHolder.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/gshell/trunk/gshell-remote/gshell-remote-server/src/main/java/org/apache/geronimo/gshell/remote/server/RemoteShellContextHolder.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: geronimo/gshell/trunk/gshell-remote/gshell-remote-server/src/main/java/org/apache/geronimo/gshell/remote/server/RemoteShellContextHolder.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: geronimo/gshell/trunk/gshell-remote/gshell-remote-server/src/main/java/org/apache/geronimo/gshell/remote/server/RemoteShellImpl.java
URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-remote/gshell-remote-server/src/main/java/org/apache/geronimo/gshell/remote/server/RemoteShellImpl.java?rev=697721&r1=697720&r2=697721&view=diff
==============================================================================
--- geronimo/gshell/trunk/gshell-remote/gshell-remote-server/src/main/java/org/apache/geronimo/gshell/remote/server/RemoteShellImpl.java
(original)
+++ geronimo/gshell/trunk/gshell-remote/gshell-remote-server/src/main/java/org/apache/geronimo/gshell/remote/server/RemoteShellImpl.java
Mon Sep 22 02:13:56 2008
@@ -43,8 +43,6 @@
     @Autowired
     private CommandLineExecutor executor;
 
-    private ShellContext context;
-
     private boolean opened = true;
 
     public RemoteShellImpl() {}
@@ -68,19 +66,15 @@
     public ShellContext getContext() {
         ensureOpened();
 
+        ShellContext context = RemoteShellContextHolder.getContext();
+
         if (context == null) {
             throw new IllegalStateException("Shell context has not been initialized");
         }
-        return context;
-    }
 
-    // HACK: Allow context to be forced into the shell
-    public void setContext(final ShellContext context) {
-        assert context != null;
-
-        this.context = context;
+        return context;
     }
-
+    
     public ShellInfo getInfo() {
         ensureOpened();
 

Modified: geronimo/gshell/trunk/gshell-remote/gshell-remote-server/src/main/java/org/apache/geronimo/gshell/remote/server/RshServer.java
URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-remote/gshell-remote-server/src/main/java/org/apache/geronimo/gshell/remote/server/RshServer.java?rev=697721&r1=697720&r2=697721&view=diff
==============================================================================
--- geronimo/gshell/trunk/gshell-remote/gshell-remote-server/src/main/java/org/apache/geronimo/gshell/remote/server/RshServer.java
(original)
+++ geronimo/gshell/trunk/gshell-remote/gshell-remote-server/src/main/java/org/apache/geronimo/gshell/remote/server/RshServer.java
Mon Sep 22 02:13:56 2008
@@ -19,10 +19,6 @@
 
 package org.apache.geronimo.gshell.remote.server;
 
-import java.net.URI;
-import java.util.List;
-import java.util.concurrent.TimeUnit;
-
 import org.apache.geronimo.gshell.chronos.Duration;
 import org.apache.geronimo.gshell.remote.server.handler.ServerMessageHandler;
 import org.apache.geronimo.gshell.remote.server.handler.ServerSessionContext;
@@ -38,6 +34,10 @@
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
 
+import java.net.URI;
+import java.util.List;
+import java.util.concurrent.TimeUnit;
+
 /**
  * Provides support for the server-side of the remote shell protocol.
  *

Modified: geronimo/gshell/trunk/gshell-remote/gshell-remote-server/src/main/java/org/apache/geronimo/gshell/remote/server/RshServerCommand.java
URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-remote/gshell-remote-server/src/main/java/org/apache/geronimo/gshell/remote/server/RshServerCommand.java?rev=697721&r1=697720&r2=697721&view=diff
==============================================================================
--- geronimo/gshell/trunk/gshell-remote/gshell-remote-server/src/main/java/org/apache/geronimo/gshell/remote/server/RshServerCommand.java
(original)
+++ geronimo/gshell/trunk/gshell-remote/gshell-remote-server/src/main/java/org/apache/geronimo/gshell/remote/server/RshServerCommand.java
Mon Sep 22 02:13:56 2008
@@ -24,8 +24,8 @@
 import org.apache.geronimo.gshell.command.CommandAction;
 import org.apache.geronimo.gshell.command.CommandContext;
 import org.apache.geronimo.gshell.io.IO;
-import org.apache.geronimo.gshell.spring.BeanContainerAware;
 import org.apache.geronimo.gshell.spring.BeanContainer;
+import org.apache.geronimo.gshell.spring.BeanContainerAware;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -59,6 +59,9 @@
         assert context != null;
 
         RshServer server = container.getBean(RshServer.class);
+
+        log.debug("Created server: {}", server);
+
         server.bind(location);
 
         IO io = context.getIo();
@@ -67,6 +70,8 @@
 
         if (!background) {
             synchronized (this) {
+                log.debug("Waiting for server to shutdown");
+                
                 wait();
             }
 

Modified: geronimo/gshell/trunk/gshell-remote/gshell-remote-server/src/main/java/org/apache/geronimo/gshell/remote/server/auth/BogusLoginModule.java
URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-remote/gshell-remote-server/src/main/java/org/apache/geronimo/gshell/remote/server/auth/BogusLoginModule.java?rev=697721&r1=697720&r2=697721&view=diff
==============================================================================
--- geronimo/gshell/trunk/gshell-remote/gshell-remote-server/src/main/java/org/apache/geronimo/gshell/remote/server/auth/BogusLoginModule.java
(original)
+++ geronimo/gshell/trunk/gshell-remote/gshell-remote-server/src/main/java/org/apache/geronimo/gshell/remote/server/auth/BogusLoginModule.java
Mon Sep 22 02:13:56 2008
@@ -57,8 +57,13 @@
     private String username;
 
     public void initialize(final Subject subject, final CallbackHandler callbackHandler,
final Map<String, ?> sharedState, final Map<String, ?> options) {
+        assert subject != null;
+        assert callbackHandler != null;
+
         this.subject = subject;
         this.callbackHandler = callbackHandler;
+        // ignoring sharedState
+        // ignoring options
     }
 
     private void reset() {

Modified: geronimo/gshell/trunk/gshell-remote/gshell-remote-server/src/main/java/org/apache/geronimo/gshell/remote/server/handler/CloseShellHandler.java
URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-remote/gshell-remote-server/src/main/java/org/apache/geronimo/gshell/remote/server/handler/CloseShellHandler.java?rev=697721&r1=697720&r2=697721&view=diff
==============================================================================
--- geronimo/gshell/trunk/gshell-remote/gshell-remote-server/src/main/java/org/apache/geronimo/gshell/remote/server/handler/CloseShellHandler.java
(original)
+++ geronimo/gshell/trunk/gshell-remote/gshell-remote-server/src/main/java/org/apache/geronimo/gshell/remote/server/handler/CloseShellHandler.java
Mon Sep 22 02:13:56 2008
@@ -19,7 +19,11 @@
 
 package org.apache.geronimo.gshell.remote.server.handler;
 
+import org.apache.geronimo.gshell.command.Variables;
+import org.apache.geronimo.gshell.io.IO;
 import org.apache.geronimo.gshell.remote.message.CloseShellMessage;
+import org.apache.geronimo.gshell.remote.server.RemoteShellContextHolder;
+import org.apache.geronimo.gshell.shell.ShellContext;
 import org.apache.geronimo.gshell.whisper.transport.Session;
 
 /**
@@ -39,7 +43,24 @@
         assert context != null;
         assert message != null;
 
-        context.close();
+        ShellContext shellContext = new ShellContext() {
+            public IO getIo() {
+                return context.io;
+            }
+
+            public Variables getVariables() {
+                return context.variables;
+            }
+        };
+
+        RemoteShellContextHolder.setContext(shellContext);
+
+        try {
+            context.close();
+        }
+        finally {
+            RemoteShellContextHolder.clearContext();
+        }
 
         CloseShellMessage.Result reply = new CloseShellMessage.Result();
         reply.setCorrelationId(message.getId());

Modified: geronimo/gshell/trunk/gshell-remote/gshell-remote-server/src/main/java/org/apache/geronimo/gshell/remote/server/handler/ExecuteHandler.java
URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-remote/gshell-remote-server/src/main/java/org/apache/geronimo/gshell/remote/server/handler/ExecuteHandler.java?rev=697721&r1=697720&r2=697721&view=diff
==============================================================================
--- geronimo/gshell/trunk/gshell-remote/gshell-remote-server/src/main/java/org/apache/geronimo/gshell/remote/server/handler/ExecuteHandler.java
(original)
+++ geronimo/gshell/trunk/gshell-remote/gshell-remote-server/src/main/java/org/apache/geronimo/gshell/remote/server/handler/ExecuteHandler.java
Mon Sep 22 02:13:56 2008
@@ -19,8 +19,12 @@
 
 package org.apache.geronimo.gshell.remote.server.handler;
 
+import org.apache.geronimo.gshell.command.Variables;
+import org.apache.geronimo.gshell.io.IO;
 import org.apache.geronimo.gshell.notification.Notification;
 import org.apache.geronimo.gshell.remote.message.ExecuteMessage;
+import org.apache.geronimo.gshell.remote.server.RemoteShellContextHolder;
+import org.apache.geronimo.gshell.shell.ShellContext;
 import org.apache.geronimo.gshell.whisper.transport.Session;
 
 /**
@@ -40,24 +44,41 @@
         assert context != null;
         assert message != null;
 
+        ShellContext shellContext = new ShellContext() {
+            public IO getIo() {
+                return context.io;
+            }
+
+            public Variables getVariables() {
+                return context.variables;
+            }
+        };
+
         ExecuteMessage.Result reply;
+        
+        RemoteShellContextHolder.setContext(shellContext);
 
         try {
-            Object result = message.execute(context.shell);
+            try {
+                Object result = message.execute(context.shell);
 
-            log.debug("Result: {}", result);
+                log.debug("Result: {}", result);
 
-            reply = new ExecuteMessage.Result(result);
-        }
-        catch (Notification n) {
-            log.debug("Notification: " + n);
+                reply = new ExecuteMessage.Result(result);
+            }
+            catch (Notification n) {
+                log.debug("Notification: " + n);
+
+                reply = new ExecuteMessage.NotificationResult(n);
+            }
+            catch (Throwable t) {
+                log.debug("Failure: " + t);
 
-            reply = new ExecuteMessage.NotificationResult(n);
+                reply = new ExecuteMessage.FailureResult(t);
+            }
         }
-        catch (Throwable t) {
-            log.debug("Failure: " + t);
-
-            reply = new ExecuteMessage.FailureResult(t);
+        finally {
+            RemoteShellContextHolder.clearContext();
         }
 
         reply.setCorrelationId(message.getId());

Modified: geronimo/gshell/trunk/gshell-remote/gshell-remote-server/src/main/java/org/apache/geronimo/gshell/remote/server/handler/OpenShellHandler.java
URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-remote/gshell-remote-server/src/main/java/org/apache/geronimo/gshell/remote/server/handler/OpenShellHandler.java?rev=697721&r1=697720&r2=697721&view=diff
==============================================================================
--- geronimo/gshell/trunk/gshell-remote/gshell-remote-server/src/main/java/org/apache/geronimo/gshell/remote/server/handler/OpenShellHandler.java
(original)
+++ geronimo/gshell/trunk/gshell-remote/gshell-remote-server/src/main/java/org/apache/geronimo/gshell/remote/server/handler/OpenShellHandler.java
Mon Sep 22 02:13:56 2008
@@ -19,16 +19,16 @@
 
 package org.apache.geronimo.gshell.remote.server.handler;
 
+import org.apache.geronimo.gshell.command.Variables;
+import org.apache.geronimo.gshell.io.IO;
 import org.apache.geronimo.gshell.remote.RemoteShell;
 import org.apache.geronimo.gshell.remote.message.OpenShellMessage;
 import org.apache.geronimo.gshell.remote.server.RemoteIO;
-import org.apache.geronimo.gshell.remote.server.RemoteShellImpl;
+import org.apache.geronimo.gshell.remote.server.RemoteShellContextHolder;
+import org.apache.geronimo.gshell.shell.ShellContext;
 import org.apache.geronimo.gshell.spring.BeanContainer;
 import org.apache.geronimo.gshell.spring.BeanContainerAware;
 import org.apache.geronimo.gshell.whisper.transport.Session;
-import org.apache.geronimo.gshell.shell.ShellContext;
-import org.apache.geronimo.gshell.io.IO;
-import org.apache.geronimo.gshell.command.Variables;
 
 import java.util.UUID;
 
@@ -61,16 +61,11 @@
         context.container = container.createChild(id);
         context.container.start();
 
-        // Setup the I/O context (w/o auto-flushing)
+        // Setup the shell context and related components
         context.io = new RemoteIO(session);
-
         context.variables = new Variables();
 
-        // Create a new shell instance
-        context.shell = context.container.getBean("remoteShell", RemoteShell.class);
-
-        // HACK: Need to force the context into the shell
-        ((RemoteShellImpl)context.shell).setContext(new ShellContext() {
+        ShellContext shellContext = new ShellContext() {
             public IO getIo() {
                 return context.io;
             }
@@ -78,7 +73,17 @@
             public Variables getVariables() {
                 return context.variables;
             }
-        });
+        };
+
+        RemoteShellContextHolder.setContext(shellContext);
+
+        try {
+            // Create a new shell instance
+            context.shell = context.container.getBean("remoteShell", RemoteShell.class);
+        }
+        finally {
+            RemoteShellContextHolder.clearContext();
+        }
 
         OpenShellMessage.Result reply = new OpenShellMessage.Result();
         reply.setCorrelationId(message.getId());

Modified: geronimo/gshell/trunk/gshell-remote/gshell-remote-server/src/main/java/org/apache/geronimo/gshell/remote/server/handler/ServerSessionContext.java
URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-remote/gshell-remote-server/src/main/java/org/apache/geronimo/gshell/remote/server/handler/ServerSessionContext.java?rev=697721&r1=697720&r2=697721&view=diff
==============================================================================
--- geronimo/gshell/trunk/gshell-remote/gshell-remote-server/src/main/java/org/apache/geronimo/gshell/remote/server/handler/ServerSessionContext.java
(original)
+++ geronimo/gshell/trunk/gshell-remote/gshell-remote-server/src/main/java/org/apache/geronimo/gshell/remote/server/handler/ServerSessionContext.java
Mon Sep 22 02:13:56 2008
@@ -19,17 +19,16 @@
 
 package org.apache.geronimo.gshell.remote.server.handler;
 
-import java.security.PublicKey;
-
-import javax.security.auth.Subject;
-
+import org.apache.geronimo.gshell.command.Variables;
 import org.apache.geronimo.gshell.remote.RemoteShell;
 import org.apache.geronimo.gshell.remote.jaas.Identity;
 import org.apache.geronimo.gshell.remote.jaas.UserPrincipal;
 import org.apache.geronimo.gshell.remote.server.RemoteIO;
-import org.apache.geronimo.gshell.whisper.util.SessionAttributeBinder;
 import org.apache.geronimo.gshell.spring.BeanContainer;
-import org.apache.geronimo.gshell.command.Variables;
+import org.apache.geronimo.gshell.whisper.util.SessionAttributeBinder;
+
+import javax.security.auth.Subject;
+import java.security.PublicKey;
 
 /**
  * Container for server-side session state.

Modified: geronimo/gshell/trunk/gshell-remote/gshell-remote-server/src/main/java/org/apache/geronimo/gshell/remote/server/timeout/TimeoutManagerImpl.java
URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-remote/gshell-remote-server/src/main/java/org/apache/geronimo/gshell/remote/server/timeout/TimeoutManagerImpl.java?rev=697721&r1=697720&r2=697721&view=diff
==============================================================================
--- geronimo/gshell/trunk/gshell-remote/gshell-remote-server/src/main/java/org/apache/geronimo/gshell/remote/server/timeout/TimeoutManagerImpl.java
(original)
+++ geronimo/gshell/trunk/gshell-remote/gshell-remote-server/src/main/java/org/apache/geronimo/gshell/remote/server/timeout/TimeoutManagerImpl.java
Mon Sep 22 02:13:56 2008
@@ -57,6 +57,8 @@
         assert timeout != null;
         assert task != null;
 
+        log.debug("Scheduling timeout; session: {}, duration: {}", session, timeout);
+
         ScheduledFuture tf = scheduler.schedule(task, timeout.value, timeout.unit);
 
         TIMEOUT.rebind(session.getSession(), tf);
@@ -67,6 +69,8 @@
     public boolean cancelTimeout(final Session session) {
         assert session != null;
 
+        log.debug("Canceling timeout; session: {}", session);
+
         ScheduledFuture tf = TIMEOUT.lookup(session.getSession());
 
         return tf.cancel(false);



Mime
View raw message