You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mina.apache.org by gn...@apache.org on 2014/02/10 13:47:49 UTC

[1/2] git commit: [SSHD-289] IoService instances should reuse the same thread pool

Updated Branches:
  refs/heads/master 1a3aae3e0 -> b9fef4e90


[SSHD-289] IoService instances should reuse the same thread pool

Project: http://git-wip-us.apache.org/repos/asf/mina-sshd/repo
Commit: http://git-wip-us.apache.org/repos/asf/mina-sshd/commit/2a808921
Tree: http://git-wip-us.apache.org/repos/asf/mina-sshd/tree/2a808921
Diff: http://git-wip-us.apache.org/repos/asf/mina-sshd/diff/2a808921

Branch: refs/heads/master
Commit: 2a808921cdc3d17fb8c6a01c735513b89634a7cd
Parents: 1a3aae3
Author: Guillaume Nodet <gn...@apache.org>
Authored: Mon Feb 10 13:11:47 2014 +0100
Committer: Guillaume Nodet <gn...@apache.org>
Committed: Mon Feb 10 13:11:47 2014 +0100

----------------------------------------------------------------------
 .../org.apache.sshd.common.io.IoServiceFactory  |  21 ----
 ...pache.sshd.common.io.IoServiceFactoryFactory |  21 ++++
 .../main/java/org/apache/sshd/SshClient.java    |  19 +++-
 .../main/java/org/apache/sshd/SshServer.java    |  37 ++++---
 .../sshd/common/AbstractFactoryManager.java     |  15 ++-
 .../org/apache/sshd/common/FactoryManager.java  |   1 +
 .../common/forward/DefaultTcpipForwarder.java   |   2 +-
 .../sshd/common/forward/TcpipServerChannel.java |   2 +-
 .../sshd/common/io/DefaultIoServiceFactory.java |  94 -----------------
 .../io/DefaultIoServiceFactoryFactory.java      | 101 +++++++++++++++++++
 .../sshd/common/io/IoAcceptorFactory.java       |  29 ------
 .../apache/sshd/common/io/IoServiceFactory.java |   8 +-
 .../sshd/common/io/IoServiceFactoryFactory.java |  29 ++++++
 .../sshd/common/io/mina/MinaAcceptor.java       |   8 +-
 .../sshd/common/io/mina/MinaConnector.java      |   9 +-
 .../apache/sshd/common/io/mina/MinaService.java |  17 +---
 .../sshd/common/io/mina/MinaServiceFactory.java |  55 +++++++++-
 .../io/mina/MinaServiceFactoryFactory.java      |  36 +++++++
 .../sshd/common/io/nio2/Nio2Acceptor.java       |  15 +--
 .../sshd/common/io/nio2/Nio2Connector.java      |   5 +-
 .../apache/sshd/common/io/nio2/Nio2Service.java |  41 ++------
 .../sshd/common/io/nio2/Nio2ServiceFactory.java |  55 ++++++++--
 .../io/nio2/Nio2ServiceFactoryFactory.java      |  40 ++++++++
 .../apache/sshd/common/io/nio2/Nio2Session.java |   2 -
 .../sshd/server/x11/X11ForwardSupport.java      |   2 +-
 25 files changed, 408 insertions(+), 256 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/2a808921/sshd-core/src/main/filtered-resources/META-INF/services/org.apache.sshd.common.io.IoServiceFactory
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/filtered-resources/META-INF/services/org.apache.sshd.common.io.IoServiceFactory b/sshd-core/src/main/filtered-resources/META-INF/services/org.apache.sshd.common.io.IoServiceFactory
deleted file mode 100644
index d168059..0000000
--- a/sshd-core/src/main/filtered-resources/META-INF/services/org.apache.sshd.common.io.IoServiceFactory
+++ /dev/null
@@ -1,21 +0,0 @@
-##
-## 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.
-##
-
-org.apache.sshd.common.io.nio2.Nio2ServiceFactory
-org.apache.sshd.common.io.mina.MinaServiceFactory

http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/2a808921/sshd-core/src/main/filtered-resources/META-INF/services/org.apache.sshd.common.io.IoServiceFactoryFactory
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/filtered-resources/META-INF/services/org.apache.sshd.common.io.IoServiceFactoryFactory b/sshd-core/src/main/filtered-resources/META-INF/services/org.apache.sshd.common.io.IoServiceFactoryFactory
new file mode 100644
index 0000000..b59ba00
--- /dev/null
+++ b/sshd-core/src/main/filtered-resources/META-INF/services/org.apache.sshd.common.io.IoServiceFactoryFactory
@@ -0,0 +1,21 @@
+##
+## 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.
+##
+
+org.apache.sshd.common.io.nio2.Nio2ServiceFactoryFactory
+org.apache.sshd.common.io.mina.MinaServiceFactoryFactory

http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/2a808921/sshd-core/src/main/java/org/apache/sshd/SshClient.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/SshClient.java b/sshd-core/src/main/java/org/apache/sshd/SshClient.java
index fddc498..3571a12 100644
--- a/sshd-core/src/main/java/org/apache/sshd/SshClient.java
+++ b/sshd-core/src/main/java/org/apache/sshd/SshClient.java
@@ -93,7 +93,7 @@ import org.apache.sshd.common.forward.DefaultTcpipForwarderFactory;
 import org.apache.sshd.common.forward.TcpipServerChannel;
 import org.apache.sshd.common.future.CloseFuture;
 import org.apache.sshd.common.future.SshFutureListener;
-import org.apache.sshd.common.io.DefaultIoServiceFactory;
+import org.apache.sshd.common.io.DefaultIoServiceFactoryFactory;
 import org.apache.sshd.common.io.IoConnectFuture;
 import org.apache.sshd.common.io.IoConnector;
 import org.apache.sshd.common.keyprovider.FileKeyPairProvider;
@@ -110,6 +110,7 @@ import org.apache.sshd.common.session.AbstractSession;
 import org.apache.sshd.common.signature.SignatureDSA;
 import org.apache.sshd.common.signature.SignatureECDSA;
 import org.apache.sshd.common.signature.SignatureRSA;
+import org.apache.sshd.common.util.CloseableUtils;
 import org.apache.sshd.common.util.NoCloseInputStream;
 import org.apache.sshd.common.util.NoCloseOutputStream;
 import org.apache.sshd.common.util.SecurityUtils;
