You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hc.apache.org by ol...@apache.org on 2018/08/05 12:48:14 UTC

httpcomponents-core git commit: Refactored SSL managed buffer components

Repository: httpcomponents-core
Updated Branches:
  refs/heads/master 49c62969d -> 8051de55d


Refactored SSL managed buffer components


Project: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/commit/8051de55
Tree: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/tree/8051de55
Diff: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/diff/8051de55

Branch: refs/heads/master
Commit: 8051de55d171cf18aadb0421522c45fc9986a543
Parents: 49c6296
Author: Oleg Kalnichevski <ol...@apache.org>
Authored: Sun Aug 5 14:38:28 2018 +0200
Committer: Oleg Kalnichevski <ol...@apache.org>
Committed: Sun Aug 5 14:44:17 2018 +0200

----------------------------------------------------------------------
 .../hc/core5/http2/ssl/H2ClientTlsStrategy.java |  10 +-
 .../hc/core5/http2/ssl/H2ServerTlsStrategy.java |  10 +-
 .../http/nio/ssl/BasicClientTlsStrategy.java    |  10 +-
 .../http/nio/ssl/BasicServerTlsStrategy.java    |  10 +-
 .../hc/core5/reactor/InternalDataChannel.java   |   6 +-
 .../apache/hc/core5/reactor/ssl/SSLBuffer.java  |  61 ---------
 .../core5/reactor/ssl/SSLBufferManagement.java  | 136 -------------------
 .../hc/core5/reactor/ssl/SSLBufferMode.java     |  38 ++++++
 .../hc/core5/reactor/ssl/SSLIOSession.java      |  18 +--
 .../hc/core5/reactor/ssl/SSLManagedBuffer.java  | 135 ++++++++++++++++++
 .../reactor/ssl/TransportSecurityLayer.java     |   2 +-
 11 files changed, 206 insertions(+), 230 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/8051de55/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/ssl/H2ClientTlsStrategy.java
----------------------------------------------------------------------
diff --git a/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/ssl/H2ClientTlsStrategy.java b/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/ssl/H2ClientTlsStrategy.java
index e21b3d5..9d8a306 100644
--- a/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/ssl/H2ClientTlsStrategy.java
+++ b/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/ssl/H2ClientTlsStrategy.java
@@ -34,7 +34,7 @@ import javax.net.ssl.SSLContext;
 import org.apache.hc.core5.http.HttpHost;
 import org.apache.hc.core5.http.URIScheme;
 import org.apache.hc.core5.http.nio.ssl.TlsStrategy;
-import org.apache.hc.core5.reactor.ssl.SSLBufferManagement;
+import org.apache.hc.core5.reactor.ssl.SSLBufferMode;
 import org.apache.hc.core5.reactor.ssl.SSLSessionInitializer;
 import org.apache.hc.core5.reactor.ssl.SSLSessionVerifier;
 import org.apache.hc.core5.reactor.ssl.TransportSecurityLayer;
