You are viewing a plain text version of this content. The canonical link for it is here.
Posted to scm@geronimo.apache.org by jd...@apache.org on 2007/09/22 21:35:43 UTC

svn commit: r578480 - in /geronimo/sandbox/gshell/trunk: gshell-assembly/src/main/underlay/etc/ gshell-remote/gshell-remote-client/src/main/java/org/apache/geronimo/gshell/remote/client/ gshell-remote/gshell-remote-common/src/main/java/org/apache/geron...

Author: jdillon
Date: Sat Sep 22 12:35:42 2007
New Revision: 578480

URL: http://svn.apache.org/viewvc?rev=578480&view=rev
Log:
Rewrote the request manager to simplify it a bit and make sure that we don't blow up on cases where responses get consumed faster than we can process the request sends (which seems to happen often)
Trim down some logging so I don't go so mad looking at a ton of junk while I'm pulling my hair out wondering wtf is going on
Reverted the plexus child container bits, that doesn't work at all... spent like 2 hours... close to punching computer to figure that out... ahhh I miss spring... :-(
Set the id and sequence to generate on first getter access to prevent gaps and wasted cpu building these things when deserializing

Added:
    geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/request/RequestManager.java
    geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/request/RequestResponseFilter.java
    geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/session/ThreadPoolModel.java   (contents, props changed)
      - copied, changed from r578448, geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/session/ExecutorThreadModel.java
    geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/util/TimeValue.java   (with props)
Removed:
    geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/request/DuplicateRequestException.java
    geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/request/InvalidRequestMappingException.java
    geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/request/MissingRequestTimeoutException.java
    geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/session/ExecutorThreadModel.java
Modified:
    geronimo/sandbox/gshell/trunk/gshell-assembly/src/main/underlay/etc/gsh-log4j.properties
    geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-client/src/main/java/org/apache/geronimo/gshell/remote/client/RshClient.java
    geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-client/src/main/java/org/apache/geronimo/gshell/remote/client/RshCommand.java
    geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/MessageHandler.java
    geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/MessageSupport.java
    geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/rsh/HandShakeMessage.java
    geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/request/Request.java
    geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/request/RequestException.java
    geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/request/Requestor.java
    geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/request/Response.java
    geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/security/SecurityFilter.java
    geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/transport/base/BaseCommon.java
    geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/transport/base/BaseTransport.java
    geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/transport/base/BaseTransportServer.java
    geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/util/NamedThreadFactory.java
    geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-server/src/main/java/org/apache/geronimo/gshell/remote/server/DefaultRemoteShell.java
    geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-server/src/main/java/org/apache/geronimo/gshell/remote/server/RshServerMessageVisitor.java

Modified: geronimo/sandbox/gshell/trunk/gshell-assembly/src/main/underlay/etc/gsh-log4j.properties
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-assembly/src/main/underlay/etc/gsh-log4j.properties?rev=578480&r1=578479&r2=578480&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-assembly/src/main/underlay/etc/gsh-log4j.properties (original)
+++ geronimo/sandbox/gshell/trunk/gshell-assembly/src/main/underlay/etc/gsh-log4j.properties Sat Sep 22 12:35:42 2007
@@ -36,3 +36,10 @@
 log4j.appender.FILE.Threshold=DEBUG
 log4j.appender.FILE.layout=org.apache.log4j.PatternLayout
 log4j.appender.FILE.layout.ConversionPattern=%d{ABSOLUTE} %-5p (%t) [%c] %m%n
+
+log4j.logger.org.apache.geronimo.gshell.plugin=INFO
+log4j.logger.org.apache.geronimo.gshell.console=INFO
+log4j.logger.org.apache.geronimo.gshell.remote.util.NamedThreadFactory=INFO
+log4j.logger.org.apache.geronimo.gshell.remote.session.ThreadPoolModel=INFO
+log4j.logger.org.codehaus.plexus.PlexusContainer=INFO
+log4j.logger.org.apache.mina.filter.executor.ExecutorFilter=INFO
\ No newline at end of file

Modified: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-client/src/main/java/org/apache/geronimo/gshell/remote/client/RshClient.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-client/src/main/java/org/apache/geronimo/gshell/remote/client/RshClient.java?rev=578480&r1=578479&r2=578480&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-client/src/main/java/org/apache/geronimo/gshell/remote/client/RshClient.java (original)
+++ geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-client/src/main/java/org/apache/geronimo/gshell/remote/client/RshClient.java Sat Sep 22 12:35:42 2007
@@ -68,6 +68,22 @@
         log.debug("Connected to: {}", remote);
     }
 
+    public InputStream getInputStream() {
+        return transport.getInputStream();
+    }
+
+    public OutputStream getOutputStream() {
+        return transport.getOutputStream();
+    }
+
+    public Transport getTransport() {
+        return transport;
+    }
+
+    public void close() {
+        transport.close();
+    }
+
     public void login(final String username, final String password) throws Exception {
         assert username != null;
         assert password != null;
@@ -158,17 +174,5 @@
         assert args != null;
 
         return doExecute(new ExecuteMessage(path, args));
-    }
-
-    public InputStream getInputStream() {
-        return transport.getInputStream();
-    }
-
-    public OutputStream getOutputStream() {
-        return transport.getOutputStream();
-    }
-
-    public void close() {
-        transport.close();
     }
 }

