geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jdil...@apache.org
Subject svn commit: r578421 [3/3] - in /geronimo/sandbox/gshell/trunk/gshell-remote: gshell-remote-client/src/main/java/org/apache/geronimo/gshell/remote/client/ gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/codec/ gshell-remote-common/s...
Date Sat, 22 Sep 2007 12:42:28 GMT
Copied: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/transport/base/BaseTransportServer.java
(from r578362, geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/transport/tcp/TcpTransportServer.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?p2=geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/transport/base/BaseTransportServer.java&p1=geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/transport/tcp/TcpTransportServer.java&r1=578362&r2=578421&rev=578421&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/transport/tcp/TcpTransportServer.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 05:42:24 2007
@@ -17,41 +17,41 @@
  * under the License.
  */
 
-package org.apache.geronimo.gshell.remote.transport.tcp;
+package org.apache.geronimo.gshell.remote.transport.base;
 
-import java.net.InetAddress;
-import java.net.InetSocketAddress;
 import java.net.SocketAddress;
 import java.net.URI;
-import java.util.concurrent.Executors;
+import java.util.concurrent.atomic.AtomicLong;
 
 import org.apache.geronimo.gshell.remote.message.MessageVisitor;
 import org.apache.geronimo.gshell.remote.security.SecurityFilter;
-import org.apache.geronimo.gshell.remote.transport.TransportCommon;
+import org.apache.geronimo.gshell.remote.session.ExecutorThreadModel;
 import org.apache.geronimo.gshell.remote.transport.TransportServer;
 import org.apache.mina.common.DefaultIoFilterChainBuilder;
 import org.apache.mina.common.IoAcceptor;
-import org.apache.mina.transport.socket.nio.SocketAcceptor;
-import org.apache.mina.transport.socket.nio.SocketAcceptorConfig;
 
 /**
- * Provides TCP server-side support.
+ * Support for {@link TransportServer} implementations.
  *
  * @version $Rev$ $Date$
  */
-public class TcpTransportServer
-    extends TransportCommon
+public abstract class BaseTransportServer
+    extends BaseCommon
     implements TransportServer
 {
+    private static final AtomicLong COUNTER = new AtomicLong(0);
+
     protected final URI location;
 
     protected final SocketAddress address;
 
     protected IoAcceptor acceptor;
 
+    protected ExecutorThreadModel threadModel;
+
     protected boolean bound;
 
-    protected TcpTransportServer(final URI location, final SocketAddress address) {
+    protected BaseTransportServer(final URI location, final SocketAddress address) {
         assert location != null;
         assert address != null;
 
@@ -59,27 +59,19 @@
         this.address = address;
     }
 
-    public TcpTransportServer(final URI location) throws Exception {
-        this(location, new InetSocketAddress(InetAddress.getByName(location.getHost()), location.getPort()));
-    }
-
     public URI getLocation() {
         return location;
     }
-    
-    protected IoAcceptor createAcceptor() throws Exception {
-        SocketAcceptor acceptor = new SocketAcceptor(Runtime.getRuntime().availableProcessors()
+ 1, Executors.newCachedThreadPool());
 
-        SocketAcceptorConfig config = acceptor.getDefaultConfig();
-
-        config.getSessionConfig().setKeepAlive(true);
-
-        return acceptor;
-    }
+    protected abstract IoAcceptor createAcceptor() throws Exception;
 
     protected synchronized void init() throws Exception {
         acceptor = createAcceptor();
 
+        // Install the thread model
+        threadModel = new ExecutorThreadModel(getClass().getSimpleName() + "-" + COUNTER.getAndIncrement());
+        acceptor.getDefaultConfig().setThreadModel(threadModel);
+
         //
         // HACK: Need to manually wire in the visitor impl for now... :-(
         //
@@ -87,10 +79,15 @@
         setMessageVisitor((MessageVisitor) getContainer().lookup(MessageVisitor.class, "server"));
 
         configure(acceptor);
+    }
+
+    @Override
+    protected void configure(final DefaultIoFilterChainBuilder chain) throws Exception {
+        assert chain != null;
+
+        super.configure(chain);
 
-        DefaultIoFilterChainBuilder filterChain = acceptor.getFilterChain();
-        
-        filterChain.addLast(SecurityFilter.class.getSimpleName(), getSecurityFilter());
+        chain.addLast(SecurityFilter.class.getSimpleName(), getSecurityFilter());
     }
 
     public synchronized void bind() throws Exception {
@@ -100,7 +97,7 @@
 
         init();
 
-        acceptor.bind(address, getProtocolHandler());
+        acceptor.bind(address, getHandler());
 
         bound = true;
 
@@ -110,6 +107,8 @@
     public synchronized void close() {
         try {
             acceptor.unbind(address);
+
+            threadModel.close();
         }
         finally {
             super.close();
@@ -117,14 +116,15 @@
     }
 
     //
-    // AutoWire Support
+    // AutoWire Support, Setters exposed to support Plexus autowire()  Getters exposed to
handle state checking.
     //
 
-    private SecurityFilter securityFilter;
-    
     //
-    // NOTE: Setters exposed to support Plexus autowire()  Getters exposed to handle state
checking.
+    // TODO: See if we should tack this puppy on in the handler when the session opens er
something? Since this
+    //       is rather application specific...
     //
+    
+    private SecurityFilter securityFilter;
 
     public void setSecurityFilter(final SecurityFilter securityFilter) {
         this.securityFilter = securityFilter;
@@ -137,5 +137,4 @@
 
         return securityFilter;
     }
-
 }

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

Propchange: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/transport/base/BaseTransportServer.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/transport/base/BaseTransportServer.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/transport/base/package-info.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/package-info.java?rev=578421&view=auto
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/transport/base/package-info.java
(added)
+++ geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/transport/base/package-info.java
Sat Sep 22 05:42:24 2007
@@ -0,0 +1,25 @@
+/*
+ * 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.
+ */
+
+/**
+ * Base support for transport implementations.
+ *
+ * @version $Rev$ $Date$
+ */
+package org.apache.geronimo.gshell.remote.transport.base;
\ No newline at end of file

Propchange: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/transport/base/package-info.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/transport/base/package-info.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/transport/base/package-info.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/ssl/SslTransport.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/ssl/SslTransport.java?rev=578421&r1=578420&r2=578421&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/transport/ssl/SslTransport.java
(original)
+++ geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/transport/ssl/SslTransport.java
Sat Sep 22 05:42:24 2007
@@ -24,7 +24,6 @@
 import org.apache.geronimo.gshell.remote.ssl.SSLContextFactory;
 import org.apache.geronimo.gshell.remote.transport.tcp.TcpTransport;
 import org.apache.mina.common.DefaultIoFilterChainBuilder;
-import org.apache.mina.common.IoService;
 import org.apache.mina.filter.SSLFilter;
 
 /**
@@ -39,27 +38,24 @@
         super(remote, local);
     }
 
-    protected void configure(final IoService service) throws Exception {
-        super.configure(service);
+    @Override
+    protected void configure(final DefaultIoFilterChainBuilder chain) throws Exception {
+        assert chain != null;
 
-        DefaultIoFilterChainBuilder filterChain = service.getFilterChain();
+        super.configure(chain);
 
         SSLFilter sslFilter = new SSLFilter(getSslContextFactory().createClientContext());
         sslFilter.setUseClientMode(true);
 
-        filterChain.addFirst(SSLFilter.class.getSimpleName(), sslFilter);
+        chain.addFirst(SSLFilter.class.getSimpleName(), sslFilter);
     }
 
     //
-    // AutoWire Support
+    // AutoWire Support, Setters exposed to support Plexus autowire()  Getters exposed to
handle state checking.
     //
 
     private SSLContextFactory sslContextFactory;
-
-    //
-    // NOTE: Setters exposed to support Plexus autowire()
-    //
-
+    
     public void setSslContextFactory(final SSLContextFactory factory) {
         log.debug("Using SSL Context Factory: {}", factory);
 

Modified: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/transport/ssl/SslTransportFactory.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/ssl/SslTransportFactory.java?rev=578421&r1=578420&r2=578421&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/transport/ssl/SslTransportFactory.java
(original)
+++ geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/transport/ssl/SslTransportFactory.java
Sat Sep 22 05:42:24 2007
@@ -21,10 +21,10 @@
 
 import java.net.URI;
 
+import org.apache.geronimo.gshell.remote.transport.Transport;
 import org.apache.geronimo.gshell.remote.transport.TransportFactory;
-import org.apache.geronimo.gshell.remote.transport.tcp.TcpTransport;
+import org.apache.geronimo.gshell.remote.transport.TransportServer;
 import org.apache.geronimo.gshell.remote.transport.tcp.TcpTransportFactory;
-import org.apache.geronimo.gshell.remote.transport.tcp.TcpTransportServer;
 import org.codehaus.plexus.component.annotations.Component;
 
 /**
@@ -37,12 +37,12 @@
     extends TcpTransportFactory
 {
     @Override
-    protected TcpTransport createTransport(final URI remote, final URI local) throws Exception
{
+    protected Transport createTransport(final URI remote, final URI local) throws Exception
{
         return new SslTransport(remote, local);
     }
 
     @Override
-    protected TcpTransportServer createTransportServer(final URI location) throws Exception
{
+    protected TransportServer createTransportServer(final URI location) throws Exception
{
         return new SslTransportServer(location);
     }
 }

Modified: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/transport/ssl/SslTransportServer.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/ssl/SslTransportServer.java?rev=578421&r1=578420&r2=578421&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/transport/ssl/SslTransportServer.java
(original)
+++ geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/transport/ssl/SslTransportServer.java
Sat Sep 22 05:42:24 2007
@@ -24,7 +24,6 @@
 import org.apache.geronimo.gshell.remote.ssl.SSLContextFactory;
 import org.apache.geronimo.gshell.remote.transport.tcp.TcpTransportServer;
 import org.apache.mina.common.DefaultIoFilterChainBuilder;
-import org.apache.mina.common.IoService;
 import org.apache.mina.filter.SSLFilter;
 
 /**
@@ -39,25 +38,22 @@
         super(location);
     }
 
-    protected void configure(final IoService service) throws Exception {
-        super.configure(service);
+    @Override
+    protected void configure(final DefaultIoFilterChainBuilder chain) throws Exception {
+        assert chain != null;
 
-        DefaultIoFilterChainBuilder filterChain = service.getFilterChain();
+        super.configure(chain);
 
         SSLFilter sslFilter = new SSLFilter(getSslContextFactory().createServerContext());
 
-        filterChain.addFirst(SSLFilter.class.getSimpleName(), sslFilter);
+        chain.addFirst(SSLFilter.class.getSimpleName(), sslFilter);
     }
 
     //
-    // AutoWire Support
+    // AutoWire Support, Setters exposed to support Plexus autowire()  Getters exposed to
handle state checking.
     //
 
     private SSLContextFactory sslContextFactory;
-
-    //
-    // NOTE: Setters exposed to support Plexus autowire()
-    //
 
     public void setSslContextFactory(final SSLContextFactory factory) {
         log.debug("Using SSL Context Factory: {}", factory);

Modified: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/transport/tcp/TcpTransport.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/tcp/TcpTransport.java?rev=578421&r1=578420&r2=578421&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/transport/tcp/TcpTransport.java
(original)
+++ geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/transport/tcp/TcpTransport.java
Sat Sep 22 05:42:24 2007
@@ -19,27 +19,11 @@
 
 package org.apache.geronimo.gshell.remote.transport.tcp;
 
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.net.InetAddress;
-import java.net.InetSocketAddress;
-import java.net.SocketAddress;
 import java.net.URI;
 import java.util.concurrent.Executors;
-import java.util.concurrent.TimeUnit;
 
-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.stream.SessionInputStream;
-import org.apache.geronimo.gshell.remote.stream.SessionOutputStream;
-import org.apache.geronimo.gshell.remote.transport.Transport;
-import org.apache.geronimo.gshell.remote.transport.TransportCommon;
-import org.apache.mina.common.CloseFuture;
-import org.apache.mina.common.ConnectFuture;
+import org.apache.geronimo.gshell.remote.transport.base.BaseTransport;
 import org.apache.mina.common.IoConnector;
-import org.apache.mina.common.IoSession;
-import org.apache.mina.common.WriteFuture;
 import org.apache.mina.transport.socket.nio.SocketConnector;
 import org.apache.mina.transport.socket.nio.SocketConnectorConfig;
 
@@ -49,52 +33,13 @@
  * @version $Rev$ $Date$
  */
 public class TcpTransport
-    extends TransportCommon
-    implements Transport
+    extends BaseTransport
 {
-    protected final URI remoteLocation;
-
-    protected final SocketAddress remoteAddress;
-
-    protected final URI localLocation;
-
-    protected final SocketAddress localAddress;
-
-    protected IoConnector connector;
-
-    protected IoSession session;
-
-    protected boolean connected;
-
-    protected TcpTransport(final URI remoteLocation, final SocketAddress remoteAddress, final
URI localLocation, final SocketAddress localAddress) throws Exception {
-        assert remoteLocation != null;
-        assert remoteAddress != null;
-
-        this.remoteLocation = remoteLocation;
-        this.remoteAddress = remoteAddress;
-
-        this.localLocation = localLocation;
-        this.localAddress = localAddress;
-    }
-
     public TcpTransport(final URI remote, final URI local) throws Exception {
-        assert remote != null;
-        // local may be null
-
-        this.remoteLocation = remote;
-        this.remoteAddress = new InetSocketAddress(InetAddress.getByName(remote.getHost()),
remote.getPort());
-
-        if (local != null) {
-            this.localLocation = local;
-            this.localAddress = new InetSocketAddress(InetAddress.getByName(local.getHost()),
local.getPort());
-        }
-        else {
-            // These are final, so make sure to mark them null if we have no local address
-            this.localLocation = null;
-            this.localAddress = null;
-        }
+        super(remote, TcpTransportFactory.address(remote), local, TcpTransportFactory.address(local));
     }
 
+    @Override
     protected IoConnector createConnector() throws Exception {
         SocketConnector connector = new SocketConnector(Runtime.getRuntime().availableProcessors()
+ 1, Executors.newCachedThreadPool());
 
@@ -103,86 +48,5 @@
         config.getSessionConfig().setKeepAlive(true);
 
         return connector;
-    }
-
-    protected synchronized void init() throws Exception {
-        connector = createConnector();
-
-        //
-        // HACK: Need to manually wire in the visitor impl for now... :-(
-        //
-
-        setMessageVisitor((MessageVisitor) getContainer().lookup(MessageVisitor.class, "client"));
-        
-        configure(connector);
-    }
-
-    public synchronized void connect() throws Exception {
-        if (connected) {
-            throw new IllegalStateException("Already connected");
-        }
-        
-        init();
-
-        log.info("Connecting to: {}", remoteAddress);
-
-        ConnectFuture cf = connector.connect(remoteAddress, localAddress, getProtocolHandler());
-
-        cf.join();
-
-        session = cf.getSession();
-
-        connected = true;
-        
-        log.info("Connected");
-    }
-
-    public synchronized void close() {
-        try {
-            CloseFuture cf = session.close();
-
-            cf.join();
-        }
-        finally {
-            super.close();
-        }
-    }
-
-    public URI getRemoteLocation() {
-        return remoteLocation;
-    }
-
-    public URI getLocalLocation() {
-        return localLocation;
-    }
-
-    public WriteFuture send(final Object msg) throws Exception {
-        assert msg != null;
-
-        return session.write(msg);
-    }
-
-    public Message request(final Message msg) throws Exception {
-        assert msg != null;
-
-        Requestor requestor = new Requestor(this);
-
-        return requestor.request(msg);
-    }
-    
-    public Message request(final Message msg, final long timeout, final TimeUnit unit) throws
Exception {
-        assert msg != null;
-
-        Requestor requestor = new Requestor(this);
-
-        return requestor.request(msg, timeout, unit);
-    }
-    
-    public InputStream getInputStream() {
-        return SessionInputStream.BINDER.lookup(session);
-    }
-
-    public OutputStream getOutputStream() {
-        return SessionOutputStream.BINDER.lookup(session);
     }
 }

Modified: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/transport/tcp/TcpTransportFactory.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/tcp/TcpTransportFactory.java?rev=578421&r1=578420&r2=578421&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/transport/tcp/TcpTransportFactory.java
(original)
+++ geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/transport/tcp/TcpTransportFactory.java
Sat Sep 22 05:42:24 2007
@@ -19,14 +19,16 @@
 
 package org.apache.geronimo.gshell.remote.transport.tcp;
 
+import java.net.InetAddress;
+import java.net.InetSocketAddress;
 import java.net.URI;
+import java.net.UnknownHostException;
 
 import org.apache.geronimo.gshell.remote.transport.Transport;
 import org.apache.geronimo.gshell.remote.transport.TransportFactory;
 import org.apache.geronimo.gshell.remote.transport.TransportServer;
-import org.codehaus.plexus.PlexusContainer;
+import org.apache.geronimo.gshell.remote.transport.base.BaseTransportFactory;
 import org.codehaus.plexus.component.annotations.Component;
-import org.codehaus.plexus.component.annotations.Requirement;
 
 /**
  * Produces TCP transport instances.
@@ -35,52 +37,25 @@
  */
 @Component(role=TransportFactory.class, hint="tcp")
 public class TcpTransportFactory
-    implements TransportFactory
+    extends BaseTransportFactory
 {
-    @Requirement
-    private PlexusContainer container;
-
-    //
-    // NOTE: We use autowire() here to get a few components injected.  These are injected
via setters.
-    //
-    
-    public Transport connect(final URI remote, final URI local) throws Exception {
-        assert remote != null;
-        // local can be null
-
-        TcpTransport transport = createTransport(remote, local);
-
-        container.autowire(transport);
-
-        transport.connect();
-
-        return transport;
-    }
-
-    protected TcpTransport createTransport(final URI remote, final URI local) throws Exception
{
-        assert remote != null;
-        // local can be null
-        
+    @Override
+    protected Transport createTransport(final URI remote, final URI local) throws Exception
{
         return new TcpTransport(remote, local);
     }
 
-    public Transport connect(final URI remote) throws Exception {
-        return connect(remote, null);
+    @Override
+    protected TransportServer createTransportServer(final URI location) throws Exception
{
+        return new TcpTransportServer(location);
     }
 
-    public TransportServer bind(final URI location) throws Exception {
-        assert location != null;
-
-        TcpTransportServer server = createTransportServer(location);
-
-        container.autowire(server);
+    static InetSocketAddress address(final URI location) throws UnknownHostException {
+        InetSocketAddress addr = null;
 
-        server.bind();
+        if (location != null) {
+            addr = new InetSocketAddress(InetAddress.getByName(location.getHost()), location.getPort());
+        }
 
-        return server;
-    }
-
-    protected TcpTransportServer createTransportServer(final URI location) throws Exception
{
-        return new TcpTransportServer(location);
+        return addr;
     }
 }

Modified: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/transport/tcp/TcpTransportServer.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/tcp/TcpTransportServer.java?rev=578421&r1=578420&r2=578421&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/transport/tcp/TcpTransportServer.java
(original)
+++ geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/transport/tcp/TcpTransportServer.java
Sat Sep 22 05:42:24 2007
@@ -19,17 +19,10 @@
 
 package org.apache.geronimo.gshell.remote.transport.tcp;
 
-import java.net.InetAddress;
-import java.net.InetSocketAddress;
-import java.net.SocketAddress;
 import java.net.URI;
 import java.util.concurrent.Executors;
 
-import org.apache.geronimo.gshell.remote.message.MessageVisitor;
-import org.apache.geronimo.gshell.remote.security.SecurityFilter;
-import org.apache.geronimo.gshell.remote.transport.TransportCommon;
-import org.apache.geronimo.gshell.remote.transport.TransportServer;
-import org.apache.mina.common.DefaultIoFilterChainBuilder;
+import org.apache.geronimo.gshell.remote.transport.base.BaseTransportServer;
 import org.apache.mina.common.IoAcceptor;
 import org.apache.mina.transport.socket.nio.SocketAcceptor;
 import org.apache.mina.transport.socket.nio.SocketAcceptorConfig;
@@ -40,33 +33,13 @@
  * @version $Rev$ $Date$
  */
 public class TcpTransportServer
-    extends TransportCommon
-    implements TransportServer
+    extends BaseTransportServer
 {
-    protected final URI location;
-
-    protected final SocketAddress address;
-
-    protected IoAcceptor acceptor;
-
-    protected boolean bound;
-
-    protected TcpTransportServer(final URI location, final SocketAddress address) {
-        assert location != null;
-        assert address != null;
-
-        this.location = location;
-        this.address = address;
-    }
-
     public TcpTransportServer(final URI location) throws Exception {
-        this(location, new InetSocketAddress(InetAddress.getByName(location.getHost()), location.getPort()));
+        super(location, TcpTransportFactory.address(location));
     }
 
-    public URI getLocation() {
-        return location;
-    }
-    
+    @Override
     protected IoAcceptor createAcceptor() throws Exception {
         SocketAcceptor acceptor = new SocketAcceptor(Runtime.getRuntime().availableProcessors()
+ 1, Executors.newCachedThreadPool());
 
@@ -76,66 +49,4 @@
 
         return acceptor;
     }
-
-    protected synchronized void init() throws Exception {
-        acceptor = createAcceptor();
-
-        //
-        // HACK: Need to manually wire in the visitor impl for now... :-(
-        //
-
-        setMessageVisitor((MessageVisitor) getContainer().lookup(MessageVisitor.class, "server"));
-
-        configure(acceptor);
-
-        DefaultIoFilterChainBuilder filterChain = acceptor.getFilterChain();
-        
-        filterChain.addLast(SecurityFilter.class.getSimpleName(), getSecurityFilter());
-    }
-
-    public synchronized void bind() throws Exception {
-        if (bound) {
-            throw new IllegalStateException("Already bound");
-        }
-
-        init();
-
-        acceptor.bind(address, getProtocolHandler());
-
-        bound = true;
-
-        log.info("Listening on: {}", address);
-    }
-
-    public synchronized void close() {
-        try {
-            acceptor.unbind(address);
-        }
-        finally {
-            super.close();
-        }
-    }
-
-    //
-    // AutoWire Support
-    //
-
-    private SecurityFilter securityFilter;
-    
-    //
-    // NOTE: Setters exposed to support Plexus autowire()  Getters exposed to handle state
checking.
-    //
-
-    public void setSecurityFilter(final SecurityFilter securityFilter) {
-        this.securityFilter = securityFilter;
-    }
-
-    protected SecurityFilter getSecurityFilter() {
-        if (securityFilter == null) {
-            throw new IllegalStateException("Security filter not bound");
-        }
-
-        return securityFilter;
-    }
-
 }

Modified: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/transport/vm/VmTransport.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/vm/VmTransport.java?rev=578421&r1=578420&r2=578421&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/transport/vm/VmTransport.java
(original)
+++ geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/transport/vm/VmTransport.java
Sat Sep 22 05:42:24 2007
@@ -21,9 +21,8 @@
 
 import java.net.URI;
 
-import org.apache.geronimo.gshell.remote.transport.tcp.TcpTransport;
+import org.apache.geronimo.gshell.remote.transport.base.BaseTransport;
 import org.apache.mina.common.IoConnector;
-import org.apache.mina.transport.vmpipe.VmPipeAddress;
 import org.apache.mina.transport.vmpipe.VmPipeConnector;
 
 /**
@@ -32,12 +31,13 @@
  * @version $Rev$ $Date$
  */
 public class VmTransport
-    extends TcpTransport
+    extends BaseTransport
 {
     public VmTransport(final URI remote, final URI local) throws Exception {
-        super(remote, new VmPipeAddress(remote.getPort()), local, local != null ? new VmPipeAddress(local.getPort())
: null);
+        super(remote, VmTransportFactory.address(remote), local, VmTransportFactory.address(local));
     }
 
+    @Override
     protected IoConnector createConnector() throws Exception {
         return new VmPipeConnector();
     }

Modified: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/transport/vm/VmTransportFactory.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/vm/VmTransportFactory.java?rev=578421&r1=578420&r2=578421&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/transport/vm/VmTransportFactory.java
(original)
+++ geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/transport/vm/VmTransportFactory.java
Sat Sep 22 05:42:24 2007
@@ -24,9 +24,9 @@
 import org.apache.geronimo.gshell.remote.transport.Transport;
 import org.apache.geronimo.gshell.remote.transport.TransportFactory;
 import org.apache.geronimo.gshell.remote.transport.TransportServer;
-import org.codehaus.plexus.PlexusContainer;
+import org.apache.geronimo.gshell.remote.transport.base.BaseTransportFactory;
+import org.apache.mina.transport.vmpipe.VmPipeAddress;
 import org.codehaus.plexus.component.annotations.Component;
-import org.codehaus.plexus.component.annotations.Requirement;
 
 /**
  * Produces in-VM transport instances.
@@ -35,52 +35,25 @@
  */
 @Component(role=TransportFactory.class, hint="vm")
 public class VmTransportFactory
-    implements TransportFactory
+    extends BaseTransportFactory
 {
-    @Requirement
-    private PlexusContainer container;
-
-    //
-    // NOTE: We use autowire() here to get a few components injected.  These are injected
via setters.
-    //
-
-    public Transport connect(final URI remote, final URI local) throws Exception {
-        assert remote != null;
-        // local can be null
-
-        VmTransport transport = createTransport(remote, local);
-
-        container.autowire(transport);
-
-        transport.connect();
-
-        return transport;
-    }
-
-    protected VmTransport createTransport(final URI remote, final URI local) throws Exception
{
-        assert remote != null;
-        // local can be null
-
+    @Override
+    protected Transport createTransport(final URI remote, final URI local) throws Exception
{
         return new VmTransport(remote, local);
     }
 
-    public Transport connect(final URI remote) throws Exception {
-        return connect(remote, null);
+    @Override
+    protected TransportServer createTransportServer(final URI location) throws Exception
{
+        return new VmTransportServer(location);
     }
 
-    public TransportServer bind(final URI location) throws Exception {
-        assert location != null;
-
-        VmTransportServer server = createTransportServer(location);
-
-        container.autowire(server);
+    static VmPipeAddress address(final URI location) {
+        VmPipeAddress addr = null;
 
-        server.bind();
+        if (location != null) {
+            addr = new VmPipeAddress(location.getPort());
+        }
 
-        return server;
-    }
-
-    protected VmTransportServer createTransportServer(final URI location) throws Exception
{
-        return new VmTransportServer(location);
+        return addr;
     }
 }

Modified: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/transport/vm/VmTransportServer.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/vm/VmTransportServer.java?rev=578421&r1=578420&r2=578421&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/transport/vm/VmTransportServer.java
(original)
+++ geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/transport/vm/VmTransportServer.java
Sat Sep 22 05:42:24 2007
@@ -21,10 +21,9 @@
 
 import java.net.URI;
 
-import org.apache.geronimo.gshell.remote.transport.tcp.TcpTransportServer;
+import org.apache.geronimo.gshell.remote.transport.base.BaseTransportServer;
 import org.apache.mina.common.IoAcceptor;
 import org.apache.mina.transport.vmpipe.VmPipeAcceptor;
-import org.apache.mina.transport.vmpipe.VmPipeAddress;
 
 /**
  * Provides in-VM server-side support.
@@ -32,12 +31,13 @@
  * @version $Rev$ $Date$
  */
 public class VmTransportServer
-    extends TcpTransportServer
+    extends BaseTransportServer
 {
     public VmTransportServer(final URI location) throws Exception {
-        super(location, new VmPipeAddress(location.getPort()));
+        super(location, VmTransportFactory.address(location));
     }
 
+    @Override
     protected IoAcceptor createAcceptor() throws Exception {
         return new VmPipeAcceptor();
     }

Added: 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=578421&view=auto
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/util/NamedThreadFactory.java
(added)
+++ geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/util/NamedThreadFactory.java
Sat Sep 22 05:42:24 2007
@@ -0,0 +1,78 @@
+/*
+ * 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.ThreadFactory;
+import java.util.concurrent.atomic.AtomicLong;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * ???
+ *
+ * @version $Rev$ $Date$
+ */
+public class NamedThreadFactory
+    implements ThreadFactory
+{
+    private final Logger log = LoggerFactory.getLogger(getClass());
+
+    private final String name;
+
+    private final ThreadGroup group;
+
+    private final AtomicLong counter = new AtomicLong(0);
+
+    public NamedThreadFactory(final String name, final ThreadGroup group) {
+        assert name != null;
+        assert group != null;
+
+        this.name = name;
+
+        this.group = group;
+    }
+
+    public NamedThreadFactory(final String name) {
+        this(name, Thread.currentThread().getThreadGroup());
+    }
+
+    public NamedThreadFactory(final Class type) {
+        this(type.getSimpleName());
+    }
+
+    public Thread newThread(final Runnable task) {
+        assert task != null;
+
+        String id = name + "-" + counter.getAndIncrement();
+
+        Thread t = new Thread(group, task, id);
+        
+        configure(t);
+
+        log.debug("Created thread: {}", t);
+
+        return t;
+    }
+
+    protected void configure(final Thread t) {
+        t.setDaemon(true);
+    }
+}
\ No newline at end of file

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

Propchange: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/util/NamedThreadFactory.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/NamedThreadFactory.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=578421&r1=578420&r2=578421&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 05:42:24 2007
@@ -73,8 +73,6 @@
 
     public void close() {
         opened = false;
-
-        log.info("Closed");
     }
 
     public Environment getEnvironment() {

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=578421&r1=578420&r2=578421&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 05:42:24 2007
@@ -28,12 +28,12 @@
 import org.apache.geronimo.gshell.lookup.EnvironmentLookup;
 import org.apache.geronimo.gshell.lookup.IOLookup;
 import org.apache.geronimo.gshell.remote.RemoteShell;
-import org.apache.geronimo.gshell.remote.message.CloseShellMessage;
-import org.apache.geronimo.gshell.remote.message.EchoMessage;
-import org.apache.geronimo.gshell.remote.message.ExecuteMessage;
 import org.apache.geronimo.gshell.remote.message.MessageVisitor;
 import org.apache.geronimo.gshell.remote.message.MessageVisitorSupport;
-import org.apache.geronimo.gshell.remote.message.OpenShellMessage;
+import org.apache.geronimo.gshell.remote.message.rsh.CloseShellMessage;
+import org.apache.geronimo.gshell.remote.message.rsh.EchoMessage;
+import org.apache.geronimo.gshell.remote.message.rsh.ExecuteMessage;
+import org.apache.geronimo.gshell.remote.message.rsh.OpenShellMessage;
 import org.apache.geronimo.gshell.remote.stream.SessionInputStream;
 import org.apache.geronimo.gshell.remote.stream.SessionOutputStream;
 import org.apache.geronimo.gshell.shell.Environment;



Mime
View raw message