You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mina.apache.org by lg...@apache.org on 2018/10/31 05:03:13 UTC

[5/5] mina-sshd git commit: [SSHD-859] Moved read-only access of AttributeStore to AttributeRepository

[SSHD-859] Moved read-only access of AttributeStore to AttributeRepository


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

Branch: refs/heads/master
Commit: ba008331bdb92afb85e3027c006cc3569ddefad2
Parents: 4e12d7e
Author: Lyor Goldstein <lg...@apache.org>
Authored: Tue Oct 30 12:07:29 2018 +0200
Committer: Lyor Goldstein <lg...@apache.org>
Committed: Wed Oct 31 07:02:56 2018 +0200

----------------------------------------------------------------------
 .../apache/sshd/common/AttributeRepository.java | 108 +++++++++++++++++++
 .../org/apache/sshd/common/AttributeStore.java  |  42 +-------
 .../org/apache/sshd/common/FactoryManager.java  |   4 +-
 .../sshd/common/channel/AbstractChannel.java    |  17 ++-
 .../org/apache/sshd/common/channel/Channel.java |   5 +-
 .../common/helpers/AbstractFactoryManager.java  |  18 +++-
 .../org/apache/sshd/common/io/IoService.java    |   1 -
 .../sshd/common/io/nio2/Nio2Acceptor.java       |  16 ++-
 .../sshd/common/io/nio2/Nio2Connector.java      |  23 ++--
 .../apache/sshd/common/io/nio2/Nio2Service.java |  11 +-
 .../apache/sshd/common/io/nio2/Nio2Session.java |  75 ++++++++-----
 .../org/apache/sshd/common/session/Session.java |   5 +-
 .../common/session/helpers/SessionHelper.java   |  18 +++-
 .../pubkey/CachingPublicKeyAuthenticator.java   |   7 +-
 .../apache/sshd/common/AttributeStoreTest.java  |   4 +-
 .../apache/sshd/common/io/mina/MinaService.java |  12 +--
 .../apache/sshd/common/io/mina/MinaSession.java |  28 +++--
 .../org/apache/sshd/netty/NettyIoConnector.java |   1 -
 .../org/apache/sshd/netty/NettyIoService.java   |   3 +-
 .../org/apache/sshd/netty/NettyIoSession.java   |   6 +-
 20 files changed, 267 insertions(+), 137 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/ba008331/sshd-common/src/main/java/org/apache/sshd/common/AttributeRepository.java
----------------------------------------------------------------------
diff --git a/sshd-common/src/main/java/org/apache/sshd/common/AttributeRepository.java b/sshd-common/src/main/java/org/apache/sshd/common/AttributeRepository.java
new file mode 100644
index 0000000..f754e87
--- /dev/null
+++ b/sshd-common/src/main/java/org/apache/sshd/common/AttributeRepository.java
@@ -0,0 +1,108 @@
+/*
+ * 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;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Objects;
+
+import org.apache.sshd.common.util.GenericUtils;
+
+/**
+ * @author <a href="mailto:dev@mina.apache.org">Apache MINA SSHD Project</a>
+ */
+public interface AttributeRepository {
+    /**
+     * <P>
+     * Type safe key for storage of user attributes. Typically it is used as a static
+     * variable that is shared between the producer and the consumer. To further
+     * restrict access the setting or getting it from the store one can add static
+     * {@code get/set methods} e.g:
+     * </P>
+     *
+     * <pre>
+     * public static final AttributeKey&lt;MyValue&gt; MY_KEY = new AttributeKey&lt;MyValue&gt;();
+     *
+     * public static MyValue getMyValue(Session s) {
+     *   return s.getAttribute(MY_KEY);
+     * }
+     *
+     * public static void setMyValue(Session s, MyValue value) {
+     *   s.setAttribute(MY_KEY, value);
+     * }
+     * </pre>
+     *
+     * @param <T> type of value stored in the attribute.
+     * @author <a href="mailto:dev@mina.apache.org">Apache MINA SSHD Project</a>
+     */
+    // CHECKSTYLE:OFF
+    class AttributeKey<T> {
+        public AttributeKey() {
+            super();
+        }
+    }
+    // CHECKSTYLE:ON
+
+    /**
+     * Returns the value of the user-defined attribute.
+     *
+     * @param <T> The generic attribute type
+     * @param key The key of the attribute; must not be {@code null}.
+     * @return {@code null} if there is no value associated with the specified key
+     */
+    <T> T getAttribute(AttributeKey<T> key);
+
+    /**
+     * @return A {@link Collection} <u>snapshot</u> of all the currently registered
+     * attributes in the repository
+     */
+    Collection<AttributeKey<?>> attributeKeys();
+
+    static <A> AttributeRepository ofKeyValuePair(AttributeKey<A> key, A value) {
+        Objects.requireNonNull(key, "No key provided");
+        Objects.requireNonNull(value, "No value provided");
+        return ofAttributesMap(Collections.singletonMap(key, value));
+    }
+
+    static AttributeRepository ofAttributesMap(Map<AttributeKey<?>, ?> attributes) {
+        return new AttributeRepository() {
+            @Override
+            @SuppressWarnings("unchecked")
+            public <T> T getAttribute(AttributeKey<T> key) {
+                Objects.requireNonNull(key, "No key provided");
+                return GenericUtils.isEmpty(attributes) ? null : (T) attributes.get(key);
+            }
+
+            @Override
+            public Collection<AttributeKey<?>> attributeKeys() {
+                return GenericUtils.isEmpty(attributes)
+                     ? Collections.emptySet()
+                     : new HashSet<>(attributes.keySet());
+            }
+
+            @Override
+            public String toString() {
+                return AttributeRepository.class.getSimpleName() + "[" + attributes + "]";
+            }
+        };
+    }
+}

http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/ba008331/sshd-common/src/main/java/org/apache/sshd/common/AttributeStore.java
----------------------------------------------------------------------
diff --git a/sshd-common/src/main/java/org/apache/sshd/common/AttributeStore.java b/sshd-common/src/main/java/org/apache/sshd/common/AttributeStore.java
index feccc11..cc5665a 100644
--- a/sshd-common/src/main/java/org/apache/sshd/common/AttributeStore.java
+++ b/sshd-common/src/main/java/org/apache/sshd/common/AttributeStore.java
@@ -27,47 +27,7 @@ import java.util.function.Function;
  *
  * @author <a href="mailto:dev@mina.apache.org">Apache MINA SSHD Project</a>
  */