Modified: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-client/src/main/java/org/apache/geronimo/gshell/remote/client/RshCommand.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-client/src/main/java/org/apache/geronimo/gshell/remote/client/RshCommand.java?rev=578480&r1=578479&r2=578480&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-client/src/main/java/org/apache/geronimo/gshell/remote/client/RshCommand.java (original)
+++ geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-client/src/main/java/org/apache/geronimo/gshell/remote/client/RshCommand.java Sat Sep 22 12:35:42 2007
@@ -29,6 +29,8 @@
 import org.apache.geronimo.gshell.clp.Option;
 import org.apache.geronimo.gshell.command.CommandSupport;
 import org.apache.geronimo.gshell.command.annotation.CommandComponent;
+import org.apache.geronimo.gshell.remote.message.Message;
+import org.apache.geronimo.gshell.remote.message.rsh.EchoMessage;
 import org.codehaus.plexus.component.annotations.Requirement;
 
 /**
@@ -67,7 +69,9 @@
         client.login("jason", "password");
 
         // client.echo("NOISE MAKER");
-        
+
+        // client.getTransport().request(new EchoMessage("NO REPLY"));
+
         RemoteShellProxy shell = new RemoteShellProxy(client, io, terminal);
 
         Object rv = SUCCESS;

Modified: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/MessageHandler.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/MessageHandler.java?rev=578480&r1=578479&r2=578480&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/MessageHandler.java (original)
+++ geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/MessageHandler.java Sat Sep 22 12:35:42 2007
@@ -80,10 +80,6 @@
         if (obj instanceof Message) {
             Message msg = (Message)obj;
 
-            //
-            // TODO: Change the visit* methods to take a session and a visitor to avoid needing to attach to the message
-            //
-            
             // Attach the session to the context
             msg.setSession(session);
             msg.freeze();

Modified: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/MessageSupport.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/MessageSupport.java?rev=578480&r1=578479&r2=578480&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/MessageSupport.java (original)
+++ geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/MessageSupport.java Sat Sep 22 12:35:42 2007
@@ -37,7 +37,7 @@
 public class MessageSupport
     implements Message
 {
-    private static final IDGenerator ID_GENERATOR = new UuidMessageID.Generator(); // new LongMessageID.Generator();
+    private static final IDGenerator ID_GENERATOR = /*new UuidMessageID.Generator();*/ new LongMessageID.Generator();
 
     private static final AtomicLong SEQUENCE_COUNTER = new AtomicLong(0);
 
@@ -60,11 +60,19 @@
         
         this.type = type;
 
-        this.id = ID_GENERATOR.generate();
-        
         this.timestamp = System.currentTimeMillis();
+
+        // late init id and sequence
     }
 
+    public int hashCode() {
+        return getId().hashCode();
+    }
+    
+    //
+    // TODO: Add equals()
+    //
+    
     public String toString() {
         return ReflectionToStringBuilder.toString(this, ToStringStyle.SHORT_PREFIX_STYLE);
     }
@@ -74,6 +82,10 @@
     }
 
     public ID getId() {
+        if (id == null) {
+            id = ID_GENERATOR.generate();
+        }
+
         return id;
     }
     
@@ -95,7 +107,7 @@
 
     public long getSequence() {
         if (sequence == null) {
-            throw new IllegalStateException("Sequence number is set upon write and is not yet available");
+            sequence = SEQUENCE_COUNTER.getAndIncrement();
         }
 
         return sequence;
@@ -159,14 +171,12 @@
     public void writeExternal(final ByteBuffer out) throws Exception {
         assert out != null;
 
-        Marshaller.marshal(out, id);
+        Marshaller.marshal(out, getId());
 
-        Marshaller.marshal(out, cid);
+        Marshaller.marshal(out, getCorrelationId());
 
-        out.putLong(timestamp);
+        out.putLong(getTimestamp());
 
-        sequence = SEQUENCE_COUNTER.getAndIncrement();
-        
-        out.putLong(sequence);
+        out.putLong(getSequence());
     }
 }

Modified: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/rsh/HandShakeMessage.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/rsh/HandShakeMessage.java?rev=578480&r1=578479&r2=578480&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/rsh/HandShakeMessage.java (original)
+++ geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/rsh/HandShakeMessage.java Sat Sep 22 12:35:42 2007
@@ -24,6 +24,8 @@
 import org.apache.geronimo.gshell.remote.marshall.Marshaller;
 import org.apache.geronimo.gshell.remote.message.CryptoAwareMessageSupport;
 import org.apache.geronimo.gshell.remote.message.MessageType;
+import org.apache.geronimo.gshell.common.tostring.ToStringBuilder;
+import org.apache.geronimo.gshell.common.tostring.ToStringStyle;
 import org.apache.mina.common.ByteBuffer;
 
 //

Modified: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/request/Request.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/request/Request.java?rev=578480&r1=578479&r2=578480&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/request/Request.java (original)
+++ geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/request/Request.java Sat Sep 22 12:35:42 2007
@@ -29,7 +29,7 @@
 import java.util.concurrent.locks.Lock;
 import java.util.concurrent.locks.ReentrantLock;
 
