You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@hc.apache.org by GitBox <gi...@apache.org> on 2020/08/04 15:21:30 UTC

[GitHub] [httpcomponents-client] carterkozak opened a new pull request #243: Implement an adaptor from unmanaged to managed client connections

carterkozak opened a new pull request #243:
URL: https://github.com/apache/httpcomponents-client/pull/243


   Draft based on discussion in https://github.com/apache/httpcomponents-core/pull/206#issuecomment-668594741
   If this seems helpful I will file a ticket and write tests.


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@hc.apache.org
For additional commands, e-mail: dev-help@hc.apache.org


[GitHub] [httpcomponents-client] carterkozak commented on a change in pull request #243: Implement an adaptor from unmanaged to managed client connections

Posted by GitBox <gi...@apache.org>.
carterkozak commented on a change in pull request #243:
URL: https://github.com/apache/httpcomponents-client/pull/243#discussion_r465134285



##########
File path: httpclient5/src/main/java/org/apache/hc/client5/http/impl/io/HttpClientConnectionFactoryManagedAdapter.java
##########
@@ -0,0 +1,215 @@
+/*
+ * ====================================================================
+ * 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.client5.http.impl.io;
+
+import org.apache.hc.client5.http.io.ManagedHttpClientConnection;
+import org.apache.hc.core5.http.ClassicHttpRequest;
+import org.apache.hc.core5.http.ClassicHttpResponse;
+import org.apache.hc.core5.http.EndpointDetails;
+import org.apache.hc.core5.http.HttpException;
+import org.apache.hc.core5.http.ProtocolVersion;
+import org.apache.hc.core5.http.io.HttpClientConnection;
+import org.apache.hc.core5.http.io.HttpConnectionFactory;
+import org.apache.hc.core5.io.CloseMode;
+import org.apache.hc.core5.util.Timeout;
+
+import javax.net.ssl.SSLSession;
+import java.io.IOException;
+import java.io.InterruptedIOException;
+import java.net.Socket;
+import java.net.SocketAddress;
+import java.util.concurrent.atomic.AtomicBoolean;
+
+/** Adapter to use convert basic http client connection factories into managed http client connection factories. */
+public final class HttpClientConnectionFactoryManagedAdapter implements HttpConnectionFactory<ManagedHttpClientConnection> {
+
+    private final HttpConnectionFactory<HttpClientConnection> delegate;
+
+    public HttpClientConnectionFactoryManagedAdapter(final HttpConnectionFactory<HttpClientConnection> delegate) {
+        this.delegate = delegate;
+    }
+
+    @Override
+    public ManagedHttpClientConnection createConnection(final Socket socket) throws IOException {
+        return new ManagedHttpClientConnectionAdapter(delegate.createConnection(socket));
+    }
+
+    @Override
+    public String toString() {
+        return "HttpClientConnectionFactoryManagedAdapter{" + delegate + '}';
+    }
+
+    private static final class ManagedHttpClientConnectionAdapter implements ManagedHttpClientConnection {
+
+        private final HttpClientConnection delegate;
+        private final AtomicBoolean closed = new AtomicBoolean();

Review comment:
       I'm not sure close tracking is necessary here, but I borrowed it from the DefaultManagedHttpClientConnection implementation.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@hc.apache.org
For additional commands, e-mail: dev-help@hc.apache.org


[GitHub] [httpcomponents-client] ok2c commented on pull request #243: Implement an adapter from unmanaged to managed client connections

Posted by GitBox <gi...@apache.org>.
ok2c commented on pull request #243:
URL: https://github.com/apache/httpcomponents-client/pull/243#issuecomment-769881960


   @carterkozak Let's just close it. We can always re-visit it at a later point. 


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@hc.apache.org
For additional commands, e-mail: dev-help@hc.apache.org


[GitHub] [httpcomponents-client] ok2c commented on pull request #243: Implement an adapter from unmanaged to managed client connections

Posted by GitBox <gi...@apache.org>.
ok2c commented on pull request #243:
URL: https://github.com/apache/httpcomponents-client/pull/243#issuecomment-769864777


   @carterkozak Is this PR still relevant? Could you please re-base it off the latest master?


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@hc.apache.org
For additional commands, e-mail: dev-help@hc.apache.org


[GitHub] [httpcomponents-client] carterkozak commented on pull request #243: Implement an adapter from unmanaged to managed client connections

Posted by GitBox <gi...@apache.org>.
carterkozak commented on pull request #243:
URL: https://github.com/apache/httpcomponents-client/pull/243#issuecomment-769882397


   Sounds good to me, closed.


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@hc.apache.org
For additional commands, e-mail: dev-help@hc.apache.org


[GitHub] [httpcomponents-client] carterkozak closed pull request #243: Implement an adapter from unmanaged to managed client connections

Posted by GitBox <gi...@apache.org>.
carterkozak closed pull request #243:
URL: https://github.com/apache/httpcomponents-client/pull/243


   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@hc.apache.org
For additional commands, e-mail: dev-help@hc.apache.org


[GitHub] [httpcomponents-client] carterkozak commented on pull request #243: Implement an adapter from unmanaged to managed client connections

Posted by GitBox <gi...@apache.org>.
carterkozak commented on pull request #243:
URL: https://github.com/apache/httpcomponents-client/pull/243#issuecomment-769873582


   @ok2c I'm not sure this is a helpful utility to provide since we define `DefaultManagedHttpClientConnection` to adapt the httpcomponents-core factory into a managed connection factory, but it was useful to validate new changes from core without a direct dependency from httpcomponents-client onto the snapshot of core. If there are other custom non-managed connection factories, this could be helpful.
   
   I suppose I am leaning towards closing this out, but if you think it would be helpful I'd be more than happy to give it a jira issue and merge it. What do you think?


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@hc.apache.org
For additional commands, e-mail: dev-help@hc.apache.org