geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jdil...@apache.org
Subject svn commit: r576612 [2/2] - 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/ gshell-remote-common/src/mai...
Date Mon, 17 Sep 2007 22:27:59 GMT
Added: 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=576612&view=auto
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/transport/tcp/TcpTransportServer.java
(added)
+++ geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/transport/tcp/TcpTransportServer.java
Mon Sep 17 15:27:55 2007
@@ -0,0 +1,133 @@
+/*
+ * 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.transport.tcp;
+
+import java.net.InetSocketAddress;
+import java.net.URI;
+import java.net.InetAddress;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+
+import org.apache.geronimo.gshell.remote.filter.LoggingFilter;
+import org.apache.geronimo.gshell.remote.message.MessageCodecFactory;
+import org.apache.geronimo.gshell.remote.transport.TransportServer;
+import org.apache.mina.common.DefaultIoFilterChainBuilder;
+import org.apache.mina.common.CloseFuture;
+import org.apache.mina.filter.codec.ProtocolCodecFilter;
+import org.apache.mina.transport.socket.nio.SocketAcceptor;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * ???
+ *
+ * @version $Rev$ $Date$
+ */
+public class TcpTransportServer
+    implements TransportServer
+{
+    protected Logger log = LoggerFactory.getLogger(getClass());
+
+    protected TcpServerMessageVisitor messageVisitor;
+    
+    protected TcpProtocolHandler protocolHandler;
+
+    protected URI location;
+
+    protected InetSocketAddress address;
+
+    protected SocketAcceptor acceptor;
+
+    protected boolean bound;
+
+    public TcpTransportServer(final URI location) throws Exception {
+        assert location != null;
+
+        this.location = location;
+        this.address = new InetSocketAddress(InetAddress.getByName(location.getHost()), location.getPort());
+    }
+
+    protected void init() throws Exception {
+        if (protocolHandler == null) {
+            throw new IllegalStateException("Protocol handler not injected");
+        }
+        if (messageVisitor == null) {
+            throw new IllegalStateException("Message visitor not injected");
+        }
+
+        protocolHandler.setVisitor(messageVisitor);
+        
+        ExecutorService executor = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors()
+ 1);
+        
+        acceptor = new SocketAcceptor(Runtime.getRuntime().availableProcessors(), executor);
+        acceptor.setLocalAddress(address);
+        acceptor.setHandler(protocolHandler);
+
+        DefaultIoFilterChainBuilder filterChain = acceptor.getFilterChain();
+
+        filterChain.addLast("logger", new LoggingFilter());
+
+        filterChain.addLast("protocol", new ProtocolCodecFilter(new MessageCodecFactory()));
+
+        // filterChain.addLast("auth", new AuthenticationFilter());
+    }
+
+    //
+    // NOTE: Setters exposed to support Plexus autowire()
+    //
+
+    public void setMessageVisitor(final TcpServerMessageVisitor messageVisitor) {
+        log.debug("Using message visitor: {}", messageVisitor);
+
+        this.messageVisitor = messageVisitor;
+    }
+
+    public void setProtocolHandler(final TcpProtocolHandler protocolHandler) {
+        log.debug("Using protocol handler: {}", protocolHandler);
+
+        this.protocolHandler = protocolHandler;
+    }
+
+    public void bind() throws Exception {
+        if (bound) {
+            throw new IllegalStateException("Already bound");
+        }
+
+        init();
+
+        acceptor.bind();
+
+        bound = true;
+
+        log.info("Listening on: {}", address);
+    }
+
+    public URI getLocation() {
+        return location;
+    }
+
+    //
+    // TransportServer
+    //
+
+    public void close() {
+        acceptor.unbind();
+    }
+}
\ 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/tcp/TcpTransportServer.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/transport/tcp/TcpTransportServer.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/tcp/TcpTransportServer.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/tcp/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/tcp/package-info.java?rev=576612&view=auto
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/transport/tcp/package-info.java
(added)
+++ geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/transport/tcp/package-info.java
Mon Sep 17 15:27:55 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.
+ */
+
+/**
+ * ???
+ *
+ * @version $Rev$ $Date$
+ */
+package org.apache.geronimo.gshell.remote.transport.tcp;
\ 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/tcp/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/tcp/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/tcp/package-info.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/RshServer.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/RshServer.java?rev=576612&r1=576611&r2=576612&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-server/src/main/java/org/apache/geronimo/gshell/remote/server/RshServer.java
(original)
+++ geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-server/src/main/java/org/apache/geronimo/gshell/remote/server/RshServer.java
Mon Sep 17 15:27:55 2007
@@ -19,22 +19,10 @@
 
 package org.apache.geronimo.gshell.remote.server;
 
-import java.net.InetSocketAddress;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Executors;
-
-import org.apache.geronimo.gshell.remote.message.MessageCodecFactory;
-import org.apache.geronimo.gshell.remote.ssl.BogusSSLContextFactory;
-import org.apache.mina.common.DefaultIoFilterChainBuilder;
-import org.apache.mina.common.IoEventType;
-import org.apache.mina.common.IoHandler;
-import org.apache.mina.filter.codec.ProtocolCodecFilter;
-import org.apache.mina.filter.logging.LoggingFilter;
-import org.apache.mina.filter.ssl.SSLFilter;
-import org.apache.mina.transport.socket.nio.SocketAcceptor;
-import org.codehaus.plexus.component.annotations.Component;
-import org.codehaus.plexus.component.annotations.InstantiationStrategy;
-import org.codehaus.plexus.component.annotations.Requirement;
+import java.net.URI;
+
+import org.apache.geronimo.gshell.remote.transport.TransportFactory;
+import org.apache.geronimo.gshell.remote.transport.TransportServer;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -43,59 +31,22 @@
  *
  * @version $Rev$ $Date$
  */