-import org.apache.geronimo.gshell.common.tostring.ReflectionToStringBuilder;
+import org.apache.geronimo.gshell.common.tostring.ToStringBuilder;
 import org.apache.geronimo.gshell.common.tostring.ToStringStyle;
 import org.apache.geronimo.gshell.remote.message.Message;
 import org.slf4j.Logger;
@@ -42,7 +42,7 @@
  */
 public class Request
 {
-    private transient final Logger log = LoggerFactory.getLogger(getClass());
+    private final Logger log = LoggerFactory.getLogger(getClass());
 
     final Lock lock = new ReentrantLock();
 
@@ -85,7 +85,11 @@
     }
 
     public String toString() {
-        return ReflectionToStringBuilder.toString(this, ToStringStyle.SHORT_PREFIX_STYLE);
+        return new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE)
+                .append("id", getId())
+                .append("signaled", signaled)
+                .append("message", message)
+                .toString();
     }
 
     public Message getMessage() {

Modified: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/request/RequestException.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/request/RequestException.java?rev=578480&r1=578479&r2=578480&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/request/RequestException.java (original)
+++ geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/request/RequestException.java Sat Sep 22 12:35:42 2007
@@ -19,10 +19,12 @@
 
 package org.apache.geronimo.gshell.remote.request;
 
+import org.apache.geronimo.gshell.remote.message.Message;
+
 /**
  * Thrown to indicate a request operation failed.
  *
- * @version $Rev$ $Date$
+ * @version $Rev: 577545 $ $Date: 2007-09-19 21:55:19 -0700 (Wed, 19 Sep 2007) $
  */
 public class RequestException
     extends RuntimeException
@@ -39,6 +41,10 @@
 
     public RequestException(final Throwable cause) {
         super(cause);
+    }
+
+    public RequestException(final Message.ID id) {
+        super(String.valueOf(id));
     }
 
     public RequestException() {

Added: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/request/RequestManager.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/request/RequestManager.java?rev=578480&view=auto
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/request/RequestManager.java (added)
+++ geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/request/RequestManager.java Sat Sep 22 12:35:42 2007
@@ -0,0 +1,334 @@
+/*
+ * 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.request;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.ScheduledFuture;
+import java.util.concurrent.ScheduledThreadPoolExecutor;
+import java.util.concurrent.ThreadFactory;
+import java.util.concurrent.locks.Lock;
+import java.util.concurrent.locks.ReentrantLock;
+
+import org.apache.geronimo.gshell.common.tostring.ToStringBuilder;
+import org.apache.geronimo.gshell.common.tostring.ToStringStyle;
+import org.apache.geronimo.gshell.remote.message.Message;
+import org.apache.geronimo.gshell.remote.session.SessionAttributeBinder;
+import org.apache.geronimo.gshell.remote.util.NamedThreadFactory;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * ???
+ *
+ * @version $Rev$ $Date$
+ */
+public class RequestManager
+{
+    public static final SessionAttributeBinder<RequestManager> BINDER = new SessionAttributeBinder<RequestManager>(RequestManager.class);
+
+    private final Logger log = LoggerFactory.getLogger(getClass());
+
+    private final Map<Message.ID,Registration> registrations = new HashMap<Message.ID, Registration>();
+
+    private final ScheduledExecutorService scheduler;
+
+    //
+    // TODO: Use a better locking scheme...
+    //
+    
+    private final Lock lock = new ReentrantLock();
+
+    public RequestManager() {
+        ThreadFactory tf = new NamedThreadFactory(getClass());
+        
+        scheduler = new ScheduledThreadPoolExecutor(Runtime.getRuntime().availableProcessors() + 1, tf);
+    }
+
+    private Registration get(final Message.ID id) {
+        assert id != null;
+
+        Registration reg = registrations.get(id);
+
+        if (reg == null) {
+            throw new NotRegisteredException(id);
+        }
+
+        return reg;
+    }
+
+    private Registration remove(final Message.ID id) {
+        assert id != null;
+
+        Registration reg = registrations.remove(id);
+
+        if (reg == null) {
+            throw new NotRegisteredException(id);
+        }
+
+        return reg;
+    }
+
+    public void register(final Request request) {
+        assert request != null;
+
+        lock.lock();
+
+        try {
+            Message.ID id = request.getId();
+
+            if (registrations.containsKey(id)) {
+                throw new DuplicateRegistrationException(id);
+            }
+
+            Registration reg = new Registration(request);
+
+            registrations.put(id, reg);
+
+            log.debug("Registered: {}", reg);
+        }
+        finally {
+            lock.unlock();
+        }
+    }
+
+    public Request lookup(final Message.ID id) {
+        assert id != null;
+
+        lock.lock();
+
+        try {
+            Registration reg = get(id);
+
+            return reg.request;
+        }
+        finally {
+            lock.unlock();
+        }
+    }
+
+    public Request deregister(final Message.ID id) {
+        assert id != null;
+
+        lock.lock();
+
+        try {
+            Registration reg = remove(id);
+
+            reg.deactivate();
+
+            log.debug("Deregistered: {}", reg);
+
+            return reg.request;
+        }
+        finally {
+            lock.unlock();
+        }
+    }
+
+    public void activate(final Message.ID id) {
+        assert id != null;
+
+        lock.lock();
+
+        try {
+            Registration reg = get(id);
+            
+            reg.activate();
+
+            log.debug("Activated: {}", reg);
+        }
+        catch (NotRegisteredException e) {
+            log.debug("Ignoring activation; request not registered: {}", id);
+        }
+        finally {
+            lock.unlock();
+        }
+    }
+
+    public void deactivate(final Message.ID id) {
+        assert id != null;
+
+        lock.lock();
+
+        try {
+            Registration reg = get(id);
+
+            reg.deactivate();
+
+            log.debug("Deactivated: {}", reg);
+        }
+        catch (NotRegisteredException e) {
+            log.debug("Ignoring deactivation; request not registered: {}", id);
+        }
+        finally {
+            lock.unlock();
+        }
+    }
+
+    private void timeout(final Message.ID id) {
+        assert id != null;
+
+        lock.lock();
+
+        try {
+            Registration reg = remove(id);
+
+            reg.timeout();
+
+            log.debug("Timed out: {}", reg);
+        }
+        catch (NotRegisteredException e) {
+            log.debug("Ignoring timeout; request not registered: {}", id);
+        }
+        catch (TimeoutAbortedException e) {
+            log.debug("Timeout aborted: " + e.getMessage());
+        }
+        finally {
+            lock.unlock();
+        }
+    }
+
+    public void close() {
+        lock.lock();
+
+        try {
+            if (!registrations.isEmpty()) {
+                log.warn("Timing out remaining {} registrations", registrations.size());
+
+                for (Registration reg : registrations.values()) {
+                    timeout(reg.request.getId());
+                }
+            }
+
+            //
+            // FIXME: This causes some problems when a rsh client closes, like:
+            //
+            //        java.security.AccessControlException: access denied (java.lang.RuntimePermission modifyThread)
+            //
+            // scheduler.shutdown();
+        }
+        finally {
+            lock.unlock();
+        }
+    }
+
+    private enum RegistrationState
+    {
+        PENDING,
+        ACTIVE,
+        DEACTIVE,
+        TIMEDOUT
+    }
+
+    private class Registration
+    {
+        public final Request request;
+
+        public RegistrationState state = RegistrationState.PENDING;
+
+        private ScheduledFuture<?> timeoutFuture;
+
+        public Registration(final Request request) {
+            assert request != null;
+
+            this.request = request;
+        }
+
+        public void activate() {
+            if (state != RegistrationState.PENDING) {
+                log.debug("Can not activate, state is not PENDING, found: {}", state);
+            }
+            else {
+                Runnable task = new Runnable() {
+                    public void run() {
+                        RequestManager.this.timeout(request.getId());
+                    }
+                };
+
+                timeoutFuture = scheduler.schedule(task, request.getTimeout(), request.getTimeoutUnit());
+
+                state = RegistrationState.ACTIVE;
+            }
+        }
+
+        public void deactivate() {
+            if (state != RegistrationState.ACTIVE) {
+                log.debug("Can not deactivate; state is not ACTIVE, found: {}", state);
+            }
+            else if (timeoutFuture.cancel(false)) {
+                timeoutFuture = null;
+
+                state = RegistrationState.DEACTIVE;
+            }
+            else {
+                log.warn("Unable to cancel registration timeout: {}", this);
+            }
+        }
+
+        public void timeout() {
+            Message.ID id = request.getId();
+
+            if (timeoutFuture.isCancelled()) {
+                throw new TimeoutAbortedException("Timeout has been canceled: " + id);
+            }
+            else if (request.isSignaled()) {
+                throw new TimeoutAbortedException("Request has been singled: " + id);
+            }
+            else {
+                request.timeout();
+
+                state = RegistrationState.TIMEDOUT;
+            }
+        }
+
+        public String toString() {
+            return new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE)
+                    .append("id", request.getId())
+                    .append("state", state)
+                    .toString();
+        }
+    }
+
+    public class NotRegisteredException
+        extends RequestException
+    {
+        public NotRegisteredException(final Message.ID id) {
+            super(id);
+        }
+    }
+
+    public class DuplicateRegistrationException
+        extends RequestException
+    {
+        public DuplicateRegistrationException(final Message.ID id) {
+            super(id);
+        }
+    }
+
+    public class TimeoutAbortedException
+        extends RequestException
+    {
+        public TimeoutAbortedException(final String msg) {
+            super(msg);
+        }
+    }
+}
\ No newline at end of file

Added: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/request/RequestResponseFilter.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/request/RequestResponseFilter.java?rev=578480&view=auto
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/request/RequestResponseFilter.java (added)
+++ geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/request/RequestResponseFilter.java Sat Sep 22 12:35:42 2007
@@ -0,0 +1,127 @@
+/*
+ * 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.request;
+
+import org.apache.geronimo.gshell.remote.message.Message;
+import org.apache.mina.common.IoFilterAdapter;
+import org.apache.mina.common.IoSession;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Provides synchronous request/response messaging.
+ *
+ * @version $Rev$ $Date$
+ */
+public class RequestResponseFilter
+    extends IoFilterAdapter
+{
+    private final Logger log = LoggerFactory.getLogger(getClass());
+
+    /**
+     * Set up the request manager instance for the session.
+     */
+    @Override
+    public void sessionCreated(final NextFilter nextFilter, final IoSession session) throws Exception {
+        RequestManager.BINDER.bind(session, new RequestManager());
+
+        nextFilter.sessionCreated(session);
+    }
+
+    /**
+     * Close the request manager instance for the session.
+     */
+    @Override
+    public void sessionClosed(final NextFilter nextFilter, final IoSession session) throws Exception {
+        RequestManager manager = RequestManager.BINDER.unbind(session);
+        
+        manager.close();
+
+        nextFilter.sessionClosed(session);
+    }
+
+    /**
+     * When a request is sent, register it with the request manager.
+     */
+    @Override
+    public void filterWrite(final NextFilter nextFilter, final IoSession session, final WriteRequest writeRequest) throws Exception {
+        Object message = writeRequest.getMessage();
+
+        if (message instanceof Request) {
+            Request request = (Request) message;
+
+            RequestManager manager = RequestManager.BINDER.lookup(session);
+
+            manager.register(request);
+        }
+
+        nextFilter.filterWrite(session, writeRequest);
+    }
+
+    /**
+     * When a response message has been received, deregister it and signal the response.
+     */
+    @Override
+    public void messageReceived(final NextFilter nextFilter, final IoSession session, final Object message) throws Exception {
+        Message msg = null;
+
+        Message.ID id = null;
+
+        if (message instanceof Message) {
+            msg = (Message)message;
+
+            id = msg.getCorrelationId();
+        }
+
+        // If we have a correlation id, then we can process the response
+        if (id != null) {
+            RequestManager manager = RequestManager.BINDER.lookup(session);
+
+            Request request = manager.deregister(id);
+
+            // Setup the response and signal the request
+            Response response = new Response(request, msg, Response.Type.WHOLE);
+
+            request.signal(response);
+
+            // Do not pass on the response
+        }
+        else {
+            nextFilter.messageReceived(session, message);
+        }
+    }
+
+    /**
+     * Once the reqeust message has been sent then activate it.  Some times a message gets consumed before we get a chance
+     * to activate it, which is okay, the {@link RequestManager} will simply ignore the request.
+     */
+    @Override
+    public void messageSent(final NextFilter nextFilter, final IoSession session, final Object message) throws Exception {
+        if (message instanceof Request) {
+            Request request = (Request) message;
+
+            RequestManager manager = RequestManager.BINDER.lookup(session);
+
+            manager.activate(request.getId());
+        }
+
+        nextFilter.messageSent(session, message);
+    }
+}
\ No newline at end of file

Modified: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/request/Requestor.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/request/Requestor.java?rev=578480&r1=578479&r2=578480&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/request/Requestor.java (original)
+++ geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/request/Requestor.java Sat Sep 22 12:35:42 2007
@@ -36,7 +36,7 @@
  */
 public class Requestor
 {
-    public static final long DEFAULT_TIMEOUT = 60;
+    public static final long DEFAULT_TIMEOUT = 10;
 
     public static final TimeUnit DEFAULT_TIMEOUT_UNIT = TimeUnit.SECONDS;
 

Modified: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/request/Response.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/request/Response.java?rev=578480&r1=578479&r2=578480&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/request/Response.java (original)
+++ geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/request/Response.java Sat Sep 22 12:35:42 2007
@@ -21,6 +21,7 @@
 
 import org.apache.geronimo.gshell.common.tostring.ReflectionToStringBuilder;
 import org.apache.geronimo.gshell.common.tostring.ToStringStyle;
+import org.apache.geronimo.gshell.common.tostring.ToStringBuilder;
 import org.apache.geronimo.gshell.remote.message.Message;
 
 //
@@ -67,7 +68,11 @@
     }
 
     public String toString() {
-        return ReflectionToStringBuilder.toString(this, ToStringStyle.SHORT_PREFIX_STYLE);
+        return new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE)
+                .append("id", getId())
+                .append("responseTo", getRequest().getId())
+                .append("message", message)
+                .toString();
     }
 
     public Request getRequest() {

Modified: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/security/SecurityFilter.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/security/SecurityFilter.java?rev=578480&r1=578479&r2=578480&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/security/SecurityFilter.java (original)
+++ geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/security/SecurityFilter.java Sat Sep 22 12:35:42 2007
@@ -66,7 +66,7 @@
     private final UUID securityToken;
 
     public SecurityFilter() throws Exception {
-        ThreadFactory tf = new NamedThreadFactory(SecurityFilter.class);
+        ThreadFactory tf = new NamedThreadFactory(getClass());
         
         scheduler = new ScheduledThreadPoolExecutor(Runtime.getRuntime().availableProcessors(), tf);
 
@@ -78,17 +78,6 @@
     }
 
     @Override
-    public void init() throws Exception {
-        // Install the schedule purger to purge any cancelled tasks to prevent memory leaks
-        scheduler.scheduleWithFixedDelay(new SchedulePurgerTask(), 10, 10, TimeUnit.SECONDS);
-    }
-
-    @Override
-    public void destroy() throws Exception {
-        scheduler.shutdownNow();
-    }
-
-    @Override
     public void sessionOpened(final NextFilter nextFilter, final IoSession session) throws Exception {
         assert nextFilter != null;
         assert session != null;
@@ -248,21 +237,6 @@
             log.error("Timeout waiting for handshake or authentication from: " + session.getRemoteAddress());
 
             session.close();
-        }
-    }
-
-    //
-    // SchedulePurgerTask
-    //
-
-    /**
-     * Task to remove cancelled tasks from the scheduler
-     */
-    private class SchedulePurgerTask
-        implements Runnable
-    {
-        public void run() {
-            scheduler.purge();
         }
     }
 }

