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 2005/04/03 20:36:38 UTC
svn commit: r159951 - in
jakarta/httpclient/trunk/http-common/src/java/org/apache/http/impl:
DefaultProtocolSocketFactory.java NIOProtocolSocketFactory.java
OldIOProtocolSocketFactory.java
Author: olegk
Date: Sun Apr 3 11:36:37 2005
New Revision: 159951
URL: http://svn.apache.org/viewcvs?view=rev&rev=159951
Log:
Provided NIO and old IO versions of the default protocol socket factory
Added:
jakarta/httpclient/trunk/http-common/src/java/org/apache/http/impl/NIOProtocolSocketFactory.java
- copied, changed from r159764, jakarta/httpclient/trunk/http-common/src/java/org/apache/http/impl/DefaultProtocolSocketFactory.java
jakarta/httpclient/trunk/http-common/src/java/org/apache/http/impl/OldIOProtocolSocketFactory.java (with props)
Removed:
jakarta/httpclient/trunk/http-common/src/java/org/apache/http/impl/DefaultProtocolSocketFactory.java
Copied: jakarta/httpclient/trunk/http-common/src/java/org/apache/http/impl/NIOProtocolSocketFactory.java (from r159764, jakarta/httpclient/trunk/http-common/src/java/org/apache/http/impl/DefaultProtocolSocketFactory.java)
URL: http://svn.apache.org/viewcvs/jakarta/httpclient/trunk/http-common/src/java/org/apache/http/impl/NIOProtocolSocketFactory.java?view=diff&rev=159951&p1=jakarta/httpclient/trunk/http-common/src/java/org/apache/http/impl/DefaultProtocolSocketFactory.java&r1=159764&p2=jakarta/httpclient/trunk/http-common/src/java/org/apache/http/impl/NIOProtocolSocketFactory.java&r2=159951
==============================================================================
--- jakarta/httpclient/trunk/http-common/src/java/org/apache/http/impl/DefaultProtocolSocketFactory.java (original)
+++ jakarta/httpclient/trunk/http-common/src/java/org/apache/http/impl/NIOProtocolSocketFactory.java Sun Apr 3 11:36:37 2005
@@ -48,38 +48,30 @@
*
* @since 2.0
*/
-public class DefaultProtocolSocketFactory implements ProtocolSocketFactory {
+public class NIOProtocolSocketFactory implements ProtocolSocketFactory {
/**
* The factory singleton.
*/
- private static final DefaultProtocolSocketFactory factory = new DefaultProtocolSocketFactory();
+ private static final NIOProtocolSocketFactory factory = new NIOProtocolSocketFactory();
/**
* Gets an singleton instance of the DefaultProtocolSocketFactory.
* @return a DefaultProtocolSocketFactory
*/
- public static DefaultProtocolSocketFactory getSocketFactory() {
+ public static NIOProtocolSocketFactory getSocketFactory() {
return factory;
}
/**
* Constructor for DefaultProtocolSocketFactory.
*/
- private DefaultProtocolSocketFactory() {
+ private NIOProtocolSocketFactory() {
super();
}
/**
* Attempts to get a new socket connection to the given host within the given time limit.
- * <p>
- * This method employs several techniques to circumvent the limitations of older JREs that
- * do not support connect timeout. When running in JRE 1.4 or above reflection is used to
- * call Socket#connect(SocketAddress endpoint, int timeout) method. When executing in older
- * JREs a controller thread is executed. The controller thread attempts to create a new socket
- * within the given limit of time. If socket constructor does not return until the timeout
- * expires, the controller terminates and throws an {@link ConnectTimeoutException}
- * </p>
*
* @param host the host name/IP
* @param port the port on the host
@@ -121,14 +113,14 @@
* All instances of DefaultProtocolSocketFactory are the same.
*/
public boolean equals(Object obj) {
- return ((obj != null) && obj.getClass().equals(DefaultProtocolSocketFactory.class));
+ return ((obj != null) && obj.getClass().equals(NIOProtocolSocketFactory.class));
}
/**
* All instances of DefaultProtocolSocketFactory have the same hash code.
*/
public int hashCode() {
- return DefaultProtocolSocketFactory.class.hashCode();
+ return NIOProtocolSocketFactory.class.hashCode();
}
}
Added: jakarta/httpclient/trunk/http-common/src/java/org/apache/http/impl/OldIOProtocolSocketFactory.java
URL: http://svn.apache.org/viewcvs/jakarta/httpclient/trunk/http-common/src/java/org/apache/http/impl/OldIOProtocolSocketFactory.java?view=auto&rev=159951
==============================================================================
--- jakarta/httpclient/trunk/http-common/src/java/org/apache/http/impl/OldIOProtocolSocketFactory.java (added)
+++ jakarta/httpclient/trunk/http-common/src/java/org/apache/http/impl/OldIOProtocolSocketFactory.java Sun Apr 3 11:36:37 2005
@@ -0,0 +1,127 @@
+/*
+ * $HeadURL$
+ * $Revision$
+ * $Date$
+ *
+ * ====================================================================
+ *
+ * Copyright 2002-2004 The Apache Software Foundation
+ *
+ * Licensed 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.http.impl;
+
+import java.io.IOException;
+import java.net.InetAddress;
+import java.net.Socket;
+import java.net.UnknownHostException;
+
+import org.apache.http.ProtocolSocketFactory;
+import org.apache.http.params.HttpConnectionParams;
+import org.apache.http.params.HttpParams;
+
+/**
+ * The default class for creating protocol sockets. This class just uses the
+ * {@link java.net.Socket socket} constructors.
+ *
+ * @author Michael Becke
+ *
+ * @since 2.0
+ */
+public class OldIOProtocolSocketFactory implements ProtocolSocketFactory {
+
+ /**
+ * The factory singleton.
+ */
+ private static final OldIOProtocolSocketFactory factory = new OldIOProtocolSocketFactory();
+
+ /**
+ * Gets an singleton instance of the DefaultProtocolSocketFactory.
+ * @return a DefaultProtocolSocketFactory
+ */
+ public static OldIOProtocolSocketFactory getSocketFactory() {
+ return factory;
+ }
+
+ /**
+ * Constructor for DefaultProtocolSocketFactory.
+ */
+ private OldIOProtocolSocketFactory() {
+ super();
+ }
+
+ /**
+ * Attempts to get a new socket connection to using old (pre Java 1.4) IO mode.
+ * This socket factory does not support connect timeout as it requires Java 1.4
+ * functionality.
+ *
+ * @param host the host name/IP
+ * @param port the port on the host
+ * @param localAddress the local host name/IP to bind the socket to
+ * @param localPort the port on the local machine
+ * @param params {@link HttpConnectionParams Http connection parameters}
+ *
+ * @return Socket a new socket
+ *
+ * @throws IOException if an I/O error occurs while creating the socket
+ * @throws UnknownHostException if the IP address of the host cannot be
+ * @throws IllegalStateException if connection timeout is set
+ * determined
+ *
+ * @since 3.0
+ */
+ public Socket createSocket(
+ final String host,
+ final int port,
+ final InetAddress localAddress,
+ final int localPort,
+ final HttpParams params
+ ) throws IOException, UnknownHostException {
+ if (params == null) {
+ throw new IllegalArgumentException("Parameters may not be null");
+ }
+ HttpConnectionParams connparams = new HttpConnectionParams(params);
+ int timeout = connparams.getConnectionTimeout();
+ if (timeout != 0) {
+ throw new IllegalStateException("Connection timeout is not supported in old IO mode");
+ }
+ if (localAddress != null) {
+ return new Socket(host, port, localAddress, localPort);
+ } else {
+ return new Socket(host, port);
+ }
+ }
+
+ /**
+ * All instances of DefaultProtocolSocketFactory are the same.
+ */
+ public boolean equals(Object obj) {
+ return ((obj != null) && obj.getClass().equals(OldIOProtocolSocketFactory.class));
+ }
+
+ /**
+ * All instances of DefaultProtocolSocketFactory have the same hash code.
+ */
+ public int hashCode() {
+ return OldIOProtocolSocketFactory.class.hashCode();
+ }
+
+}
Propchange: jakarta/httpclient/trunk/http-common/src/java/org/apache/http/impl/OldIOProtocolSocketFactory.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: jakarta/httpclient/trunk/http-common/src/java/org/apache/http/impl/OldIOProtocolSocketFactory.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Propchange: jakarta/httpclient/trunk/http-common/src/java/org/apache/http/impl/OldIOProtocolSocketFactory.java
------------------------------------------------------------------------------
svn:mime-type = text/plain