-public interface AttributeStore {
-    /**
-     * <P>
-     * Type safe key for storage of user attributes. Typically it is used as a static
-     * variable that is shared between the producer and the consumer. To further
-     * restrict access the setting or getting it from the store one can add static
-     * {@code get/set methods} e.g:
-     * </P>
-     *
-     * <pre>
-     * public static final AttributeKey&lt;MyValue&gt; MY_KEY = new AttributeKey&lt;MyValue&gt;();
-     *
-     * public static MyValue getMyValue(Session s) {
-     *   return s.getAttribute(MY_KEY);
-     * }
-     *
-     * public static void setMyValue(Session s, MyValue value) {
-     *   s.setAttribute(MY_KEY, value);
-     * }
-     * </pre>
-     *
-     * @param <T> type of value stored in the attribute.
-     * @author <a href="mailto:dev@mina.apache.org">Apache MINA SSHD Project</a>
-     */
-    // CHECKSTYLE:OFF
-    class AttributeKey<T> {
-        public AttributeKey() {
-            super();
-        }
-    }
-    // CHECKSTYLE:ON
-
-    /**
-     * Returns the value of the user-defined attribute.
-     *
-     * @param <T> The generic attribute type
-     * @param key The key of the attribute; must not be {@code null}.
-     * @return {@code null} if there is no value associated with the specified key
-     */
-    <T> T getAttribute(AttributeKey<T> key);
-
+public interface AttributeStore extends AttributeRepository {
     /**
      * If the specified key is not already associated with a value (or is mapped
      * to {@code null}), attempts to compute its value using the given mapping

http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/ba008331/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 cc04275..18ee70a 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
@@ -469,7 +469,7 @@ public interface FactoryManager
     List<RequestHandler<ConnectionService>> getGlobalRequestHandlers();
 
     @Override
-    default <T> T resolveAttribute(AttributeKey<T> key) {
+    default <T> T resolveAttribute(AttributeRepository.AttributeKey<T> key) {
         return resolveAttribute(this, key);
     }
 
@@ -479,7 +479,7 @@ public interface FactoryManager
      * @param key The attribute key - never {@code null}
      * @return Associated value - {@code null} if not found
      */
-    static <T> T resolveAttribute(FactoryManager manager, AttributeKey<T> key) {
+    static <T> T resolveAttribute(FactoryManager manager, AttributeRepository.AttributeKey<T> key) {
         Objects.requireNonNull(key, "No key");
         return (manager == null) ? null : manager.getAttribute(key);
     }

http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/ba008331/sshd-core/src/main/java/org/apache/sshd/common/channel/AbstractChannel.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/channel/AbstractChannel.java b/sshd-core/src/main/java/org/apache/sshd/common/channel/AbstractChannel.java
index d213d72..d8918a0 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/channel/AbstractChannel.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/channel/AbstractChannel.java
@@ -23,6 +23,7 @@ import java.io.IOException;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.Date;
+import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
 import java.util.Objects;
@@ -35,6 +36,7 @@ import java.util.concurrent.atomic.AtomicReference;
 import java.util.function.Function;
 import java.util.function.IntUnaryOperator;
 
+import org.apache.sshd.common.AttributeRepository;
 import org.apache.sshd.common.Closeable;
 import org.apache.sshd.common.FactoryManager;
 import org.apache.sshd.common.PropertyResolver;
@@ -107,7 +109,7 @@ public abstract class AbstractChannel
      */
     private final Map<String, Date> pendingRequests = new ConcurrentHashMap<>();
     private final Map<String, Object> properties = new ConcurrentHashMap<>();
-    private final Map<AttributeKey<?>, Object> attributes = new ConcurrentHashMap<>();
+    private final Map<AttributeRepository.AttributeKey<?>, Object> attributes = new ConcurrentHashMap<>();
 
     protected AbstractChannel(boolean client) {
         this("", client);
@@ -949,20 +951,25 @@ public abstract class AbstractChannel
 
     @Override
     @SuppressWarnings("unchecked")
-    public <T> T getAttribute(AttributeKey<T> key) {
+    public <T> T getAttribute(AttributeRepository.AttributeKey<T> key) {
         return (T) attributes.get(Objects.requireNonNull(key, "No key"));
     }
 
     @Override
+    public Collection<AttributeKey<?>> attributeKeys() {
+        return attributes.isEmpty() ? Collections.emptySet() : new HashSet<>(attributes.keySet());
+    }
+
+    @Override
     @SuppressWarnings({ "unchecked", "rawtypes" })
     public <T> T computeAttributeIfAbsent(
-            AttributeKey<T> key, Function<? super AttributeKey<T>, ? extends T> resolver) {
+            AttributeRepository.AttributeKey<T> key, Function<? super AttributeRepository.AttributeKey<T>, ? extends T> resolver) {
         return (T) attributes.computeIfAbsent(Objects.requireNonNull(key, "No key"), (Function) resolver);
     }
 
     @Override
     @SuppressWarnings("unchecked")
-    public <T> T setAttribute(AttributeKey<T> key, T value) {
+    public <T> T setAttribute(AttributeRepository.AttributeKey<T> key, T value) {
         return (T) attributes.put(
             Objects.requireNonNull(key, "No key"),
             Objects.requireNonNull(value, "No value"));
@@ -970,7 +977,7 @@ public abstract class AbstractChannel
 
     @Override
     @SuppressWarnings("unchecked")
-    public <T> T removeAttribute(AttributeKey<T> key) {
+    public <T> T removeAttribute(AttributeRepository.AttributeKey<T> key) {
         return (T) attributes.remove(Objects.requireNonNull(key, "No key"));
     }
 

http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/ba008331/sshd-core/src/main/java/org/apache/sshd/common/channel/Channel.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/channel/Channel.java b/sshd-core/src/main/java/org/apache/sshd/common/channel/Channel.java
index 099c095..258642e 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/channel/Channel.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/channel/Channel.java
@@ -24,6 +24,7 @@ import java.util.List;
 import java.util.Objects;
 
 import org.apache.sshd.client.future.OpenFuture;
+import org.apache.sshd.common.AttributeRepository;
 import org.apache.sshd.common.AttributeStore;
 import org.apache.sshd.common.Closeable;
 import org.apache.sshd.common.PropertyResolver;
@@ -214,7 +215,7 @@ public interface Channel
     void handleOpenFailure(Buffer buffer) throws IOException;
 
     @Override
-    default <T> T resolveAttribute(AttributeKey<T> key) {
+    default <T> T resolveAttribute(AttributeRepository.AttributeKey<T> key) {
         return resolveAttribute(this, key);
     }
 
@@ -228,7 +229,7 @@ public interface Channel
      * @see #getSession()
      * @see Session#resolveAttribute(Session, AttributeKey)
      */
-    static <T> T resolveAttribute(Channel channel, AttributeKey<T> key) {
+    static <T> T resolveAttribute(Channel channel, AttributeRepository.AttributeKey<T> key) {
         Objects.requireNonNull(key, "No key");
         if (channel == null) {
             return null;

http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/ba008331/sshd-core/src/main/java/org/apache/sshd/common/helpers/AbstractFactoryManager.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/helpers/AbstractFactoryManager.java b/sshd-core/src/main/java/org/apache/sshd/common/helpers/AbstractFactoryManager.java
index 7b9a68e..4d717a2 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/helpers/AbstractFactoryManager.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/helpers/AbstractFactoryManager.java
@@ -19,6 +19,8 @@
 package org.apache.sshd.common.helpers;
 
 import java.util.Collection;
+import java.util.Collections;
+import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
 import java.util.Objects;
@@ -30,6 +32,7 @@ import java.util.concurrent.TimeUnit;
 import java.util.function.Function;
 
 import org.apache.sshd.agent.SshAgentFactory;
+import org.apache.sshd.common.AttributeRepository;
 import org.apache.sshd.common.Factory;
 import org.apache.sshd.common.FactoryManager;
 import org.apache.sshd.common.NamedFactory;
@@ -88,7 +91,7 @@ public abstract class AbstractFactoryManager extends AbstractKexFactoryManager i
     protected final PortForwardingEventListener tunnelListenerProxy;
 
     private final Map<String, Object> properties = new ConcurrentHashMap<>();
-    private final Map<AttributeKey<?>, Object> attributes = new ConcurrentHashMap<>();
+    private final Map<AttributeRepository.AttributeKey<?>, Object> attributes = new ConcurrentHashMap<>();
     private PropertyResolver parentResolver = SyspropsMapWrapper.SYSPROPS_RESOLVER;
     private ReservedSessionMessagesHandler reservedSessionMessagesHandler;
     private ChannelStreamPacketWriterResolver channelStreamPacketWriterResolver;
@@ -146,20 +149,25 @@ public abstract class AbstractFactoryManager extends AbstractKexFactoryManager i
 
     @Override
     @SuppressWarnings("unchecked")
-    public <T> T getAttribute(AttributeKey<T> key) {
+    public <T> T getAttribute(AttributeRepository.AttributeKey<T> key) {
         return (T) attributes.get(Objects.requireNonNull(key, "No key"));
     }
 
     @Override
+    public Collection<AttributeKey<?>> attributeKeys() {
+        return attributes.isEmpty() ? Collections.emptySet() : new HashSet<>(attributes.keySet());
+    }
+
+    @Override
     @SuppressWarnings({ "unchecked", "rawtypes" })
     public <T> T computeAttributeIfAbsent(
-            AttributeKey<T> key, Function<? super AttributeKey<T>, ? extends T> resolver) {
+            AttributeRepository.AttributeKey<T> key, Function<? super AttributeRepository.AttributeKey<T>, ? extends T> resolver) {
         return (T) attributes.computeIfAbsent(Objects.requireNonNull(key, "No key"), (Function) resolver);
     }
 
     @Override
     @SuppressWarnings("unchecked")
-    public <T> T setAttribute(AttributeKey<T> key, T value) {
+    public <T> T setAttribute(AttributeRepository.AttributeKey<T> key, T value) {
         return (T) attributes.put(
                 Objects.requireNonNull(key, "No key"),
                 Objects.requireNonNull(value, "No value"));
@@ -167,7 +175,7 @@ public abstract class AbstractFactoryManager extends AbstractKexFactoryManager i
 
     @Override
     @SuppressWarnings("unchecked")
-    public <T> T removeAttribute(AttributeKey<T> key) {
+    public <T> T removeAttribute(AttributeRepository.AttributeKey<T> key) {
         return (T) attributes.remove(Objects.requireNonNull(key, "No key"));
     }
 

http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/ba008331/sshd-core/src/main/java/org/apache/sshd/common/io/IoService.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/io/IoService.java b/sshd-core/src/main/java/org/apache/sshd/common/io/IoService.java
index 453e625..4a8ce58 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/io/IoService.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/io/IoService.java
@@ -40,5 +40,4 @@ public interface IoService extends Closeable, IoServiceEventListenerManager {
      * @return the sessions. An empty collection if there's no session.
      */
     Map<Long, IoSession> getManagedSessions();
-
 }

http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/ba008331/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 0c90ce3..0dcfdb8 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
@@ -74,12 +74,14 @@ public class Nio2Acceptor extends Nio2Service implements IoAcceptor {
     }
 
     protected AsynchronousServerSocketChannel openAsynchronousServerSocketChannel(
-            SocketAddress address, AsynchronousChannelGroup group) throws IOException {
+            SocketAddress address, AsynchronousChannelGroup group)
+                throws IOException {
         return AsynchronousServerSocketChannel.open(group);
     }
 
     protected CompletionHandler<AsynchronousSocketChannel, ? super SocketAddress> createSocketCompletionHandler(
-            Map<SocketAddress, AsynchronousServerSocketChannel> channelsMap, AsynchronousServerSocketChannel socket) throws IOException {
+            Map<SocketAddress, AsynchronousServerSocketChannel> channelsMap, AsynchronousServerSocketChannel socket)
+                throws IOException {
         return new AcceptCompletionHandler(socket);
     }
 
@@ -112,7 +114,7 @@ public class Nio2Acceptor extends Nio2Service implements IoAcceptor {
                     channel.close();
                 } catch (IOException e) {
                     log.warn("unbind({}) {} while unbinding channel: {}",
-                         address, e.getClass().getSimpleName(), e.getMessage());
+                        address, e.getClass().getSimpleName(), e.getMessage());
                     if (debugEnabled) {
                         log.debug("unbind(" + address + ") failure details", e);
                     }
@@ -208,7 +210,9 @@ public class Nio2Acceptor extends Nio2Service implements IoAcceptor {
                 // Create a session
                 IoHandler handler = getIoHandler();
                 setSocketOptions(result);
-                session = Objects.requireNonNull(createSession(Nio2Acceptor.this, address, result, handler), "No NIO2 session created");
+                session = Objects.requireNonNull(
+                    createSession(Nio2Acceptor.this, address, result, handler),
+                    "No NIO2 session created");
                 sessionId = session.getId();
                 handler.sessionCreated(session);
                 sessions.put(sessionId, session);
@@ -264,7 +268,9 @@ public class Nio2Acceptor extends Nio2Service implements IoAcceptor {
             }
         }
 
-        protected Nio2Session createSession(Nio2Acceptor acceptor, SocketAddress address, AsynchronousSocketChannel channel, IoHandler handler) throws Throwable {
+        protected Nio2Session createSession(
+                Nio2Acceptor acceptor, SocketAddress address, AsynchronousSocketChannel channel, IoHandler handler)
+                    throws Throwable {
             if (log.isTraceEnabled()) {
                 log.trace("createNio2Session({}) address={}", acceptor, address);
             }

http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/ba008331/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 061795d..e8410e7 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
@@ -61,15 +61,16 @@ public class Nio2Connector extends Nio2Service implements IoConnector {
                 socket.bind(localAddress);
             }
             Nio2CompletionHandler<Void, Object> completionHandler =
-                ValidateUtils.checkNotNull(createConnectionCompletionHandler(future, socket, getFactoryManager(), getIoHandler()),
-                   "No connection completion handler created for %s",
-                   address);
+                ValidateUtils.checkNotNull(
+                    createConnectionCompletionHandler(future, socket, getFactoryManager(), getIoHandler()),
+                    "No connection completion handler created for %s",
+                    address);
             socket.connect(address, null, completionHandler);
         } catch (Throwable exc) {
             Throwable t = GenericUtils.peelException(exc);
             if (debugEnabled) {
                 log.debug("connect({}) failed ({}) to schedule connection: {}",
-                          address, t.getClass().getSimpleName(), t.getMessage());
+                    address, t.getClass().getSimpleName(), t.getMessage());
             }
             if (log.isTraceEnabled()) {
                 log.trace("connect(" + address + ") connection failure details", t);
@@ -82,7 +83,7 @@ public class Nio2Connector extends Nio2Service implements IoConnector {
             } catch (IOException err) {
                 if (debugEnabled) {
                     log.debug("connect({}) - failed ({}) to close socket: {}",
-                            address, err.getClass().getSimpleName(), err.getMessage());
+                        address, err.getClass().getSimpleName(), err.getMessage());
                 }
             }
 
@@ -93,7 +94,7 @@ public class Nio2Connector extends Nio2Service implements IoConnector {
             } catch (IOException err) {
                 if (debugEnabled) {
                     log.debug("connect({}) - failed ({}) to close channel: {}",
-                            address, err.getClass().getSimpleName(), err.getMessage());
+                        address, err.getClass().getSimpleName(), err.getMessage());
                 }
             }
 
@@ -170,7 +171,8 @@ public class Nio2Connector extends Nio2Service implements IoConnector {
                 }
 
                 if (debugEnabled) {
-                    log.debug("onCompleted - failed {} to start session: {}", t.getClass().getSimpleName(), t.getMessage());
+                    log.debug("onCompleted - failed {} to start session: {}",
+                        t.getClass().getSimpleName(), t.getMessage());
                 }
                 if (log.isTraceEnabled()) {
                     log.trace("onCompleted - session creation failure details", t);
@@ -180,7 +182,8 @@ public class Nio2Connector extends Nio2Service implements IoConnector {
                     socket.close();
                 } catch (IOException err) {
                     if (debugEnabled) {
-                        log.debug("onCompleted - failed {} to close socket: {}", err.getClass().getSimpleName(), err.getMessage());
+                        log.debug("onCompleted - failed {} to close socket: {}",
+                            err.getClass().getSimpleName(), err.getMessage());
                     }
                 }
 
@@ -195,7 +198,9 @@ public class Nio2Connector extends Nio2Service implements IoConnector {
         }
     }
 
-    protected Nio2Session createSession(FactoryManager manager, IoHandler handler, AsynchronousSocketChannel socket) throws Throwable {
+    protected Nio2Session createSession(
+            FactoryManager manager, IoHandler handler, AsynchronousSocketChannel socket)
+                throws Throwable {
         return new Nio2Session(this, manager, handler, socket);
     }
 

http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/ba008331/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 b340ec8..066df84 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
@@ -115,7 +115,8 @@ public abstract class Nio2Service extends AbstractInnerCloseable implements IoSe
             }
         } catch (IOException e) {
             if (log.isDebugEnabled()) {
-                log.debug("dispose({}) {} while stopping service: {}", this, e.getClass().getSimpleName(), e.getMessage());
+                log.debug("dispose({}) {} while stopping service: {}",
+                    this, e.getClass().getSimpleName(), e.getMessage());
             }
 
             if (log.isTraceEnabled()) {
@@ -126,7 +127,9 @@ public abstract class Nio2Service extends AbstractInnerCloseable implements IoSe
 
     @Override
     protected Closeable getInnerCloseable() {
-        return builder().parallel(toString(), sessions.values()).build();
+        return builder()
+            .parallel(toString(), sessions.values())
+            .build();
     }
 
     @Override
@@ -165,7 +168,9 @@ public abstract class Nio2Service extends AbstractInnerCloseable implements IoSe
         return socket;
     }
 
-    protected <T> boolean setOption(NetworkChannel socket, String property, SocketOption<T> option, T defaultValue) throws IOException {
+    protected <T> boolean setOption(
+            NetworkChannel socket, String property, SocketOption<T> option, T defaultValue)
+                throws IOException {
         PropertyResolver manager = getFactoryManager();
         String valStr = manager.getString(property);
         T val = defaultValue;

http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/ba008331/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 9a9ef4a..a49e132 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
@@ -64,7 +64,8 @@ public class Nio2Session extends AbstractCloseable implements IoSession {
     private final Queue<Nio2DefaultIoWriteFuture> writes = new LinkedTransferQueue<>();
     private final AtomicReference<Nio2DefaultIoWriteFuture> currentWrite = new AtomicReference<>();
 
-    public Nio2Session(Nio2Service service, FactoryManager manager, IoHandler handler, AsynchronousSocketChannel socket) throws IOException {
+    public Nio2Session(Nio2Service service, FactoryManager manager, IoHandler handler, AsynchronousSocketChannel socket)
+            throws IOException {
         this.service = Objects.requireNonNull(service, "No service instance");
         this.manager = Objects.requireNonNull(manager, "No factory manager");
         this.ioHandler = Objects.requireNonNull(handler, "No IoHandler");
@@ -135,7 +136,7 @@ public class Nio2Session extends AbstractCloseable implements IoSession {
         } catch (IOException e) {
             if (debugEnabled) {
                 log.debug("suspend({}) failed {{}) to shutdown input: {}",
-                          this, e.getClass().getSimpleName(), e.getMessage());
+                    this, e.getClass().getSimpleName(), e.getMessage());
             }
         }
 
@@ -144,7 +145,7 @@ public class Nio2Session extends AbstractCloseable implements IoSession {
         } catch (IOException e) {
             if (debugEnabled) {
                 log.debug("suspend({}) failed {{}) to shutdown output: {}",
-                          this, e.getClass().getSimpleName(), e.getMessage());
+                    this, e.getClass().getSimpleName(), e.getMessage());
             }
         }
     }
@@ -156,7 +157,8 @@ public class Nio2Session extends AbstractCloseable implements IoSession {
         }
 
         ByteBuffer buf = ByteBuffer.wrap(buffer.array(), buffer.rpos(), buffer.available());
-        Nio2DefaultIoWriteFuture future = new Nio2DefaultIoWriteFuture(getRemoteAddress(), null, buf);
+        Nio2DefaultIoWriteFuture future =
+            new Nio2DefaultIoWriteFuture(getRemoteAddress(), null, buf);
         if (isClosing()) {
             Throwable exc = new ClosedChannelException();
             future.setException(exc);
@@ -179,14 +181,14 @@ public class Nio2Session extends AbstractCloseable implements IoSession {
             try {
                 if (log.isDebugEnabled()) {
                     log.debug("exceptionCaught({}) caught {}[{}] - calling handler",
-                              this, exc.getClass().getSimpleName(), exc.getMessage());
+                        this, exc.getClass().getSimpleName(), exc.getMessage());
                 }
                 handler.exceptionCaught(this, exc);
             } catch (Throwable e) {
                 Throwable t = GenericUtils.peelException(e);
                 if (log.isDebugEnabled()) {
                     log.debug("exceptionCaught({}) Exception handler threw {}, closing the session: {}",
-                              this, t.getClass().getSimpleName(), t.getMessage());
+                        this, t.getClass().getSimpleName(), t.getMessage());
                 }
 
                 if (log.isTraceEnabled()) {
@@ -201,15 +203,18 @@ public class Nio2Session extends AbstractCloseable implements IoSession {
     @Override
     protected CloseFuture doCloseGracefully() {
         Object closeId = toString();
-        return builder().when(closeId, writes).run(closeId, () -> {
-            try {
-                AsynchronousSocketChannel socket = getSocket();
-                socket.shutdownOutput();
-            } catch (IOException e) {
-                log.info("doCloseGracefully({}) {} while shutting down output: {}",
-                         this, e.getClass().getSimpleName(), e.getMessage());
-            }
-        }).build().close(false);
+        return builder()
+            .when(closeId, writes)
+            .run(closeId, () -> {
+                try {
+                    AsynchronousSocketChannel socket = getSocket();
+                    socket.shutdownOutput();
+                } catch (IOException e) {
+                    log.info("doCloseGracefully({}) {} while shutting down output: {}",
+                        this, e.getClass().getSimpleName(), e.getMessage());
+                }
+            }).build()
+            .close(false);
     }
 
     @Override
@@ -231,7 +236,8 @@ public class Nio2Session extends AbstractCloseable implements IoSession {
                     if (debugEnabled) {
                         log.debug("doCloseImmediately({}) signal write abort for future={}", this, future);
                     }
-                    future.setException(new WriteAbortedException("Write request aborted due to immediate session close", null));
+                    future.setException(
+                        new WriteAbortedException("Write request aborted due to immediate session close", null));
                 }
             } else {
                 break;
@@ -252,7 +258,7 @@ public class Nio2Session extends AbstractCloseable implements IoSession {
 
         } catch (IOException e) {
             log.info("doCloseImmediately({}) {} caught while closing socket={}: {}",
-                    this, e.getClass().getSimpleName(), socket, e.getMessage());
+                this, e.getClass().getSimpleName(), socket, e.getMessage());
             if (debugEnabled) {
                 log.debug("doCloseImmediately(" + this + ") socket=" + socket + " close failure details", e);
             }
@@ -267,7 +273,7 @@ public class Nio2Session extends AbstractCloseable implements IoSession {
         } catch (Throwable e) {
             if (debugEnabled) {
                 log.debug("doCloseImmediately({}) {} while calling IoHandler#sessionClosed: {}",
-                          this, e.getClass().getSimpleName(), e.getMessage());
+                    this, e.getClass().getSimpleName(), e.getMessage());
             }
 
             if (log.isTraceEnabled()) {
@@ -307,11 +313,14 @@ public class Nio2Session extends AbstractCloseable implements IoSession {
 
     protected void doReadCycle(ByteBuffer buffer, Readable bufReader) {
         Nio2CompletionHandler<Integer, Object> completion =
-                Objects.requireNonNull(createReadCycleCompletionHandler(buffer, bufReader), "No completion handler created");
+            Objects.requireNonNull(
+                createReadCycleCompletionHandler(buffer, bufReader),
+                "No completion handler created");
         doReadCycle(buffer, completion);
     }
 
-    protected Nio2CompletionHandler<Integer, Object> createReadCycleCompletionHandler(ByteBuffer buffer, Readable bufReader) {
+    protected Nio2CompletionHandler<Integer, Object> createReadCycleCompletionHandler(
+            ByteBuffer buffer, Readable bufReader) {
         return new Nio2CompletionHandler<Integer, Object>() {
             @Override
             protected void onCompleted(Integer result, Object attachment) {
@@ -326,7 +335,8 @@ public class Nio2Session extends AbstractCloseable implements IoSession {
     }
 
     protected void handleReadCycleCompletion(
-            ByteBuffer buffer, Readable bufReader, Nio2CompletionHandler<Integer, Object> completionHandler, Integer result, Object attachment) {
+            ByteBuffer buffer, Readable bufReader, Nio2CompletionHandler<Integer, Object> completionHandler,
+            Integer result, Object attachment) {
         try {
             boolean debugEnabled = log.isDebugEnabled();
             if (result >= 0) {
@@ -348,7 +358,8 @@ public class Nio2Session extends AbstractCloseable implements IoSession {
                 }
             } else {
                 if (debugEnabled) {
-                    log.debug("handleReadCycleCompletion({}) Socket has been disconnected (result={}), closing IoSession now", this, result);
+                    log.debug("handleReadCycleCompletion({}) Socket has been disconnected (result={}), closing IoSession now",
+                        this, result);
                 }
                 close(true);
             }
@@ -363,7 +374,8 @@ public class Nio2Session extends AbstractCloseable implements IoSession {
 
     protected void doReadCycle(ByteBuffer buffer, Nio2CompletionHandler<Integer, Object> completion) {
         AsynchronousSocketChannel socket = getSocket();
-        long readTimeout = manager.getLongProperty(FactoryManager.NIO2_READ_TIMEOUT, FactoryManager.DEFAULT_NIO2_READ_TIMEOUT);
+        long readTimeout = manager.getLongProperty(
+            FactoryManager.NIO2_READ_TIMEOUT, FactoryManager.DEFAULT_NIO2_READ_TIMEOUT);
         socket.read(buffer, readTimeout, TimeUnit.MILLISECONDS, null, completion);
     }
 
@@ -381,8 +393,9 @@ public class Nio2Session extends AbstractCloseable implements IoSession {
             AsynchronousSocketChannel socket = getSocket();
             ByteBuffer buffer = future.getBuffer();
             Nio2CompletionHandler<Integer, Object> handler =
-                    Objects.requireNonNull(createWriteCycleCompletionHandler(future, socket, buffer),
-                                               "No write cycle completion handler created");
+                Objects.requireNonNull(
+                    createWriteCycleCompletionHandler(future, socket, buffer),
+                    "No write cycle completion handler created");
             doWriteCycle(buffer, handler);
         } catch (Throwable e) {
             future.setWritten();
@@ -397,7 +410,8 @@ public class Nio2Session extends AbstractCloseable implements IoSession {
 
     protected void doWriteCycle(ByteBuffer buffer, Nio2CompletionHandler<Integer, Object> completion) {
         AsynchronousSocketChannel socket = getSocket();
-        long writeTimeout = manager.getLongProperty(FactoryManager.NIO2_MIN_WRITE_TIMEOUT, FactoryManager.DEFAULT_NIO2_MIN_WRITE_TIMEOUT);
+        long writeTimeout = manager.getLongProperty(
+            FactoryManager.NIO2_MIN_WRITE_TIMEOUT, FactoryManager.DEFAULT_NIO2_MIN_WRITE_TIMEOUT);
         socket.write(buffer, writeTimeout, TimeUnit.MILLISECONDS, null, completion);
     }
 
@@ -449,7 +463,7 @@ public class Nio2Session extends AbstractCloseable implements IoSession {
             ByteBuffer buffer, int writeLen, Throwable exc, Object attachment) {
         if (log.isDebugEnabled()) {
             log.debug("handleWriteCycleFailure({}) failed ({}) to write {} bytes: {}",
-                      this, exc.getClass().getSimpleName(), writeLen, exc.getMessage());
+                this, exc.getClass().getSimpleName(), writeLen, exc.getMessage());
         }
 
         boolean traceEnabled = log.isTraceEnabled();
@@ -465,7 +479,7 @@ public class Nio2Session extends AbstractCloseable implements IoSession {
         } catch (RuntimeException e) {
             if (traceEnabled) {
                 log.trace("handleWriteCycleFailure({}) failed ({}) to finish writing: {}",
-                        this, e.getClass().getSimpleName(), e.getMessage());
+                    this, e.getClass().getSimpleName(), e.getMessage());
             }
         }
     }
@@ -478,6 +492,9 @@ public class Nio2Session extends AbstractCloseable implements IoSession {
 
     @Override
     public String toString() {
-        return getClass().getSimpleName() + "[local=" + getLocalAddress() + ", remote=" + getRemoteAddress() + "]";
+        return getClass().getSimpleName()
+            + "[local=" + getLocalAddress()
+            + ", remote=" + getRemoteAddress()
+            + "]";
     }
 }

http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/ba008331/sshd-core/src/main/java/org/apache/sshd/common/session/Session.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/session/Session.java b/sshd-core/src/main/java/org/apache/sshd/common/session/Session.java
index 6886a39..06516da 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/session/Session.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/session/Session.java
@@ -22,6 +22,7 @@ import java.io.IOException;
 import java.util.Objects;
 import java.util.concurrent.TimeUnit;
 
+import org.apache.sshd.common.AttributeRepository;
 import org.apache.sshd.common.AttributeStore;
 import org.apache.sshd.common.Closeable;
 import org.apache.sshd.common.FactoryManager;
@@ -345,7 +346,7 @@ public interface Session
     void startService(String name) throws Exception;
 
     @Override
-    default <T> T resolveAttribute(AttributeKey<T> key) {
+    default <T> T resolveAttribute(AttributeRepository.AttributeKey<T> key) {
         return resolveAttribute(this, key);
     }
 
@@ -369,7 +370,7 @@ public interface Session
      * @see Session#getFactoryManager()
      * @see FactoryManager#resolveAttribute(FactoryManager, AttributeKey)
      */
-    static <T> T resolveAttribute(Session session, AttributeKey<T> key) {
+    static <T> T resolveAttribute(Session session, AttributeRepository.AttributeKey<T> key) {
         Objects.requireNonNull(key, "No key");
         if (session == null) {
             return null;

http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/ba008331/sshd-core/src/main/java/org/apache/sshd/common/session/helpers/SessionHelper.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/session/helpers/SessionHelper.java b/sshd-core/src/main/java/org/apache/sshd/common/session/helpers/SessionHelper.java
index f4d4f30..c02c039 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/session/helpers/SessionHelper.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/session/helpers/SessionHelper.java
@@ -23,8 +23,10 @@ import java.net.SocketAddress;
 import java.nio.charset.StandardCharsets;
 import java.util.AbstractMap.SimpleImmutableEntry;
 import java.util.ArrayList;
+import java.util.Collection;
 import java.util.Collections;
 import java.util.EnumMap;
+import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
 import java.util.NavigableSet;
@@ -37,6 +39,7 @@ import java.util.concurrent.TimeoutException;
 import java.util.concurrent.atomic.AtomicReference;
 import java.util.function.Function;
 
+import org.apache.sshd.common.AttributeRepository;
 import org.apache.sshd.common.FactoryManager;
 import org.apache.sshd.common.NamedResource;
 import org.apache.sshd.common.PropertyResolver;
@@ -86,7 +89,7 @@ public abstract class SessionHelper extends AbstractKexFactoryManager implements
     /**
      * Session specific attributes
      */
-    private final Map<AttributeKey<?>, Object> attributes = new ConcurrentHashMap<>();
+    private final Map<AttributeRepository.AttributeKey<?>, Object> attributes = new ConcurrentHashMap<>();
 
     // Session timeout measurements
     private long authTimeoutStart = System.currentTimeMillis();
@@ -145,20 +148,25 @@ public abstract class SessionHelper extends AbstractKexFactoryManager implements
 
     @Override
     @SuppressWarnings("unchecked")
-    public <T> T getAttribute(AttributeKey<T> key) {
+    public <T> T getAttribute(AttributeRepository.AttributeKey<T> key) {
         return (T) attributes.get(Objects.requireNonNull(key, "No key"));
     }
 
     @Override
+    public Collection<AttributeKey<?>> attributeKeys() {
+        return attributes.isEmpty() ? Collections.emptySet() : new HashSet<>(attributes.keySet());
+    }
+
+    @Override
     @SuppressWarnings({ "unchecked", "rawtypes" })
     public <T> T computeAttributeIfAbsent(
-            AttributeKey<T> key, Function<? super AttributeKey<T>, ? extends T> resolver) {
+            AttributeRepository.AttributeKey<T> key, Function<? super AttributeRepository.AttributeKey<T>, ? extends T> resolver) {
         return (T) attributes.computeIfAbsent(Objects.requireNonNull(key, "No key"), (Function) resolver);
     }
 
     @Override
     @SuppressWarnings("unchecked")
-    public <T> T setAttribute(AttributeKey<T> key, T value) {
+    public <T> T setAttribute(AttributeRepository.AttributeKey<T> key, T value) {
         return (T) attributes.put(
             Objects.requireNonNull(key, "No key"),
             Objects.requireNonNull(value, "No value"));
@@ -166,7 +174,7 @@ public abstract class SessionHelper extends AbstractKexFactoryManager implements
 
     @Override
     @SuppressWarnings("unchecked")
-    public <T> T removeAttribute(AttributeKey<T> key) {
+    public <T> T removeAttribute(AttributeRepository.AttributeKey<T> key) {
         return (T) attributes.remove(Objects.requireNonNull(key, "No key"));
     }
 

http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/ba008331/sshd-core/src/main/java/org/apache/sshd/server/auth/pubkey/CachingPublicKeyAuthenticator.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/server/auth/pubkey/CachingPublicKeyAuthenticator.java b/sshd-core/src/main/java/org/apache/sshd/server/auth/pubkey/CachingPublicKeyAuthenticator.java
index 411a579..79cac90 100644
--- a/sshd-core/src/main/java/org/apache/sshd/server/auth/pubkey/CachingPublicKeyAuthenticator.java
+++ b/sshd-core/src/main/java/org/apache/sshd/server/auth/pubkey/CachingPublicKeyAuthenticator.java
@@ -23,7 +23,8 @@ import java.util.Map;
 import java.util.Objects;
 import java.util.concurrent.ConcurrentHashMap;
 
-import org.apache.sshd.common.AttributeStore.AttributeKey;
+import org.apache.sshd.common.AttributeRepository;
+import org.apache.sshd.common.AttributeRepository.AttributeKey;
 import org.apache.sshd.common.RuntimeSshException;
 import org.apache.sshd.common.config.keys.KeyUtils;
 import org.apache.sshd.common.util.logging.AbstractLoggingBean;
@@ -37,9 +38,9 @@ import org.apache.sshd.server.session.ServerSession;
  */
 public class CachingPublicKeyAuthenticator extends AbstractLoggingBean implements PublickeyAuthenticator {
     /**
-     * The {@link AttributeKey} used to store the cached authentication results on the session instance
+     * The {@link AttributeRepository.AttributeKey} used to store the cached authentication results on the session instance
      */
-    public static final AttributeKey<Map<PublicKey, Boolean>> CACHE_ATTRIBUTE = new AttributeKey<>();
+    public static final AttributeRepository.AttributeKey<Map<PublicKey, Boolean>> CACHE_ATTRIBUTE = new AttributeRepository.AttributeKey<>();
 
     protected final PublickeyAuthenticator authenticator;
 

http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/ba008331/sshd-core/src/test/java/org/apache/sshd/common/AttributeStoreTest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/common/AttributeStoreTest.java b/sshd-core/src/test/java/org/apache/sshd/common/AttributeStoreTest.java
index e19265e..741045e 100644
--- a/sshd-core/src/test/java/org/apache/sshd/common/AttributeStoreTest.java
+++ b/sshd-core/src/test/java/org/apache/sshd/common/AttributeStoreTest.java
@@ -21,7 +21,7 @@ package org.apache.sshd.common;
 
 import java.util.concurrent.atomic.AtomicInteger;
 
-import org.apache.sshd.common.AttributeStore.AttributeKey;
+import org.apache.sshd.common.AttributeRepository.AttributeKey;
 import org.apache.sshd.common.channel.Channel;
 import org.apache.sshd.common.session.Session;
 import org.apache.sshd.util.test.BaseTestSupport;
@@ -39,7 +39,7 @@ import org.mockito.Mockito;
 @FixMethodOrder(MethodSorters.NAME_ASCENDING)
 @Category({ NoIoTestCase.class })
 public class AttributeStoreTest extends BaseTestSupport {
-    private static final AttributeKey<String> KEY = new AttributeKey<>();
+    private static final AttributeRepository.AttributeKey<String> KEY = new AttributeRepository.AttributeKey<>();
 
     public AttributeStoreTest() {
         super();

http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/ba008331/sshd-mina/src/main/java/org/apache/sshd/common/io/mina/MinaService.java
----------------------------------------------------------------------
diff --git a/sshd-mina/src/main/java/org/apache/sshd/common/io/mina/MinaService.java b/sshd-mina/src/main/java/org/apache/sshd/common/io/mina/MinaService.java
index b6edacf..7139a5e 100644
--- a/sshd-mina/src/main/java/org/apache/sshd/common/io/mina/MinaService.java
+++ b/sshd-mina/src/main/java/org/apache/sshd/common/io/mina/MinaService.java
@@ -18,10 +18,9 @@
  */
 package org.apache.sshd.common.io.mina;
 
-import java.util.Comparator;
+import java.util.HashMap;
 import java.util.Map;
 import java.util.Objects;
-import java.util.TreeMap;
 
 import org.apache.mina.core.RuntimeIoException;
 import org.apache.mina.core.buffer.IoBuffer;
@@ -87,8 +86,8 @@ public abstract class MinaService extends AbstractCloseable implements org.apach
     public Map<Long, org.apache.sshd.common.io.IoSession> getManagedSessions() {
         IoService ioService = getIoService();
         Map<Long, IoSession> managedMap = ioService.getManagedSessions();
-        Map<Long, IoSession> mina = new TreeMap<>(managedMap);
-        Map<Long, org.apache.sshd.common.io.IoSession> sessions = new TreeMap<>(Comparator.naturalOrder());
+        Map<Long, IoSession> mina = new HashMap<>(managedMap);
+        Map<Long, org.apache.sshd.common.io.IoSession> sessions = new HashMap<>(mina.size());
         for (Long id : mina.keySet()) {
             // Avoid possible NPE if the MinaSession hasn't been created yet
             IoSession minaSession = mina.get(id);
@@ -209,10 +208,11 @@ public abstract class MinaService extends AbstractCloseable implements org.apach
         }
     }
 
-    protected void handleConfigurationError(SocketSessionConfig config, String propName, Object propValue, RuntimeIoException t) {
+    protected void handleConfigurationError(
+            SocketSessionConfig config, String propName, Object propValue, RuntimeIoException t) {
         Throwable e = GenericUtils.resolveExceptionCause(t);
         log.warn("handleConfigurationError({}={}) failed ({}) to configure: {}",
-                 propName, propValue, e.getClass().getSimpleName(), e.getMessage());
+            propName, propValue, e.getClass().getSimpleName(), e.getMessage());
     }
 
     protected Integer getInteger(String property) {

http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/ba008331/sshd-mina/src/main/java/org/apache/sshd/common/io/mina/MinaSession.java
----------------------------------------------------------------------
diff --git a/sshd-mina/src/main/java/org/apache/sshd/common/io/mina/MinaSession.java b/sshd-mina/src/main/java/org/apache/sshd/common/io/mina/MinaSession.java
index 8a8ba07..0fa11db 100644
--- a/sshd-mina/src/main/java/org/apache/sshd/common/io/mina/MinaSession.java
+++ b/sshd-mina/src/main/java/org/apache/sshd/common/io/mina/MinaSession.java
@@ -99,7 +99,8 @@ public class MinaSession extends AbstractInnerCloseable implements IoSession {
     protected Closeable getInnerCloseable() {
         return new IoBaseCloseable() {
             @SuppressWarnings("synthetic-access")
-            private final DefaultCloseFuture future = new DefaultCloseFuture(MinaSession.this.toString(), lock);
+            private final DefaultCloseFuture future =
+                new DefaultCloseFuture(MinaSession.this.toString(), lock);
 
             @SuppressWarnings("synthetic-access")
             @Override
@@ -126,7 +127,8 @@ public class MinaSession extends AbstractInnerCloseable implements IoSession {
             @SuppressWarnings("synthetic-access")
             @Override
             public org.apache.sshd.common.future.CloseFuture close(boolean immediately) {
-                org.apache.mina.core.future.CloseFuture cf = immediately ? session.closeNow() : session.closeOnFlush();
+                org.apache.mina.core.future.CloseFuture cf =
+                    immediately ? session.closeNow() : session.closeOnFlush();
                 cf.addListener(f -> future.setValue(Boolean.TRUE));
                 return future;
             }
@@ -151,14 +153,15 @@ public class MinaSession extends AbstractInnerCloseable implements IoSession {
     // NOTE !!! data buffer may NOT be re-used when method returns - at least until IoWriteFuture is signalled
     public IoWriteFuture write(IoBuffer buffer) {
         Future future = new Future(sessionWriteId, null);
-        session.write(buffer).addListener((IoFutureListener<WriteFuture>) cf -> {
-            Throwable t = cf.getException();
-            if (t != null) {
-                future.setException(t);
-            } else {
-                future.setWritten();
-            }
-        });
+        session.write(buffer)
+            .addListener((IoFutureListener<WriteFuture>) cf -> {
+                Throwable t = cf.getException();
+                if (t != null) {
+                    future.setException(t);
+                } else {
+                    future.setWritten();
+                }
+            });
         return future;
     }
 
@@ -183,6 +186,9 @@ public class MinaSession extends AbstractInnerCloseable implements IoSession {
 
     @Override
     public String toString() {
-        return getClass().getSimpleName() + "[local=" + session.getLocalAddress() + ", remote=" + session.getRemoteAddress() + "]";
+        return getClass().getSimpleName()
+            + "[local=" + session.getLocalAddress()
+            + ", remote=" + session.getRemoteAddress()
+            + "]";
     }
 }

http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/ba008331/sshd-netty/src/main/java/org/apache/sshd/netty/NettyIoConnector.java
----------------------------------------------------------------------
diff --git a/sshd-netty/src/main/java/org/apache/sshd/netty/NettyIoConnector.java b/sshd-netty/src/main/java/org/apache/sshd/netty/NettyIoConnector.java
index 6d90490..9230803 100644
--- a/sshd-netty/src/main/java/org/apache/sshd/netty/NettyIoConnector.java
+++ b/sshd-netty/src/main/java/org/apache/sshd/netty/NettyIoConnector.java
@@ -47,7 +47,6 @@ import io.netty.util.concurrent.GlobalEventExecutor;
  * @author <a href="mailto:dev@mina.apache.org">Apache MINA SSHD Project</a>
  */
 public class NettyIoConnector extends NettyIoService implements IoConnector {
-
     protected final Bootstrap bootstrap = new Bootstrap();
 
     public NettyIoConnector(NettyIoServiceFactory factory, IoHandler handler) {

http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/ba008331/sshd-netty/src/main/java/org/apache/sshd/netty/NettyIoService.java
----------------------------------------------------------------------
diff --git a/sshd-netty/src/main/java/org/apache/sshd/netty/NettyIoService.java b/sshd-netty/src/main/java/org/apache/sshd/netty/NettyIoService.java
index a62326f..ea2ca8f 100644
--- a/sshd-netty/src/main/java/org/apache/sshd/netty/NettyIoService.java
+++ b/sshd-netty/src/main/java/org/apache/sshd/netty/NettyIoService.java
@@ -40,7 +40,8 @@ import io.netty.util.AttributeKey;
  */
 public abstract class NettyIoService extends AbstractCloseable implements IoService {
 
-    public static final AttributeKey<IoConnectFuture> CONNECT_FUTURE_KEY = AttributeKey.valueOf(IoConnectFuture.class.getName());
+    public static final AttributeKey<IoConnectFuture> CONNECT_FUTURE_KEY =
+        AttributeKey.valueOf(IoConnectFuture.class.getName());
 
     protected final AtomicLong sessionSeq = new AtomicLong();
     protected final Map<Long, IoSession> sessions = new ConcurrentHashMap<>();

http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/ba008331/sshd-netty/src/main/java/org/apache/sshd/netty/NettyIoSession.java
----------------------------------------------------------------------
diff --git a/sshd-netty/src/main/java/org/apache/sshd/netty/NettyIoSession.java b/sshd-netty/src/main/java/org/apache/sshd/netty/NettyIoSession.java
index f5864df..9cdeceb 100644
--- a/sshd-netty/src/main/java/org/apache/sshd/netty/NettyIoSession.java
+++ b/sshd-netty/src/main/java/org/apache/sshd/netty/NettyIoSession.java
@@ -51,7 +51,6 @@ import io.netty.util.Attribute;
  * @author <a href="mailto:dev@mina.apache.org">Apache MINA SSHD Project</a>
  */
 public class NettyIoSession extends AbstractCloseable implements IoSession {
-
     protected final Map<Object, Object> attributes = new HashMap<>();
     protected final NettyIoService service;
     protected final IoHandler handler;
@@ -163,7 +162,8 @@ public class NettyIoSession extends AbstractCloseable implements IoSession {
         remoteAddr = channel.remoteAddress();
         handler.sessionCreated(NettyIoSession.this);
 
-        Attribute<IoConnectFuture> connectFuture = channel.attr(NettyIoService.CONNECT_FUTURE_KEY);
+        Attribute<IoConnectFuture> connectFuture =
+            channel.attr(NettyIoService.CONNECT_FUTURE_KEY);
         IoConnectFuture future = connectFuture.get();
         if (future != null) {
             future.setSession(NettyIoSession.this);
@@ -186,7 +186,6 @@ public class NettyIoSession extends AbstractCloseable implements IoSession {
     }
 
     protected static class DefaultIoWriteFuture extends AbstractIoWriteFuture {
-
         public DefaultIoWriteFuture(Object id, Object lock) {
             super(id, lock);
         }
@@ -196,7 +195,6 @@ public class NettyIoSession extends AbstractCloseable implements IoSession {
      * Simple netty adapter to use as a bridge.
      */
     protected class Adapter extends ChannelInboundHandlerAdapter {
-
         public Adapter() {
             super();
         }