Copied: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/session/ThreadPoolModel.java (from r578448, geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/session/ExecutorThreadModel.java)
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/session/ThreadPoolModel.java?p2=geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/session/ThreadPoolModel.java&p1=geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/session/ExecutorThreadModel.java&r1=578448&r2=578480&rev=578480&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/session/ExecutorThreadModel.java (original)
+++ geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/session/ThreadPoolModel.java Sat Sep 22 12:35:42 2007
@@ -40,25 +40,19 @@
  * @version $Rev$ $Date$
  */
 @SuppressWarnings({"FieldCanBeLocal"})
-public class ExecutorThreadModel
+public class ThreadPoolModel
     implements ThreadModel
 {
     private final Logger log = LoggerFactory.getLogger(getClass());
 
-    private final String name;
-
-    private final ThreadGroup group;
-
-    private final ExecutorService executor;
+    private final ThreadPoolExecutor threadPool;
 
     private final ExecutorFilter filter;
 
-    public ExecutorThreadModel(final String name) {
+    public ThreadPoolModel(final String name) {
         assert name != null;
 
-        this.name = name;
-
-        this.group = new ThreadGroup(name);
+        ThreadGroup group = new ThreadGroup(name);
 
         ThreadFactory tf = new NamedThreadFactory(name, group);
 
@@ -66,7 +60,7 @@
         // TODO: See which is better SynchronousQueue<Runnable> or LinkedBlockingQueue<Runnable>
         //
 
-        this.executor = new ThreadPoolExecutor(
+        threadPool = new ThreadPoolExecutor(
                 1,
                 Integer.MAX_VALUE,
                 60L,
@@ -75,7 +69,7 @@
                 tf,
                 new ThreadPoolExecutor.AbortPolicy());
 
-        this.filter = new ExecutorFilter(executor);
+        filter = new ExecutorFilter(threadPool);
     }
 
     public void close() {
@@ -86,7 +80,7 @@
         //
 
         /*
-        List<Runnable> pending = executor.shutdownNow();
+        List<Runnable> pending = threadPool.shutdownNow();
 
         if (!pending.isEmpty()) {
             log.warn("There were {} pending tasks which have not been run", pending.size());
@@ -100,7 +94,7 @@
 
     public void buildFilterChain(final IoFilterChain chain) throws Exception {
         assert chain != null;
-
+        
         chain.addFirst(getClass().getSimpleName(), filter);
     }
 }

Propchange: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/session/ThreadPoolModel.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/session/ThreadPoolModel.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/session/ThreadPoolModel.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/transport/base/BaseCommon.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/transport/base/BaseCommon.java?rev=578480&r1=578479&r2=578480&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/transport/base/BaseCommon.java (original)
+++ geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/transport/base/BaseCommon.java Sat Sep 22 12:35:42 2007
@@ -139,9 +139,6 @@
     protected void configure(final DefaultIoFilterChainBuilder chain) throws Exception {
         assert chain != null;
 
-        // We don't need an executor filter here (in Mina 1.1.x), since the ThreadModel does that for us
-        // chain.addLast(ExecutorFilter.class.getSimpleName(), new ExecutorFilter(executor));
-
         // chain.addLast(ProfilerTimerFilter.class.getSimpleName(), new ProfilerTimerFilter());
 
         chain.addLast(ProtocolCodecFilter.class.getSimpleName(), new ProtocolCodecFilter(getMessageCodecFactory()));

Modified: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/transport/base/BaseTransport.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/transport/base/BaseTransport.java?rev=578480&r1=578479&r2=578480&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/transport/base/BaseTransport.java (original)
+++ geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/transport/base/BaseTransport.java Sat Sep 22 12:35:42 2007
@@ -29,7 +29,7 @@
 import org.apache.geronimo.gshell.remote.message.Message;
 import org.apache.geronimo.gshell.remote.message.MessageVisitor;
 import org.apache.geronimo.gshell.remote.request.Requestor;
-import org.apache.geronimo.gshell.remote.session.ExecutorThreadModel;
+import org.apache.geronimo.gshell.remote.session.ThreadPoolModel;
 import org.apache.geronimo.gshell.remote.stream.SessionInputStream;
 import org.apache.geronimo.gshell.remote.stream.SessionOutputStream;
 import org.apache.geronimo.gshell.remote.transport.Transport;
@@ -60,7 +60,7 @@
 
     protected IoConnector connector;
 
-    protected ExecutorThreadModel threadModel;
+    protected ThreadPoolModel threadModel;
 
     protected IoSession session;
 
@@ -83,7 +83,7 @@
         connector = createConnector();
 
         // Install the thread model
-        threadModel = new ExecutorThreadModel(getClass().getSimpleName() + "-" + COUNTER.getAndIncrement());
+        threadModel = new ThreadPoolModel(getClass().getSimpleName() + "-" + COUNTER.getAndIncrement());
         connector.getDefaultConfig().setThreadModel(threadModel);
 
         //

Modified: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/transport/base/BaseTransportServer.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/transport/base/BaseTransportServer.java?rev=578480&r1=578479&r2=578480&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/transport/base/BaseTransportServer.java (original)
+++ geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/transport/base/BaseTransportServer.java Sat Sep 22 12:35:42 2007
@@ -25,7 +25,7 @@
 
 import org.apache.geronimo.gshell.remote.message.MessageVisitor;
 import org.apache.geronimo.gshell.remote.security.SecurityFilter;
-import org.apache.geronimo.gshell.remote.session.ExecutorThreadModel;
+import org.apache.geronimo.gshell.remote.session.ThreadPoolModel;
 import org.apache.geronimo.gshell.remote.transport.TransportServer;
 import org.apache.mina.common.DefaultIoFilterChainBuilder;
 import org.apache.mina.common.IoAcceptor;
@@ -47,7 +47,7 @@
 
     protected IoAcceptor acceptor;
 
-    protected ExecutorThreadModel threadModel;
+    protected ThreadPoolModel threadModel;
 
     protected boolean bound;
 
@@ -69,7 +69,7 @@
         acceptor = createAcceptor();
 
         // Install the thread model
-        threadModel = new ExecutorThreadModel(getClass().getSimpleName() + "-" + COUNTER.getAndIncrement());
+        threadModel = new ThreadPoolModel(getClass().getSimpleName() + "-" + COUNTER.getAndIncrement());
         acceptor.getDefaultConfig().setThreadModel(threadModel);
 
         //

Modified: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/util/NamedThreadFactory.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/util/NamedThreadFactory.java?rev=578480&r1=578479&r2=578480&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/util/NamedThreadFactory.java (original)
+++ geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/util/NamedThreadFactory.java Sat Sep 22 12:35:42 2007
@@ -58,6 +58,10 @@
         this(type.getSimpleName());
     }
 
+    public NamedThreadFactory(final Class type, final String suffix) {
+        this(type.getSimpleName() + "-" + suffix);
+    }
+    
     public Thread newThread(final Runnable task) {
         assert task != null;
 

Added: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/util/TimeValue.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/util/TimeValue.java?rev=578480&view=auto
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/util/TimeValue.java (added)
+++ geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/util/TimeValue.java Sat Sep 22 12:35:42 2007
@@ -0,0 +1,76 @@
+/*
+ * 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.util;
+
+import java.util.concurrent.TimeUnit;
+
+import org.apache.geronimo.gshell.common.tostring.ToStringBuilder;
+
+/**
+ * ???
+ *
+ * @version $Rev$ $Date$
+ */
+public class TimeValue
+{
+    public final long time;
+
+    public final TimeUnit unit;
+
+    public TimeValue(final long time, final TimeUnit unit) {
+        this.time = time;
+        this.unit = unit;
+    }
+
+    public long getTime() {
+        return time;
+    }
+
+    public TimeUnit getUnit() {
+        return unit;
+    }
+
+    public String toString() {
+        return new ToStringBuilder(this)
+                .append("time", time)
+                .append("unit", unit)
+                .toString();
+    }
+
+    public boolean equals(Object o) {
+        if (this == o) return true;
+        if (o == null || getClass() != o.getClass()) return false;
+
+        TimeValue timeValue = (TimeValue) o;
+
+        if (time != timeValue.time) return false;
+
+        return unit == timeValue.unit;
+    }
+
+    public int hashCode() {
+        int result;
+
+        result = (int) (time ^ (time >>> 32));
+        result = 31 * result + (unit != null ? unit.hashCode() : 0);
+
+        return result;
+    }
+}

Propchange: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/util/TimeValue.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/util/TimeValue.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/util/TimeValue.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-server/src/main/java/org/apache/geronimo/gshell/remote/server/DefaultRemoteShell.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-server/src/main/java/org/apache/geronimo/gshell/remote/server/DefaultRemoteShell.java?rev=578480&r1=578479&r2=578480&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-server/src/main/java/org/apache/geronimo/gshell/remote/server/DefaultRemoteShell.java (original)
+++ geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-server/src/main/java/org/apache/geronimo/gshell/remote/server/DefaultRemoteShell.java Sat Sep 22 12:35:42 2007
@@ -29,6 +29,7 @@
 import org.apache.geronimo.gshell.shell.Environment;
 import org.apache.geronimo.gshell.shell.ShellInfo;
 import org.codehaus.plexus.component.annotations.Component;
+import org.codehaus.plexus.component.annotations.InstantiationStrategy;
 import org.codehaus.plexus.component.annotations.Requirement;
 import org.codehaus.plexus.personality.plexus.lifecycle.phase.Initializable;
 import org.codehaus.plexus.personality.plexus.lifecycle.phase.InitializationException;
@@ -41,7 +42,7 @@
  *
  * @version $Rev$ $Date$
  */
-@Component(role=RemoteShell.class) // instantiationStrategy=InstantiationStrategy.PER_LOOKUP)
+@Component(role=RemoteShell.class, instantiationStrategy=InstantiationStrategy.PER_LOOKUP)
 public class DefaultRemoteShell
     implements RemoteShell, Initializable
 {
@@ -63,7 +64,7 @@
     
     private void ensureOpened() {
         if (!opened) {
-            throw new IllegalStateException();
+            throw new IllegalStateException("Not opened");
         }
     }
 
@@ -72,6 +73,8 @@
     }
 
     public void close() {
+        log.debug("Closing");
+        
         opened = false;
     }
 

Modified: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-server/src/main/java/org/apache/geronimo/gshell/remote/server/RshServerMessageVisitor.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-server/src/main/java/org/apache/geronimo/gshell/remote/server/RshServerMessageVisitor.java?rev=578480&r1=578479&r2=578480&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-server/src/main/java/org/apache/geronimo/gshell/remote/server/RshServerMessageVisitor.java (original)
+++ geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-server/src/main/java/org/apache/geronimo/gshell/remote/server/RshServerMessageVisitor.java Sat Sep 22 12:35:42 2007
@@ -58,12 +58,9 @@
 @Component(role=MessageVisitor.class, hint="server")
 public class RshServerMessageVisitor
     extends MessageVisitorSupport
-    implements Initializable
 {
     private static final SessionAttributeBinder<PlexusContainer> CONTAINER_BINDER = new SessionAttributeBinder<PlexusContainer>(PlexusContainer.class);
 
-    private static final SessionAttributeBinder<String> REALMID_BINDER = new SessionAttributeBinder<String>(PlexusContainer.class.getName() + ".realmId");
-
     private static final SessionAttributeBinder<IO> IO_BINDER = new SessionAttributeBinder<IO>(IO.class);
 
     private static final SessionAttributeBinder<Environment> ENV_BINDER = new SessionAttributeBinder<Environment>(Environment.class);
@@ -77,22 +74,6 @@
     @Requirement
     private PlexusContainer parentContainer;
 
-    private DefaultPlexusContainer container;
-
-    public void initialize() throws InitializationException {
-        // Create a new container which will be the parent for our remote shells
-        ContainerConfiguration config = new DefaultContainerConfiguration();
-        config.setName("gshell.rsh-server");
-        config.setClassWorld(parentContainer.getContainerRealm().getWorld());
-        
-        try {
-            container = new DefaultPlexusContainer(config);
-        }
-        catch (PlexusContainerException e) {
-            throw new InitializationException("Failed to construct container", e);
-        }
-    }
-
     //
     // MessageVisitor
     //
@@ -130,11 +111,27 @@
                 }
             }.start();
         }
+        else if ("NO REPLY".equals(text)) {
+            // ignore
+        }
         else {
             msg.reply(new EchoMessage(text));
         }
     }
 
+    private DefaultPlexusContainer createContainer() throws PlexusContainerException {
+        // Create a new container which will be the parent for our remote shells
+        ContainerConfiguration config = new DefaultContainerConfiguration();
+
+        String name = "gshell.remote-shell:" + UUID.randomUUID();
+
+        config.setName(name);
+
+        config.setClassWorld(parentContainer.getContainerRealm().getWorld());
+
+        return new DefaultPlexusContainer(config);
+    }
+
     public void visitOpenShell(final OpenShellMessage msg) throws Exception {
         assert msg != null;
 
@@ -142,12 +139,7 @@
 
         IoSession session = msg.getSession();
 
-        String realmId = "gshell.remote-shell:" + UUID.randomUUID();
-        REALMID_BINDER.bind(session, realmId);
-
-        log.debug("Remote shell container realm: {}", realmId);
-
-        PlexusContainer childContainer = container.createChildContainer(realmId, container.getContainerRealm());
+        PlexusContainer childContainer = createContainer();
         CONTAINER_BINDER.bind(session, childContainer);
 
         // Setup the I/O context (w/o auto-flushing)
@@ -157,16 +149,16 @@
         // FIXME: We need to set the verbosity of this I/O context as specified by the client
         //
 
-        IOLookup.set(container, io);
+        IOLookup.set(childContainer, io);
         IO_BINDER.bind(session, io);
 
         // Setup shell environemnt
         Environment env = new DefaultEnvironment(io);
-        EnvironmentLookup.set(container, env);
+        EnvironmentLookup.set(childContainer, env);
         ENV_BINDER.bind(session, env);
 
         // Create a new shell instance
-        RemoteShell shell = (RemoteShell) container.lookup(RemoteShell.class);
+        RemoteShell shell = (RemoteShell) childContainer.lookup(RemoteShell.class);
         SHELL_BINDER.bind(session, shell);
 
         //
@@ -197,9 +189,12 @@
 
         log.info("Destroying container");
 
-        String realmId = REALMID_BINDER.unbind(session);
-        container.removeChildContainer(realmId);
-        CONTAINER_BINDER.unbind(session);
+        PlexusContainer childContainer = CONTAINER_BINDER.unbind(session);
+
+        //
+        // FIXME: This won't work... it kills our class realm... :-(
+        //
+        // childContainer.dispose();
         
         //
         // TODO: Send a meaningful response
@@ -232,12 +227,18 @@
 
             Object result = msg.execute(shell);
 
+            log.debug("Result: {}", result);
+
             msg.reply(new ExecuteMessage.Result(result));
         }
         catch (Notification n) {
+            log.debug("Notification: " + n);
+
             msg.reply(new ExecuteMessage.Notification(n));
         }
         catch (Throwable t) {
+            log.debug("Fault: " + t);
+
             msg.reply(new ExecuteMessage.Fault(t));
         }
     }