@@ -50,17 +50,17 @@ import org.apache.hc.core5.util.Args;
 public class H2ClientTlsStrategy implements TlsStrategy {
 
     private final SSLContext sslContext;
-    private final SSLBufferManagement sslBufferManagement;
+    private final SSLBufferMode sslBufferMode;
     private final SSLSessionInitializer initializer;
     private final SSLSessionVerifier verifier;
 
     public H2ClientTlsStrategy(
             final SSLContext sslContext,
-            final SSLBufferManagement sslBufferManagement,
+            final SSLBufferMode sslBufferMode,
             final SSLSessionInitializer initializer,
             final SSLSessionVerifier verifier) {
         this.sslContext = Args.notNull(sslContext, "SSL context");
-        this.sslBufferManagement = sslBufferManagement;
+        this.sslBufferMode = sslBufferMode;
         this.initializer = initializer;
         this.verifier = verifier;
     }
@@ -98,7 +98,7 @@ public class H2ClientTlsStrategy implements TlsStrategy {
             tlsSession.startTls(
                     sslContext,
                     host,
-                    sslBufferManagement,
+                    sslBufferMode,
                     H2TlsSupport.enforceRequirements(attachment, initializer),
                     verifier);
             return true;

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/8051de55/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/ssl/H2ServerTlsStrategy.java
----------------------------------------------------------------------
diff --git a/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/ssl/H2ServerTlsStrategy.java b/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/ssl/H2ServerTlsStrategy.java
index 668a0fc..2c9ef7b 100644
--- a/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/ssl/H2ServerTlsStrategy.java
+++ b/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/ssl/H2ServerTlsStrategy.java
@@ -35,7 +35,7 @@ import org.apache.hc.core5.http.HttpHost;
 import org.apache.hc.core5.http.nio.ssl.FixedPortStrategy;
 import org.apache.hc.core5.http.nio.ssl.SecurePortStrategy;
 import org.apache.hc.core5.http.nio.ssl.TlsStrategy;
-import org.apache.hc.core5.reactor.ssl.SSLBufferManagement;
+import org.apache.hc.core5.reactor.ssl.SSLBufferMode;
 import org.apache.hc.core5.reactor.ssl.SSLSessionInitializer;
 import org.apache.hc.core5.reactor.ssl.SSLSessionVerifier;
 import org.apache.hc.core5.reactor.ssl.TransportSecurityLayer;
@@ -52,19 +52,19 @@ public class H2ServerTlsStrategy implements TlsStrategy {
 
     private final SSLContext sslContext;
     private final SecurePortStrategy securePortStrategy;
-    private final SSLBufferManagement sslBufferManagement;
+    private final SSLBufferMode sslBufferMode;
     private final SSLSessionInitializer initializer;
     private final SSLSessionVerifier verifier;
 
     public H2ServerTlsStrategy(
             final SSLContext sslContext,
             final SecurePortStrategy securePortStrategy,
-            final SSLBufferManagement sslBufferManagement,
+            final SSLBufferMode sslBufferMode,
             final SSLSessionInitializer initializer,
             final SSLSessionVerifier verifier) {
         this.sslContext = Args.notNull(sslContext, "SSL context");
         this.securePortStrategy = securePortStrategy;
-        this.sslBufferManagement = sslBufferManagement;
+        this.sslBufferMode = sslBufferMode;
         this.initializer = initializer;
         this.verifier = verifier;
     }
@@ -103,7 +103,7 @@ public class H2ServerTlsStrategy implements TlsStrategy {
             tlsSession.startTls(
                     sslContext,
                     host,
-                    sslBufferManagement,
+                    sslBufferMode,
                     H2TlsSupport.enforceRequirements(attachment, initializer),
                     verifier);
             return true;

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/8051de55/httpcore5/src/main/java/org/apache/hc/core5/http/nio/ssl/BasicClientTlsStrategy.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/http/nio/ssl/BasicClientTlsStrategy.java b/httpcore5/src/main/java/org/apache/hc/core5/http/nio/ssl/BasicClientTlsStrategy.java
index 599ea60..cd8c73c 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/http/nio/ssl/BasicClientTlsStrategy.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/http/nio/ssl/BasicClientTlsStrategy.java
@@ -33,7 +33,7 @@ import javax.net.ssl.SSLContext;
 
 import org.apache.hc.core5.http.HttpHost;
 import org.apache.hc.core5.http.URIScheme;
-import org.apache.hc.core5.reactor.ssl.SSLBufferManagement;
+import org.apache.hc.core5.reactor.ssl.SSLBufferMode;
 import org.apache.hc.core5.reactor.ssl.SSLSessionInitializer;
 import org.apache.hc.core5.reactor.ssl.SSLSessionVerifier;
 import org.apache.hc.core5.reactor.ssl.TransportSecurityLayer;
@@ -49,17 +49,17 @@ import org.apache.hc.core5.util.Args;
 public class BasicClientTlsStrategy implements TlsStrategy {
 
     private final SSLContext sslContext;
-    private final SSLBufferManagement sslBufferManagement;
+    private final SSLBufferMode sslBufferMode;
     private final SSLSessionInitializer initializer;
     private final SSLSessionVerifier verifier;
 
     public BasicClientTlsStrategy(
             final SSLContext sslContext,
-            final SSLBufferManagement sslBufferManagement,
+            final SSLBufferMode sslBufferMode,
             final SSLSessionInitializer initializer,
             final SSLSessionVerifier verifier) {
         this.sslContext = Args.notNull(sslContext, "SSL context");
-        this.sslBufferManagement = sslBufferManagement;
+        this.sslBufferMode = sslBufferMode;
         this.initializer = initializer;
         this.verifier = verifier;
     }
@@ -94,7 +94,7 @@ public class BasicClientTlsStrategy implements TlsStrategy {
             final Object attachment) {
         final String scheme = host != null ? host.getSchemeName() : null;
         if (URIScheme.HTTPS.same(scheme)) {
-            tlsSession.startTls(sslContext, host, sslBufferManagement, initializer, verifier);
+            tlsSession.startTls(sslContext, host, sslBufferMode, initializer, verifier);
             return true;
         }
         return false;

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/8051de55/httpcore5/src/main/java/org/apache/hc/core5/http/nio/ssl/BasicServerTlsStrategy.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/http/nio/ssl/BasicServerTlsStrategy.java b/httpcore5/src/main/java/org/apache/hc/core5/http/nio/ssl/BasicServerTlsStrategy.java
index e8985be..7a08d62 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/http/nio/ssl/BasicServerTlsStrategy.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/http/nio/ssl/BasicServerTlsStrategy.java
@@ -32,7 +32,7 @@ import java.net.SocketAddress;
 import javax.net.ssl.SSLContext;
 
 import org.apache.hc.core5.http.HttpHost;
-import org.apache.hc.core5.reactor.ssl.SSLBufferManagement;
+import org.apache.hc.core5.reactor.ssl.SSLBufferMode;
 import org.apache.hc.core5.reactor.ssl.SSLSessionInitializer;
 import org.apache.hc.core5.reactor.ssl.SSLSessionVerifier;
 import org.apache.hc.core5.reactor.ssl.TransportSecurityLayer;
@@ -49,19 +49,19 @@ public class BasicServerTlsStrategy implements TlsStrategy {
 
     private final SSLContext sslContext;
     private final SecurePortStrategy securePortStrategy;
-    private final SSLBufferManagement sslBufferManagement;
+    private final SSLBufferMode sslBufferMode;
     private final SSLSessionInitializer initializer;
     private final SSLSessionVerifier verifier;
 
     public BasicServerTlsStrategy(
             final SSLContext sslContext,
             final SecurePortStrategy securePortStrategy,
-            final SSLBufferManagement sslBufferManagement,
+            final SSLBufferMode sslBufferMode,
             final SSLSessionInitializer initializer,
             final SSLSessionVerifier verifier) {
         this.sslContext = Args.notNull(sslContext, "SSL context");
         this.securePortStrategy = securePortStrategy;
-        this.sslBufferManagement = sslBufferManagement;
+        this.sslBufferMode = sslBufferMode;
         this.initializer = initializer;
         this.verifier = verifier;
     }
@@ -97,7 +97,7 @@ public class BasicServerTlsStrategy implements TlsStrategy {
             final SocketAddress remoteAddress,
             final Object attachment) {
         if (securePortStrategy != null && securePortStrategy.isSecure(localAddress)) {
-            tlsSession.startTls(sslContext, host, sslBufferManagement, initializer, verifier);
+            tlsSession.startTls(sslContext, host, sslBufferMode, initializer, verifier);
             return true;
         }
         return false;

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/8051de55/httpcore5/src/main/java/org/apache/hc/core5/reactor/InternalDataChannel.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/reactor/InternalDataChannel.java b/httpcore5/src/main/java/org/apache/hc/core5/reactor/InternalDataChannel.java
index 30cf0cc..19f957b 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/reactor/InternalDataChannel.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/reactor/InternalDataChannel.java
@@ -41,7 +41,7 @@ import javax.net.ssl.SSLContext;
 import org.apache.hc.core5.function.Callback;
 import org.apache.hc.core5.io.CloseMode;
 import org.apache.hc.core5.net.NamedEndpoint;
-import org.apache.hc.core5.reactor.ssl.SSLBufferManagement;
+import org.apache.hc.core5.reactor.ssl.SSLBufferMode;
 import org.apache.hc.core5.reactor.ssl.SSLIOSession;
 import org.apache.hc.core5.reactor.ssl.SSLMode;
 import org.apache.hc.core5.reactor.ssl.SSLSessionInitializer;
@@ -210,7 +210,7 @@ final class InternalDataChannel extends InternalChannel implements ProtocolIOSes
     public void startTls(
             final SSLContext sslContext,
             final NamedEndpoint endpoint,
-            final SSLBufferManagement sslBufferManagement,
+            final SSLBufferMode sslBufferMode,
             final SSLSessionInitializer initializer,
             final SSLSessionVerifier verifier) {
         if (!tlsSessionRef.compareAndSet(null, new SSLIOSession(
@@ -218,7 +218,7 @@ final class InternalDataChannel extends InternalChannel implements ProtocolIOSes
                 ioSession,
                 initialEndpoint != null ? SSLMode.CLIENT : SSLMode.SERVER,
                 sslContext,
-                sslBufferManagement,
+                sslBufferMode,
                 initializer,
                 verifier,
                 new Callback<SSLIOSession>() {

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/8051de55/httpcore5/src/main/java/org/apache/hc/core5/reactor/ssl/SSLBuffer.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/reactor/ssl/SSLBuffer.java b/httpcore5/src/main/java/org/apache/hc/core5/reactor/ssl/SSLBuffer.java
deleted file mode 100644
index 18176b4..0000000
--- a/httpcore5/src/main/java/org/apache/hc/core5/reactor/ssl/SSLBuffer.java
+++ /dev/null
@@ -1,61 +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.
- * ====================================================================
- *
- * This software consists of voluntary contributions made by many
- * individuals on behalf of the Apache Software Foundation.  For more
- * information on the Apache Software Foundation, please see
- * <http://www.apache.org/>.
- *
- */
-package org.apache.hc.core5.reactor.ssl;
-
-import java.nio.ByteBuffer;
-
-import org.apache.hc.core5.annotation.Internal;
-
-/**
- * Managed internal SSL buffer.
- */
-@Internal
-interface SSLBuffer {
-    /**
-     * Allocates the resources required for this buffer, or returns the resources already allocated for this buffer.
-     * Unless {@link #release() } is called, multiple invokations to this method must return the same
-     * {@link java.nio.ByteBuffer}.
-     * @return buffer
-     */
-    ByteBuffer acquire();
-    /**
-     * Releases the resources for this buffer. If the buffer has already been released, this method does nothing.
-     */
-    void release();
-    /**
-     * Tests to see if this buffer has been acquired.
-     * @return {@code true} if the buffer is acquired, otherwise {@code false}
-     */
-    boolean isAcquired();
-    /**
-     * Tests to make sure that the buffer has been acquired and the underlying buffer has a position larger than
-     * {@code 0}. Essentially the same as {@code isAquired() && acquire().position > 0}.
-     * @return {@code true} if the buffer has been acquired and the underlying buffer's position is {@code &gt; 0},
-     * otherwise {@code false}
-     */
-    boolean hasData();
-}

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/8051de55/httpcore5/src/main/java/org/apache/hc/core5/reactor/ssl/SSLBufferManagement.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/reactor/ssl/SSLBufferManagement.java b/httpcore5/src/main/java/org/apache/hc/core5/reactor/ssl/SSLBufferManagement.java
deleted file mode 100644
index df1e4ff..0000000
--- a/httpcore5/src/main/java/org/apache/hc/core5/reactor/ssl/SSLBufferManagement.java
+++ /dev/null
@@ -1,136 +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.
- * ====================================================================
- *
- * This software consists of voluntary contributions made by many
- * individuals on behalf of the Apache Software Foundation.  For more
- * information on the Apache Software Foundation, please see
- * <http://www.apache.org/>.
- *
- */
-
-package org.apache.hc.core5.reactor.ssl;
-
-import java.nio.ByteBuffer;
-
-import org.apache.hc.core5.util.Args;
-
-/**
- * @since 5.0
- */
-public abstract class SSLBufferManagement {
-
-    public static final SSLBufferManagement STATIC = new StaticSSLBufferManagement();
-    public static final SSLBufferManagement DYNAMIC = new DynamicSSLBufferManagement();
-
-    public abstract SSLBuffer create(int size);
-
-    static SSLBuffer create(final SSLBufferManagement mode, final int size) {
-        if (mode == null) {
-            return STATIC.create(size);
-        }
-        return mode.create(size);
-    }
-
-    private static final class StaticSSLBufferManagement extends SSLBufferManagement {
-
-        @Override
-        public SSLBuffer create(final int size) {
-            return new StaticBuffer(size);
-        }
-
-    }
-
-    private static final class StaticBuffer implements SSLBuffer {
-
-        private final ByteBuffer buffer;
-
-        public StaticBuffer(final int size) {
-            Args.positive(size, "size");
-            buffer = ByteBuffer.allocate(size);
-        }
-
-        @Override
-        public ByteBuffer acquire() {
-            return buffer;
-        }
-
-        @Override
-        public void release() {
-            // do nothing
-        }
-
-        @Override
-        public boolean isAcquired() {
-            return true;
-        }
-
-        @Override
-        public boolean hasData() {
-            return buffer.position() > 0;
-        }
-
-    }
-
-    private static final class DynamicSSLBufferManagement extends SSLBufferManagement {
-
-        @Override
-        public SSLBuffer create(final int size) {
-            return new DynamicBuffer(size);
-        }
-
-    }
-
-    private static final class DynamicBuffer implements SSLBuffer {
-
-        private ByteBuffer wrapped;
-        private final int length;
-
-        public DynamicBuffer(final int size) {
-            Args.positive(size, "size");
-            this.length = size;
-        }
-
-        @Override
-        public ByteBuffer acquire() {
-            if (wrapped != null) {
-                return wrapped;
-            }
-            wrapped = ByteBuffer.allocate(length);
-            return wrapped;
-        }
-
-        @Override
-        public void release() {
-            wrapped = null;
-        }
-
-        @Override
-        public boolean isAcquired() {
-            return wrapped != null;
-        }
-
-        @Override
-        public boolean hasData() {
-            return wrapped != null && wrapped.position() > 0;
-        }
-
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/8051de55/httpcore5/src/main/java/org/apache/hc/core5/reactor/ssl/SSLBufferMode.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/reactor/ssl/SSLBufferMode.java b/httpcore5/src/main/java/org/apache/hc/core5/reactor/ssl/SSLBufferMode.java
new file mode 100644
index 0000000..e11c9cb
--- /dev/null
+++ b/httpcore5/src/main/java/org/apache/hc/core5/reactor/ssl/SSLBufferMode.java
@@ -0,0 +1,38 @@
+/*
+ * ====================================================================
+ * 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.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+
+package org.apache.hc.core5.reactor.ssl;
+
+/**
+ * @since 5.0
+ */
+public enum SSLBufferMode {
+
+    STATIC,
+    DYNAMIC
+
+}

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/8051de55/httpcore5/src/main/java/org/apache/hc/core5/reactor/ssl/SSLIOSession.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/reactor/ssl/SSLIOSession.java b/httpcore5/src/main/java/org/apache/hc/core5/reactor/ssl/SSLIOSession.java
index 7bb0f66..9e828b5 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/reactor/ssl/SSLIOSession.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/reactor/ssl/SSLIOSession.java
@@ -74,9 +74,9 @@ public class SSLIOSession implements IOSession {
     private final NamedEndpoint targetEndpoint;
     private final IOSession session;
     private final SSLEngine sslEngine;
-    private final SSLBuffer inEncrypted;
-    private final SSLBuffer outEncrypted;
-    private final SSLBuffer inPlain;
+    private final SSLManagedBuffer inEncrypted;
+    private final SSLManagedBuffer outEncrypted;
+    private final SSLManagedBuffer inPlain;
     private final ByteChannel channel;
     private final SSLSessionInitializer initializer;
     private final SSLSessionVerifier verifier;
@@ -111,7 +111,7 @@ public class SSLIOSession implements IOSession {
             final SSLSessionInitializer initializer,
             final SSLSessionVerifier verifier,
             final Callback<SSLIOSession> callback) {
-        this(targetEndpoint, session, sslMode, sslContext, SSLBufferManagement.STATIC, initializer, verifier, callback);
+        this(targetEndpoint, session, sslMode, sslContext, SSLBufferMode.STATIC, initializer, verifier, callback);
     }
 
     /**
@@ -121,7 +121,7 @@ public class SSLIOSession implements IOSession {
      * @param sslMode SSL mode (client or server)
      * @param targetEndpoint target endpoint (applicable in client mode only). May be {@code null}.
      * @param sslContext SSL context to use for this I/O session.
-     * @param sslBufferManagement buffer management mode
+     * @param sslBufferMode buffer management mode
      * @param initializer optional SSL session initializer. May be {@code null}.
      * @param verifier optional SSL session verifier. May be {@code null}.
      *
@@ -132,7 +132,7 @@ public class SSLIOSession implements IOSession {
             final IOSession session,
             final SSLMode sslMode,
             final SSLContext sslContext,
-            final SSLBufferManagement sslBufferManagement,
+            final SSLBufferMode sslBufferMode,
             final SSLSessionInitializer initializer,
             final SSLSessionVerifier verifier,
             final Callback<SSLIOSession> callback) {
@@ -156,12 +156,12 @@ public class SSLIOSession implements IOSession {
         final SSLSession sslSession = this.sslEngine.getSession();
         // Allocate buffers for network (encrypted) data
         final int netBufferSize = sslSession.getPacketBufferSize();
-        this.inEncrypted = SSLBufferManagement.create(sslBufferManagement, netBufferSize);
-        this.outEncrypted = SSLBufferManagement.create(sslBufferManagement, netBufferSize);
+        this.inEncrypted = SSLManagedBuffer.create(sslBufferMode, netBufferSize);
+        this.outEncrypted = SSLManagedBuffer.create(sslBufferMode, netBufferSize);
 
         // Allocate buffers for application (unencrypted) data
         final int appBufferSize = sslSession.getApplicationBufferSize();
-        this.inPlain = SSLBufferManagement.create(sslBufferManagement, appBufferSize);
+        this.inPlain = SSLManagedBuffer.create(sslBufferMode, appBufferSize);
         this.channel = new ByteChannel() {
 
             @Override

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/8051de55/httpcore5/src/main/java/org/apache/hc/core5/reactor/ssl/SSLManagedBuffer.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/reactor/ssl/SSLManagedBuffer.java b/httpcore5/src/main/java/org/apache/hc/core5/reactor/ssl/SSLManagedBuffer.java
new file mode 100644
index 0000000..138e1e8
--- /dev/null
+++ b/httpcore5/src/main/java/org/apache/hc/core5/reactor/ssl/SSLManagedBuffer.java
@@ -0,0 +1,135 @@
+/*
+ * ====================================================================
+ * 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.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+
+package org.apache.hc.core5.reactor.ssl;
+
+import java.nio.ByteBuffer;
+
+import org.apache.hc.core5.util.Args;
+
+abstract class SSLManagedBuffer {
+
+    /**
+     * Allocates the resources required for this buffer, or returns the resources already allocated for this buffer.
+     * Unless {@link #release() } is called, multiple invokations to this method must return the same
+     * {@link java.nio.ByteBuffer}.
+     * @return buffer
+     */
+    abstract ByteBuffer acquire();
+    /**
+     * Releases the resources for this buffer. If the buffer has already been released, this method does nothing.
+     */
+    abstract void release();
+    /**
+     * Tests to see if this buffer has been acquired.
+     * @return {@code true} if the buffer is acquired, otherwise {@code false}
+     */
+    abstract boolean isAcquired();
+    /**
+     * Tests to make sure that the buffer has been acquired and the underlying buffer has a position larger than
+     * {@code 0}. Essentially the same as {@code isAquired() && acquire().position > 0}.
+     * @return {@code true} if the buffer has been acquired and the underlying buffer's position is {@code &gt; 0},
+     * otherwise {@code false}
+     */
+    abstract boolean hasData();
+
+    static SSLManagedBuffer create(final SSLBufferMode mode, final int size) {
+        if (mode == SSLBufferMode.DYNAMIC) {
+            return new DynamicBuffer(size);
+        } else {
+            return new StaticBuffer(size);
+        }
+    }
+
+    static final class StaticBuffer extends SSLManagedBuffer {
+
+        private final ByteBuffer buffer;
+
+        public StaticBuffer(final int size) {
+            Args.positive(size, "size");
+            buffer = ByteBuffer.allocate(size);
+        }
+
+        @Override
+        public ByteBuffer acquire() {
+            return buffer;
+        }
+
+        @Override
+        public void release() {
+            // do nothing
+        }
+
+        @Override
+        public boolean isAcquired() {
+            return true;
+        }
+
+        @Override
+        public boolean hasData() {
+            return buffer.position() > 0;
+        }
+
+    }
+
+    static final class DynamicBuffer extends SSLManagedBuffer {
+
+        private ByteBuffer wrapped;
+        private final int length;
+
+        public DynamicBuffer(final int size) {
+            Args.positive(size, "size");
+            this.length = size;
+        }
+
+        @Override
+        public ByteBuffer acquire() {
+            if (wrapped != null) {
+                return wrapped;
+            }
+            wrapped = ByteBuffer.allocate(length);
+            return wrapped;
+        }
+
+        @Override
+        public void release() {
+            wrapped = null;
+        }
+
+        @Override
+        public boolean isAcquired() {
+            return wrapped != null;
+        }
+
+        @Override
+        public boolean hasData() {
+            return wrapped != null && wrapped.position() > 0;
+        }
+
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/8051de55/httpcore5/src/main/java/org/apache/hc/core5/reactor/ssl/TransportSecurityLayer.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/reactor/ssl/TransportSecurityLayer.java b/httpcore5/src/main/java/org/apache/hc/core5/reactor/ssl/TransportSecurityLayer.java
index 80cf1c1..fab01fa 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/reactor/ssl/TransportSecurityLayer.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/reactor/ssl/TransportSecurityLayer.java
@@ -41,7 +41,7 @@ public interface TransportSecurityLayer {
     void startTls(
             SSLContext sslContext,
             NamedEndpoint endpoint,
-            SSLBufferManagement sslBufferManagement,
+            SSLBufferMode sslBufferMode,
             SSLSessionInitializer initializer,
             SSLSessionVerifier verifier) throws UnsupportedOperationException;