-@Component(role=RshServer.class, instantiationStrategy=InstantiationStrategy.PER_LOOKUP)
 public class RshServer
 {
-    private Logger log = LoggerFactory.getLogger(getClass());
-
-    @Requirement(role=IoHandler.class, hint="rsh-server")
-    private RshServerProtocolHandler handler;
-
-    private SocketAcceptor acceptor;
-
-    private boolean ssl = true;
-
-    private boolean bound = false;
-
-    public void bind(final int port) throws Exception {
-        if (bound) {
-            throw new IllegalStateException("Already bound");
-        }
-
-        handler.setVisitor(new RshServerMessageVisitor());
-
-        ExecutorService executor = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors()
+ 1);
-
-        acceptor = new SocketAcceptor(Runtime.getRuntime().availableProcessors(), executor);
-        acceptor.setLocalAddress(new InetSocketAddress(port));
-        acceptor.setHandler(handler);
-
-        DefaultIoFilterChainBuilder filterChain = acceptor.getFilterChain();
-
-        LoggingFilter loggingFilter = new LoggingFilter();
-        loggingFilter.setLogLevel(IoEventType.EXCEPTION_CAUGHT, LoggingFilter.WARN);
-        loggingFilter.setLogLevel(IoEventType.WRITE, LoggingFilter.TRACE);
-        loggingFilter.setLogLevel(IoEventType.MESSAGE_RECEIVED, LoggingFilter.TRACE);
-        loggingFilter.setLogLevel(IoEventType.MESSAGE_SENT, LoggingFilter.TRACE);
-        loggingFilter.setLogLevel(IoEventType.SESSION_CLOSED, LoggingFilter.DEBUG);
-        loggingFilter.setLogLevel(IoEventType.SESSION_CREATED, LoggingFilter.DEBUG);
-        loggingFilter.setLogLevel(IoEventType.SESSION_IDLE, LoggingFilter.DEBUG);
-        loggingFilter.setLogLevel(IoEventType.SESSION_OPENED, LoggingFilter.DEBUG);
-        filterChain.addLast("logger", loggingFilter);
+    private final Logger log = LoggerFactory.getLogger(getClass());
 
-        filterChain.addLast("protocol", new ProtocolCodecFilter(new MessageCodecFactory()));
+    private final TransportServer server;
 
-        filterChain.addLast("auth", new AuthenticationFilter());
+    public RshServer(final URI location, final TransportFactory factory) throws Exception
{
+        assert location != null;
+        assert factory != null;
 
-        if (ssl) {
-            SSLFilter sslFilter = new SSLFilter(BogusSSLContextFactory.getInstance(true));
-            filterChain.addFirst("ssl", sslFilter);
-        }
+        server = factory.bind(location);
+    }
 
-        acceptor.bind();
-        
-        log.info("Listening on port: {}", port);
+    public void close() {
+        server.close();
 
-        bound = true;
+        log.debug("Closed");
     }
 }

Modified: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-server/src/main/java/org/apache/geronimo/gshell/remote/server/RshServerCommand.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-server/src/main/java/org/apache/geronimo/gshell/remote/server/RshServerCommand.java?rev=576612&r1=576611&r2=576612&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-server/src/main/java/org/apache/geronimo/gshell/remote/server/RshServerCommand.java
(original)
+++ geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-server/src/main/java/org/apache/geronimo/gshell/remote/server/RshServerCommand.java
Mon Sep 17 15:27:55 2007
@@ -19,6 +19,8 @@
 
 package org.apache.geronimo.gshell.remote.server;
 
+import java.net.URI;
+
 import org.apache.geronimo.gshell.command.CommandSupport;
 import org.apache.geronimo.gshell.command.annotation.CommandComponent;
 import org.codehaus.plexus.component.annotations.Requirement;
@@ -32,13 +34,17 @@
 public class RshServerCommand
     extends CommandSupport
 {
-    private int port = 9999;
-    
     @Requirement
+    private RshServerFactory factory;
+
     private RshServer server;
 
     protected Object doExecute() throws Exception {
-        server.bind(port);
+        URI location = new URI("ssl://localhost:9999");
+
+        server = factory.connect(location);
+
+        io.out.println("Listening on: " + location);
         
         return SUCCESS;
     }

Added: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-server/src/main/java/org/apache/geronimo/gshell/remote/server/RshServerFactory.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/RshServerFactory.java?rev=576612&view=auto
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-server/src/main/java/org/apache/geronimo/gshell/remote/server/RshServerFactory.java
(added)
+++ geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-server/src/main/java/org/apache/geronimo/gshell/remote/server/RshServerFactory.java
Mon Sep 17 15:27:55 2007
@@ -0,0 +1,45 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.geronimo.gshell.remote.server;
+
+import java.net.URI;
+
+import org.apache.geronimo.gshell.remote.transport.TransportFactory;
+import org.apache.geronimo.gshell.remote.transport.TransportFactoryLocator;
+import org.codehaus.plexus.component.annotations.Component;
+import org.codehaus.plexus.component.annotations.Requirement;
+
+/**
+ * ???
+ *
+ * @version $Rev$ $Date$
+ */
+@Component(role=RshServerFactory.class)
+public class RshServerFactory
+{
+    @Requirement
+    private TransportFactoryLocator locator;
+
+    public RshServer connect(final URI location) throws Exception {
+        TransportFactory factory = locator.locate(location);
+
+        return new RshServer(location, factory);
+    }
+}
\ No newline at end of file

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

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

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



Mime
View raw message