@@ -242,8 +243,8 @@ public class SshClient extends AbstractFactoryManager implements ClientFactoryMa
             factories.add(getAgentFactory().getChannelForwardingFactory());
             setChannelFactories(factories);
         }
-        if (getIoServiceFactory() == null) {
-            setIoServiceFactory(new DefaultIoServiceFactory());
+        if (getIoServiceFactoryFactory() == null) {
+            setIoServiceFactoryFactory(new DefaultIoServiceFactoryFactory());
         }
         if (getServiceFactories() == null) {
             setServiceFactories(Arrays.asList(
@@ -282,10 +283,18 @@ public class SshClient extends AbstractFactoryManager implements ClientFactoryMa
     }
 
     public CloseFuture close(boolean immediately) {
-        CloseFuture future = connector.close(immediately);
+        CloseFuture future;
+        if (connector != null) {
+            future = CloseableUtils.sequential(connector, ioServiceFactory).close(immediately);
+        } else if (ioServiceFactory != null) {
+            future = ioServiceFactory.close(immediately);
+        } else {
+            future = CloseableUtils.closed();
+        }
         future.addListener(new SshFutureListener<CloseFuture>() {
             public void operationComplete(CloseFuture future) {
                 connector = null;
+                ioServiceFactory = null;
                 if (shutdownExecutor && executor != null) {
                     executor.shutdown();
                     executor = null;
@@ -338,7 +347,7 @@ public class SshClient extends AbstractFactoryManager implements ClientFactoryMa
     }
 
     protected IoConnector createConnector() {
-        return getIoServiceFactory().createConnector(this, getSessionFactory());
+        return getIoServiceFactory().createConnector(getSessionFactory());
     }
 
     protected SessionFactory createSessionFactory() {

http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/2a808921/sshd-core/src/main/java/org/apache/sshd/SshServer.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/SshServer.java b/sshd-core/src/main/java/org/apache/sshd/SshServer.java
index d07ee0e..2ecf326 100644
--- a/sshd-core/src/main/java/org/apache/sshd/SshServer.java
+++ b/sshd-core/src/main/java/org/apache/sshd/SshServer.java
@@ -63,7 +63,7 @@ import org.apache.sshd.common.forward.DefaultTcpipForwarderFactory;
 import org.apache.sshd.common.forward.TcpipServerChannel;
 import org.apache.sshd.common.future.CloseFuture;
 import org.apache.sshd.common.future.SshFutureListener;
-import org.apache.sshd.common.io.DefaultIoServiceFactory;
+import org.apache.sshd.common.io.DefaultIoServiceFactoryFactory;
 import org.apache.sshd.common.io.IoAcceptor;
 import org.apache.sshd.common.io.IoServiceFactory;
 import org.apache.sshd.common.io.IoSession;
@@ -300,8 +300,8 @@ public class SshServer extends AbstractFactoryManager implements ServerFactoryMa
         if (getFileSystemFactory() == null) {
             throw new IllegalArgumentException("FileSystemFactory not set");
         }
-        if (getIoServiceFactory() == null) {
-            setIoServiceFactory(new DefaultIoServiceFactory());
+        if (getIoServiceFactoryFactory() == null) {
+            setIoServiceFactoryFactory(new DefaultIoServiceFactoryFactory());
         }
         if (getServiceFactories() == null) {
             setServiceFactories(Arrays.asList(
@@ -368,22 +368,27 @@ public class SshServer extends AbstractFactoryManager implements ServerFactoryMa
         start();
     }
 
-    public CloseFuture close(boolean immediately) {
+    public CloseFuture close(final boolean immediately) {
         stopSessionTimeoutListener();
+        CloseFuture future;
         if (acceptor != null) {
-            CloseFuture future = acceptor.close(immediately);
-            future.addListener(new SshFutureListener<CloseFuture>() {
-                public void operationComplete(CloseFuture future) {
-                    if (shutdownExecutor && executor != null) {
-                        executor.shutdown();
-                        executor = null;
-                    }
-                }
-            });
-            return future;
+            future = CloseableUtils.sequential(acceptor, ioServiceFactory).close(immediately);
+        } else if (ioServiceFactory != null) {
+            future = ioServiceFactory.close(immediately);
         } else {
-            return CloseableUtils.closed();
+            future = CloseableUtils.closed();
         }
+        future.addListener(new SshFutureListener<CloseFuture>() {
+            public void operationComplete(CloseFuture future) {
+                acceptor = null;
+                ioServiceFactory = null;
+                if (shutdownExecutor && executor != null) {
+                    executor.shutdown();
+                    executor = null;
+                }
+            }
+        });
+        return future;
     }
 
     /**
@@ -401,7 +406,7 @@ public class SshServer extends AbstractFactoryManager implements ServerFactoryMa
     }
 
     protected IoAcceptor createAcceptor() {
-        return getIoServiceFactory().createAcceptor(this, getSessionFactory());
+        return getIoServiceFactory().createAcceptor(getSessionFactory());
     }
 
     protected SessionFactory createSessionFactory() {

http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/2a808921/sshd-core/src/main/java/org/apache/sshd/common/AbstractFactoryManager.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/AbstractFactoryManager.java b/sshd-core/src/main/java/org/apache/sshd/common/AbstractFactoryManager.java
index 33c84ce..dc412a7 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/AbstractFactoryManager.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/AbstractFactoryManager.java
@@ -28,6 +28,7 @@ import java.util.concurrent.ScheduledExecutorService;
 import org.apache.sshd.agent.SshAgentFactory;
 import org.apache.sshd.common.file.FileSystemFactory;
 import org.apache.sshd.common.io.IoServiceFactory;
+import org.apache.sshd.common.io.IoServiceFactoryFactory;
 import org.apache.sshd.common.session.ConnectionService;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -42,6 +43,7 @@ public abstract class AbstractFactoryManager implements FactoryManager {
     protected final Logger log = LoggerFactory.getLogger(getClass());
 
     protected Map<String,String> properties = new HashMap<String,String>();
+    protected IoServiceFactoryFactory ioServiceFactoryFactory;
     protected IoServiceFactory ioServiceFactory;
     protected List<NamedFactory<KeyExchange>> keyExchangeFactories;
     protected List<NamedFactory<Cipher>> cipherFactories;
@@ -66,11 +68,20 @@ public abstract class AbstractFactoryManager implements FactoryManager {
     }
 
     public IoServiceFactory getIoServiceFactory() {
+        synchronized (ioServiceFactoryFactory) {
+            if (ioServiceFactory == null) {
+                ioServiceFactory = ioServiceFactoryFactory.create(this);
+            }
+        }
         return ioServiceFactory;
     }
 
-    public void setIoServiceFactory(IoServiceFactory ioServiceFactory) {
-        this.ioServiceFactory = ioServiceFactory;
+    public IoServiceFactoryFactory getIoServiceFactoryFactory() {
+        return ioServiceFactoryFactory;
+    }
+
+    public void setIoServiceFactoryFactory(IoServiceFactoryFactory ioServiceFactory) {
+        this.ioServiceFactoryFactory = ioServiceFactory;
     }
 
     public List<NamedFactory<KeyExchange>> getKeyExchangeFactories() {

http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/2a808921/sshd-core/src/main/java/org/apache/sshd/common/FactoryManager.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/FactoryManager.java b/sshd-core/src/main/java/org/apache/sshd/common/FactoryManager.java
index a06a13f..3025271 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/FactoryManager.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/FactoryManager.java
@@ -25,6 +25,7 @@ import java.util.concurrent.ScheduledExecutorService;
 import org.apache.sshd.agent.SshAgentFactory;
 import org.apache.sshd.common.file.FileSystemFactory;
 import org.apache.sshd.common.io.IoServiceFactory;
+import org.apache.sshd.common.io.IoServiceFactoryFactory;
 import org.apache.sshd.common.session.ConnectionService;
 
 /**

http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/2a808921/sshd-core/src/main/java/org/apache/sshd/common/forward/DefaultTcpipForwarder.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/forward/DefaultTcpipForwarder.java b/sshd-core/src/main/java/org/apache/sshd/common/forward/DefaultTcpipForwarder.java
index 4878f24..16b52d2 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/forward/DefaultTcpipForwarder.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/forward/DefaultTcpipForwarder.java
@@ -154,7 +154,7 @@ public class DefaultTcpipForwarder implements TcpipForwarder, IoHandler {
     public synchronized void initialize() {
         if (this.acceptor == null) {
             this.acceptor = session.getFactoryManager().getIoServiceFactory()
-                    .createAcceptor(session.getFactoryManager(), this);
+                    .createAcceptor(this);
         }
     }
 

http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/2a808921/sshd-core/src/main/java/org/apache/sshd/common/forward/TcpipServerChannel.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/forward/TcpipServerChannel.java b/sshd-core/src/main/java/org/apache/sshd/common/forward/TcpipServerChannel.java
index 1781f66..6709e7e 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/forward/TcpipServerChannel.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/forward/TcpipServerChannel.java
@@ -129,7 +129,7 @@ public class TcpipServerChannel extends AbstractServerChannel {
             }
         };
         connector = getSession().getFactoryManager().getIoServiceFactory()
-                .createConnector(getSession().getFactoryManager(), handler);
+                .createConnector(handler);
         IoConnectFuture future = connector.connect(address.toInetSocketAddress());
         future.addListener(new SshFutureListener<IoConnectFuture>() {
             public void operationComplete(IoConnectFuture future) {

http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/2a808921/sshd-core/src/main/java/org/apache/sshd/common/io/DefaultIoServiceFactory.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/io/DefaultIoServiceFactory.java b/sshd-core/src/main/java/org/apache/sshd/common/io/DefaultIoServiceFactory.java
deleted file mode 100644
index 552d069..0000000
--- a/sshd-core/src/main/java/org/apache/sshd/common/io/DefaultIoServiceFactory.java
+++ /dev/null
@@ -1,94 +0,0 @@
-/*
- * 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.sshd.common.io;
-
-import java.util.Iterator;
-import java.util.ServiceLoader;
-
-import org.apache.sshd.common.FactoryManager;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- */
-public class DefaultIoServiceFactory implements IoServiceFactory {
-
-    private static final Logger LOGGER = LoggerFactory.getLogger(DefaultIoServiceFactory.class);
-
-    public IoConnector createConnector(FactoryManager manager, IoHandler handler) {
-        return newInstance(IoServiceFactory.class).createConnector(manager, handler);
-    }
-
-    public IoAcceptor createAcceptor(FactoryManager manager, IoHandler handler) {
-        return newInstance(IoServiceFactory.class).createAcceptor(manager, handler);
-    }
-
-    private static <T> T newInstance(Class<T> clazz) {
-        String factory = System.getProperty(clazz.getName());
-        if (factory != null) {
-            return newInstance(clazz, factory);
-        }
-        ClassLoader cl = Thread.currentThread().getContextClassLoader();
-        if (cl != null) {
-            T t = tryLoad(ServiceLoader.load(clazz, cl));
-            if (t != null) {
-                return t;
-            }
-        }
-        if (cl != DefaultIoServiceFactory.class.getClassLoader()) {
-            T t = tryLoad(ServiceLoader.load(clazz, DefaultIoServiceFactory.class.getClassLoader()));
-            if (t != null) {
-                return t;
-            }
-        }
-        throw new IllegalStateException("Could not find a valid sshd io provider");
-    }
-
-    private static <T> T tryLoad(ServiceLoader<T> loader) {
-        Iterator<T> it = loader.iterator();
-        while (it.hasNext()) {
-            try {
-                return it.next();
-            } catch (Throwable t) {
-                LOGGER.trace("Exception while loading factory from ServiceLoader", t);
-            }
-        }
-        return null;
-    }
-
-    private static <T> T newInstance(Class<T> clazz, String factory) {
-        ClassLoader cl = Thread.currentThread().getContextClassLoader();
-        if (cl != null) {
-            try {
-                return clazz.cast(cl.loadClass(factory).newInstance());
-            } catch (Throwable t) {
-                LOGGER.trace("Exception while loading factory " + factory, t);
-            }
-        }
-        if (cl != DefaultIoServiceFactory.class.getClassLoader()) {
-            try {
-                return clazz.cast(DefaultIoServiceFactory.class.getClassLoader().loadClass(factory).newInstance());
-            } catch (Throwable t) {
-                LOGGER.trace("Exception while loading factory " + factory, t);
-            }
-        }
-        throw new IllegalStateException("Unable to create instance of class " + factory);
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/2a808921/sshd-core/src/main/java/org/apache/sshd/common/io/DefaultIoServiceFactoryFactory.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/io/DefaultIoServiceFactoryFactory.java b/sshd-core/src/main/java/org/apache/sshd/common/io/DefaultIoServiceFactoryFactory.java
new file mode 100644
index 0000000..6cd410d
--- /dev/null
+++ b/sshd-core/src/main/java/org/apache/sshd/common/io/DefaultIoServiceFactoryFactory.java
@@ -0,0 +1,101 @@
+/*
+ * 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.sshd.common.io;
+
+import java.util.Iterator;
+import java.util.ServiceLoader;
+
+import org.apache.sshd.common.FactoryManager;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ */
+public class DefaultIoServiceFactoryFactory implements IoServiceFactoryFactory {
+
+    private static final Logger LOGGER = LoggerFactory.getLogger(DefaultIoServiceFactoryFactory.class);
+
+    private IoServiceFactoryFactory factory;
+
+    public IoServiceFactory create(FactoryManager manager) {
+        return getFactory().create(manager);
+    }
+
+    private IoServiceFactoryFactory getFactory() {
+        synchronized (this) {
+            if (factory == null) {
+                factory = newInstance(IoServiceFactoryFactory.class);
+            }
+        }
+        return factory;
+    }
+
+    private static <T> T newInstance(Class<T> clazz) {
+        String factory = System.getProperty(clazz.getName());
+        if (factory != null) {
+            return newInstance(clazz, factory);
+        }
+        ClassLoader cl = Thread.currentThread().getContextClassLoader();
+        if (cl != null) {
+            T t = tryLoad(ServiceLoader.load(clazz, cl));
+            if (t != null) {
+                return t;
+            }
+        }
+        if (cl != DefaultIoServiceFactoryFactory.class.getClassLoader()) {
+            T t = tryLoad(ServiceLoader.load(clazz, DefaultIoServiceFactoryFactory.class.getClassLoader()));
+            if (t != null) {
+                return t;
+            }
+        }
+        throw new IllegalStateException("Could not find a valid sshd io provider");
+    }
+
+    private static <T> T tryLoad(ServiceLoader<T> loader) {
+        Iterator<T> it = loader.iterator();
+        while (it.hasNext()) {
+            try {
+                return it.next();
+            } catch (Throwable t) {
+                LOGGER.trace("Exception while loading factory from ServiceLoader", t);
+            }
+        }
+        return null;
+    }
+
+    private static <T> T newInstance(Class<T> clazz, String factory) {
+        ClassLoader cl = Thread.currentThread().getContextClassLoader();
+        if (cl != null) {
+            try {
+                return clazz.cast(cl.loadClass(factory).newInstance());
+            } catch (Throwable t) {
+                LOGGER.trace("Exception while loading factory " + factory, t);
+            }
+        }
+        if (cl != DefaultIoServiceFactoryFactory.class.getClassLoader()) {
+            try {
+                return clazz.cast(DefaultIoServiceFactoryFactory.class.getClassLoader().loadClass(factory).newInstance());
+            } catch (Throwable t) {
+                LOGGER.trace("Exception while loading factory " + factory, t);
+            }
+        }
+        throw new IllegalStateException("Unable to create instance of class " + factory);
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/2a808921/sshd-core/src/main/java/org/apache/sshd/common/io/IoAcceptorFactory.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/io/IoAcceptorFactory.java b/sshd-core/src/main/java/org/apache/sshd/common/io/IoAcceptorFactory.java
deleted file mode 100644
index 86fb54b..0000000
--- a/sshd-core/src/main/java/org/apache/sshd/common/io/IoAcceptorFactory.java
+++ /dev/null
@@ -1,29 +0,0 @@
-/*
- * 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.sshd.common.io;
-
-import org.apache.sshd.common.FactoryManager;
-
-/**
- */
-public interface IoAcceptorFactory {
-
-    IoAcceptor create(FactoryManager manager);
-
-}

http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/2a808921/sshd-core/src/main/java/org/apache/sshd/common/io/IoServiceFactory.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/io/IoServiceFactory.java b/sshd-core/src/main/java/org/apache/sshd/common/io/IoServiceFactory.java
index 5226e8c..ed927ba 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/io/IoServiceFactory.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/io/IoServiceFactory.java
@@ -18,14 +18,14 @@
  */
 package org.apache.sshd.common.io;
 
-import org.apache.sshd.common.FactoryManager;
+import org.apache.sshd.common.Closeable;
 
 /**
  */
-public interface IoServiceFactory {
+public interface IoServiceFactory extends Closeable {
 
-    IoConnector createConnector(FactoryManager manager, IoHandler handler);
+    IoConnector createConnector(IoHandler handler);
 
-    IoAcceptor createAcceptor(FactoryManager manager, IoHandler handler);
+    IoAcceptor createAcceptor(IoHandler handler);
 
 }

http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/2a808921/sshd-core/src/main/java/org/apache/sshd/common/io/IoServiceFactoryFactory.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/io/IoServiceFactoryFactory.java b/sshd-core/src/main/java/org/apache/sshd/common/io/IoServiceFactoryFactory.java
new file mode 100644
index 0000000..120adc0
--- /dev/null
+++ b/sshd-core/src/main/java/org/apache/sshd/common/io/IoServiceFactoryFactory.java
@@ -0,0 +1,29 @@
+/*
+ * 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.sshd.common.io;
+
+import org.apache.sshd.common.FactoryManager;
+
+/**
+ */
+public interface IoServiceFactoryFactory {
+
+    IoServiceFactory create(FactoryManager manager);
+
+}

http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/2a808921/sshd-core/src/main/java/org/apache/sshd/common/io/mina/MinaAcceptor.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/io/mina/MinaAcceptor.java b/sshd-core/src/main/java/org/apache/sshd/common/io/mina/MinaAcceptor.java
index 5127f13..107972e 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/io/mina/MinaAcceptor.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/io/mina/MinaAcceptor.java
@@ -26,8 +26,10 @@ import java.util.Set;
 
 import org.apache.mina.core.service.IoAcceptor;
 import org.apache.mina.core.service.IoHandler;
+import org.apache.mina.core.service.IoProcessor;
 import org.apache.mina.core.service.IoService;
 import org.apache.mina.core.session.IoSessionConfig;
+import org.apache.mina.transport.socket.nio.NioSession;
 import org.apache.mina.transport.socket.nio.NioSocketAcceptor;
 import org.apache.sshd.common.FactoryManager;
 
@@ -41,12 +43,12 @@ public class MinaAcceptor extends MinaService implements org.apache.sshd.common.
     protected boolean reuseAddress = true;
     protected IoSessionConfig sessionConfig;
 
-    public MinaAcceptor(FactoryManager manager, org.apache.sshd.common.io.IoHandler handler) {
-        super(manager, handler);
+    public MinaAcceptor(FactoryManager manager, org.apache.sshd.common.io.IoHandler handler, IoProcessor<NioSession> ioProcessor) {
+        super(manager, handler, ioProcessor);
     }
 
     protected IoAcceptor createAcceptor() {
-        NioSocketAcceptor acceptor = new NioSocketAcceptor(getNioWorkers());
+        NioSocketAcceptor acceptor = new NioSocketAcceptor(ioProcessor);
         acceptor.setCloseOnDeactivation(false);
         acceptor.setReuseAddress(reuseAddress);
         acceptor.setBacklog(backlog);

http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/2a808921/sshd-core/src/main/java/org/apache/sshd/common/io/mina/MinaConnector.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/io/mina/MinaConnector.java b/sshd-core/src/main/java/org/apache/sshd/common/io/mina/MinaConnector.java
index 406fb9d..8181652 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/io/mina/MinaConnector.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/io/mina/MinaConnector.java
@@ -24,7 +24,9 @@ import org.apache.mina.core.future.ConnectFuture;
 import org.apache.mina.core.future.IoFutureListener;
 import org.apache.mina.core.service.IoConnector;
 import org.apache.mina.core.service.IoHandler;
+import org.apache.mina.core.service.IoProcessor;
 import org.apache.mina.core.session.IoSessionConfig;
+import org.apache.mina.transport.socket.nio.NioSession;
 import org.apache.mina.transport.socket.nio.NioSocketConnector;
 import org.apache.sshd.common.FactoryManager;
 import org.apache.sshd.common.future.DefaultSshFuture;
@@ -37,13 +39,12 @@ public class MinaConnector extends MinaService implements org.apache.sshd.common
     protected volatile IoConnector connector;
     protected IoSessionConfig sessionConfig;
 
-    public MinaConnector(FactoryManager manager, org.apache.sshd.common.io.IoHandler handler) {
-        super(manager, handler);
+    public MinaConnector(FactoryManager manager, org.apache.sshd.common.io.IoHandler handler, IoProcessor<NioSession> ioProcessor) {
+        super(manager, handler, ioProcessor);
     }
 
-
     protected IoConnector createConnector() {
-        NioSocketConnector connector = new NioSocketConnector(getNioWorkers());
+        NioSocketConnector connector = new NioSocketConnector(ioProcessor);
         if (sessionConfig != null) {
             connector.getSessionConfig().setAll(sessionConfig);
         }

http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/2a808921/sshd-core/src/main/java/org/apache/sshd/common/io/mina/MinaService.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/io/mina/MinaService.java b/sshd-core/src/main/java/org/apache/sshd/common/io/mina/MinaService.java
index 58016dc..c2bb500 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/io/mina/MinaService.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/io/mina/MinaService.java
@@ -23,9 +23,11 @@ import java.util.Map;
 
 import org.apache.mina.core.buffer.IoBuffer;
 import org.apache.mina.core.service.IoHandler;
+import org.apache.mina.core.service.IoProcessor;
 import org.apache.mina.core.service.IoService;
 import org.apache.mina.core.session.IdleStatus;
 import org.apache.mina.core.session.IoSession;
+import org.apache.mina.transport.socket.nio.NioSession;
 import org.apache.sshd.common.Closeable;
 import org.apache.sshd.common.FactoryManager;
 import org.apache.sshd.common.future.CloseFuture;
@@ -41,21 +43,12 @@ public abstract class MinaService implements org.apache.sshd.common.io.IoService
 
     protected final FactoryManager manager;
     protected final org.apache.sshd.common.io.IoHandler handler;
+    protected final IoProcessor<NioSession> ioProcessor;
 
-    public MinaService(FactoryManager manager, org.apache.sshd.common.io.IoHandler handler) {
+    public MinaService(FactoryManager manager, org.apache.sshd.common.io.IoHandler handler, IoProcessor<NioSession> ioProcessor) {
         this.manager = manager;
         this.handler = handler;
-    }
-
-    public int getNioWorkers() {
-        String nioWorkers = manager.getProperties().get(FactoryManager.NIO_WORKERS);
-        if (nioWorkers != null && nioWorkers.length() > 0) {
-            int nb = Integer.parseInt(nioWorkers);
-            if (nb > 0) {
-                return nb;
-            }
-        }
-        return FactoryManager.DEFAULT_NIO_WORKERS;
+        this.ioProcessor = ioProcessor;
     }
 
     protected abstract IoService getIoService();

http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/2a808921/sshd-core/src/main/java/org/apache/sshd/common/io/mina/MinaServiceFactory.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/io/mina/MinaServiceFactory.java b/sshd-core/src/main/java/org/apache/sshd/common/io/mina/MinaServiceFactory.java
index 2eeb8e7..7e0b87b 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/io/mina/MinaServiceFactory.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/io/mina/MinaServiceFactory.java
@@ -18,22 +18,69 @@
  */
 package org.apache.sshd.common.io.mina;
 
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ThreadPoolExecutor;
+import java.util.concurrent.TimeUnit;
+
+import org.apache.mina.core.service.IoProcessor;
+import org.apache.mina.core.service.SimpleIoProcessorPool;
+import org.apache.mina.transport.socket.nio.NioProcessor;
+import org.apache.mina.transport.socket.nio.NioSession;
 import org.apache.sshd.common.FactoryManager;
+import org.apache.sshd.common.future.CloseFuture;
 import org.apache.sshd.common.io.IoAcceptor;
 import org.apache.sshd.common.io.IoConnector;
 import org.apache.sshd.common.io.IoHandler;
 import org.apache.sshd.common.io.IoServiceFactory;
+import org.apache.sshd.common.util.CloseableUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 /**
  */
 public class MinaServiceFactory implements IoServiceFactory {
 
-    public IoConnector createConnector(FactoryManager manager, IoHandler handler) {
-        return new MinaConnector(manager, handler);
+    private final Logger logger = LoggerFactory.getLogger(MinaServiceFactory.class);
+    private final FactoryManager manager;
+    private final ExecutorService executor;
+    private final IoProcessor<NioSession> ioProcessor;
+
+    public MinaServiceFactory(FactoryManager manager) {
+        this.manager = manager;
+        this.executor = Executors.newCachedThreadPool();
+        // Set a default reject handler
+        ((ThreadPoolExecutor) this.executor).setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
+        this.ioProcessor = new SimpleIoProcessorPool<NioSession>(NioProcessor.class, getNioWorkers());
+    }
+
+    public IoConnector createConnector(IoHandler handler) {
+        return new MinaConnector(manager, handler, ioProcessor);
+    }
+
+    public IoAcceptor createAcceptor(IoHandler handler) {
+        return new MinaAcceptor(manager, handler, ioProcessor);
+    }
+
+    public CloseFuture close(boolean immediately) {
+        try {
+            executor.shutdownNow();
+            executor.awaitTermination(5, TimeUnit.SECONDS);
+        } catch (Exception e) {
+            logger.debug("Exception caught while closing executor", e);
+        }
+        return CloseableUtils.closed();
     }
 
-    public IoAcceptor createAcceptor(FactoryManager manager, IoHandler handler) {
-        return new MinaAcceptor(manager, handler);
+    public int getNioWorkers() {
+        String nioWorkers = manager.getProperties().get(FactoryManager.NIO_WORKERS);
+        if (nioWorkers != null && nioWorkers.length() > 0) {
+            int nb = Integer.parseInt(nioWorkers);
+            if (nb > 0) {
+                return nb;
+            }
+        }
+        return FactoryManager.DEFAULT_NIO_WORKERS;
     }
 
 }

http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/2a808921/sshd-core/src/main/java/org/apache/sshd/common/io/mina/MinaServiceFactoryFactory.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/io/mina/MinaServiceFactoryFactory.java b/sshd-core/src/main/java/org/apache/sshd/common/io/mina/MinaServiceFactoryFactory.java
new file mode 100644
index 0000000..3d5c7a2
--- /dev/null
+++ b/sshd-core/src/main/java/org/apache/sshd/common/io/mina/MinaServiceFactoryFactory.java
@@ -0,0 +1,36 @@
+/*
+ * 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.sshd.common.io.mina;
+
+import org.apache.sshd.common.FactoryManager;
+import org.apache.sshd.common.io.IoServiceFactory;
+import org.apache.sshd.common.io.IoServiceFactoryFactory;
+
+/**
+ */
+public class MinaServiceFactoryFactory implements IoServiceFactoryFactory {
+
+    public MinaServiceFactoryFactory() {
+    }
+
+    public IoServiceFactory create(FactoryManager manager) {
+        return new MinaServiceFactory(manager);
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/2a808921/sshd-core/src/main/java/org/apache/sshd/common/io/nio2/Nio2Acceptor.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/io/nio2/Nio2Acceptor.java b/sshd-core/src/main/java/org/apache/sshd/common/io/nio2/Nio2Acceptor.java
index ecfc10d..599b569 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/io/nio2/Nio2Acceptor.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/io/nio2/Nio2Acceptor.java
@@ -21,6 +21,7 @@ package org.apache.sshd.common.io.nio2;
 import java.io.IOException;
 import java.net.SocketAddress;
 import java.net.StandardSocketOptions;
+import java.nio.channels.AsynchronousChannelGroup;
 import java.nio.channels.AsynchronousServerSocketChannel;
 import java.nio.channels.AsynchronousSocketChannel;
 import java.nio.channels.CompletionHandler;
@@ -30,15 +31,11 @@ import java.util.HashSet;
 import java.util.Map;
 import java.util.Set;
 import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.TimeUnit;
 
-import org.apache.sshd.common.Closeable;
 import org.apache.sshd.common.FactoryManager;
 import org.apache.sshd.common.future.CloseFuture;
 import org.apache.sshd.common.io.IoAcceptor;
 import org.apache.sshd.common.io.IoHandler;
-import org.apache.sshd.common.io.IoSession;
-import org.apache.sshd.common.util.CloseableUtils;
 
 /**
  */
@@ -48,8 +45,8 @@ public class Nio2Acceptor extends Nio2Service implements IoAcceptor {
     private final Map<SocketAddress, AsynchronousServerSocketChannel> unbound;
     private int backlog = 50;
 
-    public Nio2Acceptor(FactoryManager manager, IoHandler handler) {
-        super(manager, handler);
+    public Nio2Acceptor(FactoryManager manager, IoHandler handler, AsynchronousChannelGroup group) {
+        super(manager, handler, group);
         channels = new ConcurrentHashMap<SocketAddress, AsynchronousServerSocketChannel>();
         unbound = new ConcurrentHashMap<SocketAddress, AsynchronousServerSocketChannel>();
     }
@@ -107,12 +104,6 @@ public class Nio2Acceptor extends Nio2Service implements IoAcceptor {
             }
         }
         super.doDispose();
-        try {
-            executor.shutdownNow();
-            executor.awaitTermination(5, TimeUnit.SECONDS);
-        } catch (Exception e) {
-            logger.debug("Exception caught while closing executor", e);
-        }
     }
 
     class AcceptCompletionHandler implements CompletionHandler<AsynchronousSocketChannel, SocketAddress> {

http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/2a808921/sshd-core/src/main/java/org/apache/sshd/common/io/nio2/Nio2Connector.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/io/nio2/Nio2Connector.java b/sshd-core/src/main/java/org/apache/sshd/common/io/nio2/Nio2Connector.java
index 602aac1..25b6404 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/io/nio2/Nio2Connector.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/io/nio2/Nio2Connector.java
@@ -20,6 +20,7 @@ package org.apache.sshd.common.io.nio2;
 
 import java.io.IOException;
 import java.net.SocketAddress;
+import java.nio.channels.AsynchronousChannelGroup;
 import java.nio.channels.AsynchronousSocketChannel;
 import java.nio.channels.CompletionHandler;
 
@@ -34,8 +35,8 @@ import org.apache.sshd.common.io.IoSession;
  */
 public class Nio2Connector extends Nio2Service implements IoConnector {
 
-    public Nio2Connector(FactoryManager manager, IoHandler handler) {
-        super(manager, handler);
+    public Nio2Connector(FactoryManager manager, IoHandler handler, AsynchronousChannelGroup group) {
+        super(manager, handler, group);
     }
 
     public IoConnectFuture connect(SocketAddress address) {

http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/2a808921/sshd-core/src/main/java/org/apache/sshd/common/io/nio2/Nio2Service.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/io/nio2/Nio2Service.java b/sshd-core/src/main/java/org/apache/sshd/common/io/nio2/Nio2Service.java
index 31dc957..1942b28 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/io/nio2/Nio2Service.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/io/nio2/Nio2Service.java
@@ -18,21 +18,15 @@
  */
 package org.apache.sshd.common.io.nio2;
 
-import java.io.IOException;
 import java.nio.channels.AsynchronousChannelGroup;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.List;
 import java.util.Map;
 import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Executors;
-import java.util.concurrent.TimeUnit;
 import java.util.concurrent.atomic.AtomicBoolean;
 
-import org.apache.sshd.common.Closeable;
 import org.apache.sshd.common.FactoryManager;
-import org.apache.sshd.common.RuntimeSshException;
 import org.apache.sshd.common.future.CloseFuture;
 import org.apache.sshd.common.future.SshFutureListener;
 import org.apache.sshd.common.io.IoHandler;
@@ -49,33 +43,16 @@ public abstract class Nio2Service implements IoService {
     protected final Logger logger = LoggerFactory.getLogger(getClass());
     protected final FactoryManager manager;
     protected final IoHandler handler;
-    protected final ExecutorService executor;
-    protected final AsynchronousChannelGroup group;
     protected final Map<Long, IoSession> sessions;
     protected final AtomicBoolean disposing = new AtomicBoolean();
+    protected final AsynchronousChannelGroup group;
 
-    protected Nio2Service(FactoryManager manager, IoHandler handler) {
+    protected Nio2Service(FactoryManager manager, IoHandler handler, AsynchronousChannelGroup group) {
         logger.debug("Creating {}", getClass().getSimpleName());
-        try {
-            this.manager = manager;
-            this.handler = handler;
-            executor = Executors.newFixedThreadPool(getNioWorkers());
-            group = AsynchronousChannelGroup.withThreadPool(executor);
-            sessions = new ConcurrentHashMap<Long, IoSession>();
-        } catch (IOException e) {
-            throw new RuntimeSshException(e);
-        }
-    }
-
-    public int getNioWorkers() {
-        String nioWorkers = manager.getProperties().get(FactoryManager.NIO_WORKERS);
-        if (nioWorkers != null && nioWorkers.length() > 0) {
-            int nb = Integer.parseInt(nioWorkers);
-            if (nb > 0) {
-                return nb;
-            }
-        }
-        return FactoryManager.DEFAULT_NIO_WORKERS;
+        this.manager = manager;
+        this.handler = handler;
+        this.sessions = new ConcurrentHashMap<Long, IoSession>();
+        this.group = group;
     }
 
     public void dispose() {
@@ -87,12 +64,6 @@ public abstract class Nio2Service implements IoService {
     }
 
     protected void doDispose() {
-        try {
-            group.shutdownNow();
-            group.awaitTermination(5, TimeUnit.SECONDS);
-        } catch (Exception e) {
-            logger.debug("Exception caught while closing channel group", e);
-        }
     }
 
     public CloseFuture close(boolean immediately) {

http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/2a808921/sshd-core/src/main/java/org/apache/sshd/common/io/nio2/Nio2ServiceFactory.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/io/nio2/Nio2ServiceFactory.java b/sshd-core/src/main/java/org/apache/sshd/common/io/nio2/Nio2ServiceFactory.java
index 8ba03cc..8867da6 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/io/nio2/Nio2ServiceFactory.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/io/nio2/Nio2ServiceFactory.java
@@ -18,29 +18,68 @@
  */
 package org.apache.sshd.common.io.nio2;
 
-import java.nio.channels.AsynchronousChannel;
+import java.io.IOException;
+import java.nio.channels.AsynchronousChannelGroup;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.TimeUnit;
 
 import org.apache.sshd.common.FactoryManager;
+import org.apache.sshd.common.RuntimeSshException;
+import org.apache.sshd.common.future.CloseFuture;
 import org.apache.sshd.common.io.IoAcceptor;
 import org.apache.sshd.common.io.IoConnector;
 import org.apache.sshd.common.io.IoHandler;
 import org.apache.sshd.common.io.IoServiceFactory;
+import org.apache.sshd.common.util.CloseableUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 /**
  */
 public class Nio2ServiceFactory implements IoServiceFactory {
 
-    public Nio2ServiceFactory() {
-        // Make sure NIO2 is available
-        Class clazz = AsynchronousChannel.class;
+    private final Logger logger = LoggerFactory.getLogger(Nio2ServiceFactory.class);
+    private final FactoryManager manager;
+    private final AsynchronousChannelGroup group;
+
+    public Nio2ServiceFactory(FactoryManager manager) {
+        this.manager = manager;
+        try {
+            ExecutorService executor = Executors.newFixedThreadPool(getNioWorkers());
+            group = AsynchronousChannelGroup.withThreadPool(executor);
+        } catch (IOException e) {
+            throw new RuntimeSshException(e);
+        }
+    }
+
+    public IoConnector createConnector(IoHandler handler) {
+        return new Nio2Connector(manager, handler, group);
+    }
+
+    public IoAcceptor createAcceptor(IoHandler handler) {
+        return new Nio2Acceptor(manager, handler, group);
     }
 
-    public IoConnector createConnector(FactoryManager manager, IoHandler handler) {
-        return new Nio2Connector(manager, handler);
+    public CloseFuture close(boolean immediately) {
+        try {
+            group.shutdownNow();
+            group.awaitTermination(5, TimeUnit.SECONDS);
+        } catch (Exception e) {
+            logger.debug("Exception caught while closing channel group", e);
+        }
+        return CloseableUtils.closed();
     }
 
-    public IoAcceptor createAcceptor(FactoryManager manager, IoHandler handler) {
-        return new Nio2Acceptor(manager, handler);
+    public int getNioWorkers() {
+        String nioWorkers = manager.getProperties().get(FactoryManager.NIO_WORKERS);
+        if (nioWorkers != null && nioWorkers.length() > 0) {
+            int nb = Integer.parseInt(nioWorkers);
+            if (nb > 0) {
+                return nb;
+            }
+        }
+        return FactoryManager.DEFAULT_NIO_WORKERS;
     }
 
 }

http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/2a808921/sshd-core/src/main/java/org/apache/sshd/common/io/nio2/Nio2ServiceFactoryFactory.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/io/nio2/Nio2ServiceFactoryFactory.java b/sshd-core/src/main/java/org/apache/sshd/common/io/nio2/Nio2ServiceFactoryFactory.java
new file mode 100644
index 0000000..354bf7b
--- /dev/null
+++ b/sshd-core/src/main/java/org/apache/sshd/common/io/nio2/Nio2ServiceFactoryFactory.java
@@ -0,0 +1,40 @@
+/*
+ * 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.sshd.common.io.nio2;
+
+import java.nio.channels.AsynchronousChannel;
+
+import org.apache.sshd.common.FactoryManager;
+import org.apache.sshd.common.io.IoServiceFactory;
+import org.apache.sshd.common.io.IoServiceFactoryFactory;
+
+/**
+ */
+public class Nio2ServiceFactoryFactory implements IoServiceFactoryFactory {
+
+    public Nio2ServiceFactoryFactory() {
+        // Make sure NIO2 is available
+        Class clazz = AsynchronousChannel.class;
+    }
+
+    public IoServiceFactory create(FactoryManager manager) {
+        return new Nio2ServiceFactory(manager);
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/2a808921/sshd-core/src/main/java/org/apache/sshd/common/io/nio2/Nio2Session.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/io/nio2/Nio2Session.java b/sshd-core/src/main/java/org/apache/sshd/common/io/nio2/Nio2Session.java
index 73ad803..d1fe7cb 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/io/nio2/Nio2Session.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/io/nio2/Nio2Session.java
@@ -28,11 +28,9 @@ import java.util.HashMap;
 import java.util.Map;
 import java.util.Queue;
 import java.util.concurrent.LinkedTransferQueue;
-import java.util.concurrent.atomic.AtomicBoolean;
 import java.util.concurrent.atomic.AtomicLong;
 import java.util.concurrent.atomic.AtomicReference;
 
-import org.apache.sshd.common.RuntimeSshException;
 import org.apache.sshd.common.future.DefaultSshFuture;
 import org.apache.sshd.common.future.SshFuture;
 import org.apache.sshd.common.io.IoHandler;

http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/2a808921/sshd-core/src/main/java/org/apache/sshd/server/x11/X11ForwardSupport.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/server/x11/X11ForwardSupport.java b/sshd-core/src/main/java/org/apache/sshd/server/x11/X11ForwardSupport.java
index 0f41701..8ab57a2 100644
--- a/sshd-core/src/main/java/org/apache/sshd/server/x11/X11ForwardSupport.java
+++ b/sshd-core/src/main/java/org/apache/sshd/server/x11/X11ForwardSupport.java
@@ -68,7 +68,7 @@ public class X11ForwardSupport implements IoHandler, Closeable {
     public synchronized void initialize() {
         if (this.acceptor == null) {
             this.acceptor = service.getSession().getFactoryManager().getIoServiceFactory()
-                    .createAcceptor(service.getSession().getFactoryManager(), this);
+                    .createAcceptor(this);
         }
     }
 


[2/2] git commit: Remove done todos

Posted by gn...@apache.org.
Remove done todos

Project: http://git-wip-us.apache.org/repos/asf/mina-sshd/repo
Commit: http://git-wip-us.apache.org/repos/asf/mina-sshd/commit/b9fef4e9
Tree: http://git-wip-us.apache.org/repos/asf/mina-sshd/tree/b9fef4e9
Diff: http://git-wip-us.apache.org/repos/asf/mina-sshd/diff/b9fef4e9

Branch: refs/heads/master
Commit: b9fef4e90679c23a456a2eccf0129b1273572869
Parents: 2a80892
Author: Guillaume Nodet <gn...@apache.org>
Authored: Mon Feb 10 13:20:52 2014 +0100
Committer: Guillaume Nodet <gn...@apache.org>
Committed: Mon Feb 10 13:20:52 2014 +0100

----------------------------------------------------------------------
 sshd-core/src/main/java/org/apache/sshd/SshClient.java         | 2 --
 .../java/org/apache/sshd/server/session/ServerSession.java     | 6 ------
 2 files changed, 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/b9fef4e9/sshd-core/src/main/java/org/apache/sshd/SshClient.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/SshClient.java b/sshd-core/src/main/java/org/apache/sshd/SshClient.java
index 3571a12..75eb2ed 100644
--- a/sshd-core/src/main/java/org/apache/sshd/SshClient.java
+++ b/sshd-core/src/main/java/org/apache/sshd/SshClient.java
@@ -559,8 +559,6 @@ public class SshClient extends AbstractFactoryManager implements ClientFactoryMa
             root.setLevel(Level.FINEST);
         }
 
-        // TODO: handle log level
-
         KeyPairProvider provider = null;
         List<String> files = new ArrayList<String>();
         File f = new File(System.getProperty("user.home"), ".ssh/id_dsa");

http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/b9fef4e9/sshd-core/src/main/java/org/apache/sshd/server/session/ServerSession.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/server/session/ServerSession.java b/sshd-core/src/main/java/org/apache/sshd/server/session/ServerSession.java
index d8cda02..7df6994 100644
--- a/sshd-core/src/main/java/org/apache/sshd/server/session/ServerSession.java
+++ b/sshd-core/src/main/java/org/apache/sshd/server/session/ServerSession.java
@@ -31,12 +31,6 @@ import org.apache.sshd.server.ServerFactoryManager;
 
 /**
  *
- * TODO: handle key re-exchange
- *          key re-exchange should be performed after each gigabyte of transferred data
- *          or one hour time connection (see RFC4253, section 9)
- *
- * TODO: better use of SSH_MSG_DISCONNECT and disconnect error codes
- *
  * TODO Add javadoc
  *
  * @author <a href="mailto:dev@mina.apache.org">Apache MINA SSHD Project</a>